基本方法
function ga() { if (window.ga) { window.ga.apply(null, arguments); } else { stack.push(arguments); } }
我们可以对ga方法通过apply或call进行参数扩展
比如
function gaSendEvent(key, content, detail) { return ga.call( null, 'send', 'event', `${context}-${key}`, content, detail ); }
调用:
如果你要统计一个按钮的点击量,只要在事件中埋点就行了
function onClickEvent(){ ga('send', 'event', "这里一般是按钮页面位置", "这里一般是统计描述", `这里一般是用户信息`); }
分析结果可以在
https://analytics.google.com
这个网站看到