目前的做法:
直接把统计代码放在index.html里面;
问题:不能统计到路由跳转过程中的url;
<script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan style='display:none;' id='cnzz_stat_icon_1258575107'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s5.cnzz.com/stat.php%3Fid%3D1258575107' type='text/javascript'%3E%3C/script%3E"));</script>
vue的写法
网上找到一个关于vue的cnzz统计的代码写法,求react项目怎么写比较好?
<template>
<router-view></router-view>
</template>
<script>
export default {
name: 'app',
mounted () {
const script = document.createElement('script')
script.src = 'https://s95.cnzz.com/z_stat.php?id=1111111111&web_id=1111111111'
script.language = 'JavaScript'
document.body.appendChild(script)
},
watch: {
'$route' () {
if (window._czc) {
let location = window.location
let contentUrl = location.pathname + location.hash
let refererUrl = '/'
window._czc.push(['_trackPageview', contentUrl, refererUrl])
}
}
}
}
</script>