zoukankan      html  css  js  c++  java
  • 埋点

    下面是我在项目中遇到 埋点需求的时候,用来测试埋点的代码,需要看过来

    import {tracking} from 'env'; export const fTracking = { param: { uid: '', page_token: new Date().getTime() + Math.floor(Math.random()*100), from: 'WEB', ac_val: approach.getQueryString('md') ? approach.getQueryString('md'): '', //页面md ac_referer: window.location.pathname, //页面来源页, ac: 'view', // 监听当前页面 actionOwner: '' // 监听 触发事件的对象 }, init: function (param) { let that = this; if(this.param.ac_referer != '/') { this.param.ac_val = approach.getQueryString('id')? approach.getQueryString('id'): ''; } $('body').append($('<div id="trackDiv"></div>')); this.param.uid = param; let viewTimer = setInterval(function() { that.send(); }, 30000); }, send: function (action, actionOwner) { if(action) {//如果当前页面的view 就是跳转过来的页面为referer this.param.ac = action; // this.param.ac_referer = window.location.pathname; } else { this.param.ac = 'view'; if(window.location.href.indexOf('5paH56ug')!= -1) { this.param.ac_val = approach.getQueryString('5paH56ug'); } } if(actionOwner) { this.param.actionOwner = actionOwner; } else { this.param.actionOwner = document.referrer; } let i; let q = ''; for(i in this.param){ if(q == ''){ q = i + "=" + this.param[i]; }else{ q = q + "&" + i + "=" + this.param[i]; } } let id = 'cc.track' ; let src = tracking+'?' + q; this._sendImage(id,src); }, run: function(){ this._bindEvent(); }, _sendImage : function(id, src){ if (window.localStorage) { localStorage.setItem(id,src); } let img = new Image(); img.src=src; img.id = id; img.style.width = 0; img.style.height = 0; document.getElementById("trackDiv").appendChild(img); let timer = setInterval(function() { if (img.complete) { document.getElementById("trackDiv").removeChild(img); clearInterval(timer); } if (window.localStorage) { localStorage.removeItem(id); } }, 50); }, _bindEvent: function(){ let that = this; $("*[tccAction]").bind("click",function(e){ let action = $(e.currentTarget).attr("tccAction"); let actionOwner = $(e.currentTarget).attr("actionOwner"); that.send(action,actionOwner); }); $("*[tccAction]").blur(function(e){ let action = $(e.currentTarget).attr("tccAction"); let actionOwner = $(e.currentTarget).attr("actionOwner"); that.send(action,actionOwner); }); }, }
  • 相关阅读:
    Redis(八)理解内存
    Redis(七)Redis的噩梦:阻塞
    Redis(六)复制
    Redis(五)持久化
    笔试面试经典问题
    两个栈实现一个队列
    单链表相关操作
    我的笔记本
    10进制正整数转4位定长的36进制字符串
    微软2016校园招聘在线笔试之Magic Box
  • 原文地址:https://www.cnblogs.com/lisiyang/p/8548228.html
Copyright © 2011-2022 走看看