在Vue和UniApp中使用友盟
1.Vue
在App.vue中添加下面代码
mounted(){ // 友盟统计添加 const script = document.createElement("script"); script.src ="https://s4.cnzz.com/z_stat.php?id=友盟中创建的应用id&web_id=应用id"; //该路径为点击统计代码后,页面中第一个 文字统计 script代码 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]); } } },
2.UniApp
安装友盟微信sdk
npm install umtrack-wx --save
在main.js中添加下面代码
import uma from "umtrack-wx"; uma.init({ appKey: "友盟中创建的AppKey", useOpenid: false, autoGetOpenid: false, debug: true, });