js实现谷歌网站统计

基本方法

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
这个网站看到

  

posted @ 2017-12-08 16:43  small_winder  阅读(552)  评论(0)    收藏  举报