學(xué)習(xí)筆記《Google Analytics》

小丑魚(yú) 選擇了 Google Analytics 作為網(wǎng)站的數(shù)據(jù)監(jiān)測(cè)平臺(tái),基礎(chǔ)的功能并不復(fù)雜:

頁(yè)面監(jiān)測(cè):

在頁(yè)面中添加這樣的代碼就可以實(shí)現(xiàn)頁(yè)面監(jiān)測(cè):

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-85667918-1', 'auto');
ga('send', 'pageview');

事件監(jiān)測(cè):

文檔:https://developers.google.com/analytics/devguides/collection/analyticsjs/events

簡(jiǎn)單的封裝:

gaEventSend = function(category, action)
{
    ga('send', 'event', category, action);
}

gaEventSendAndHref = function(category, action, url)
{
    gaEventSend(category, action);
    location.href = url;
}

頁(yè)面載入時(shí)間

if (window.performance) {
    // Gets the number of milliseconds since page load
    // (and rounds the result since the value must be an integer).
    var timeSincePageLoad = Math.round(performance.now());

    // Sends the timing hit to Google Analytics.
    ga('send', 'timing', 'JS Dependencies', 'load', timeSincePageLoad);
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容