我試圖弄清楚跟蹤/分析腳本是如何工作的。還有的the Google Analytics code的優化版本:立即使用構造函數/ Universal Analytics調用函數
<script>
(function(window, document, variableName, scriptElement, firstScript) {
window['GoogleAnalyticsObject'] = variableName;
window[variableName] || (window[variableName] = function() {
(window[variableName].q = window[variableName].q || []).push(arguments);
});
window[variableName].l = +new Date;
scriptElement = document.createElement('script'),
firstScript = document.scripts[0];
scriptElement.src = 'https://127.0.0.1:3000/analytics.js';
firstScript.parentNode.insertBefore(scriptElement, firstScript)
}(window, document, 'ga'));
ga('create', 'UA-XXXX-Y');
ga('send', 'pageview');
</script>
加載自定義腳本,我無法弄清楚如何GA()函數的工作。我已經嘗試了各種IIFE和構造函數,但沒有獲得「創建」和「發送」事件。
如何在服務器上看到這些事件?
更新
我設法抽象我的方式來排隊,現在想知道怎樣才能創建一個異步隊列這些事件發送到服務器。有什麼建議麼?
(function() {
var ga = function(a) {
return void 0 != a && -1 < (a.constructor + '').indexOf('String');
};
var sa = function(a) {
return a ? a.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '') : '';
};
var gb = ga(window.GoogleAnalyticsObject) && sa(window.GoogleAnalyticsObject) || 'ga';
var Window = window;
var Document = document;
console.log(Window[gb].q);
})(window);
*您的*代碼在哪裏? – Pointy