Forked from DavidKuennen/minimal-analytics-snippet.js
Created
December 16, 2018 12:08
-
-
Save ildaroit/1a037ad6ba1c38c5f1e797c310dd06f0 to your computer and use it in GitHub Desktop.
Revisions
-
DavidKuennen revised this gist
Dec 15, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,7 +51,7 @@ return pushState.apply(history, arguments); } pageView(); })(window.history, "XX-XXXXXXXXX-X", { anonymizeIp: true, colorDepth: true, characterSet: true, -
DavidKuennen revised this gist
Dec 15, 2018 . 1 changed file with 2 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,4 @@ (function (history, trackingId, options) { const generateId = () => { return '_' + Math.random().toString(36).substr(2, 9); }; @@ -39,7 +28,7 @@ cid: getId(), t: 'pageview', sd: options.colorDepth && screen.colorDepth ? `${screen.colorDepth}-bits` : undefined, dr: document.referrer || undefined, dt: document.title, dl: document.location.origin + document.location.pathname + document.location.search, ul: options.language ? (navigator.language || "").toLowerCase() : undefined, @@ -62,7 +51,7 @@ return pushState.apply(history, arguments); } pageView(); })(window.history, "UA-120315485-2", { anonymizeIp: true, colorDepth: true, characterSet: true, -
DavidKuennen renamed this gist
Dec 14, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
DavidKuennen revised this gist
Dec 14, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,7 +62,7 @@ return pushState.apply(history, arguments); } pageView(); })(window.history, "XX-XXXXXXXXX-X", { anonymizeIp: true, colorDepth: true, characterSet: true, -
DavidKuennen revised this gist
Dec 14, 2018 . No changes.There are no files selected for viewing
-
DavidKuennen created this gist
Dec 14, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ (function (history, trackingId, options) { const getParameterByName = (paramName) => { var searchString = window.location.search.substring(1), i, val, params = searchString.split("&"); for (i=0;i<params.length;i++) { val = params[i].split("="); if (val[0] == paramName) { return val[1] || undefined; } } return undefined; }; const generateId = () => { return '_' + Math.random().toString(36).substr(2, 9); }; const getId = () => { if (!localStorage.cid) { localStorage.cid = generateId() } return localStorage.cid; }; const serialize = (obj) => { var str = []; for (var p in obj) { if (obj.hasOwnProperty(p)) { if(obj[p] !== undefined) { str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); } } } return str.join("&"); }; const pageView = () => { setTimeout(() => { const data = { v: '1', aip: options.anonymizeIp ? 1 : undefined, tid: trackingId, cid: getId(), t: 'pageview', sd: options.colorDepth && screen.colorDepth ? `${screen.colorDepth}-bits` : undefined, dr: getParameterByName('ref'), dt: document.title, dl: document.location.origin + document.location.pathname + document.location.search, ul: options.language ? (navigator.language || "").toLowerCase() : undefined, de: options.characterSet ? document.characterSet : undefined, sr: options.screenSize ? `${(window.screen || {}).width}x${(window.screen || {}).height}` : undefined, vp: options.screenSize && window.visualViewport ? `${(window.visualViewport || {}).width}x${(window.visualViewport || {}).height}` : undefined }; var xhr = new XMLHttpRequest(); xhr.open("GET", `https://www.google-analytics.com/collect?${serialize(data)}&z=${Math.random()}`, true); xhr.send(null); }, 10); }; const pushState = history.pushState; history.pushState = function (state) { if (typeof history.onpushstate == "function") { history.onpushstate({ state: state }); } pageView() return pushState.apply(history, arguments); } pageView(); })(window.history, "UA-120315485-2", { anonymizeIp: true, colorDepth: true, characterSet: true, screenSize: true, language: true });