Skip to content

Commit

Permalink
Fix an issue where GA, Heap, and Hotjar integrations could interfere …
Browse files Browse the repository at this point in the history
…with the global scope of the page.
  • Loading branch information
emmerich committed Dec 15, 2023
1 parent 5cbbef8 commit 055dde6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"eslint.format.enable": true,
// Fix errors on save using ESLint
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
// Format using Prettier to format on save
"editor.defaultFormatter": "esbenp.prettier-vscode",
Expand Down
53 changes: 26 additions & 27 deletions integrations/googleanalytics/src/script.raw.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
const trackingID = '<TO_REPLACE>';
(function (win, doc, script, layer) {
const id = '<TO_REPLACE>';
const GRANTED_COOKIE = '__gitbook_cookie_granted';

const GANTED_COOKIE = '__gitbook_cookie_granted';
function triggerView(win) {
win.gtag('event', 'page_view', {
page_path: win.location.pathname,
page_location: win.location.href,
page_title: win.document.title,
send_to: 'tracking_views',
});
}

function getCookie(cname) {
const name = `${cname}=`;
const decodedCookie = decodeURIComponent(document.cookie);
const ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
function getCookie(cname) {
const name = `${cname}=`;
const decodedCookie = decodeURIComponent(document.cookie);
const ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return '';
}
return '';
}

function triggerView(win) {
win.gtag('event', 'page_view', {
page_path: win.location.pathname,
page_location: win.location.href,
page_title: win.document.title,
send_to: 'tracking_views',
});
}

(function (win, doc, script, layer, id) {
let disableCookies = false;
const cookie = getCookie(GANTED_COOKIE);
const cookie = getCookie(GRANTED_COOKIE);
if (cookie === 'yes') {
disableCookies = false;
} else if (cookie === 'no') {
Expand Down Expand Up @@ -69,4 +68,4 @@ function triggerView(win) {
});
};
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', trackingID);
})(window, document, 'script', 'dataLayer');
62 changes: 36 additions & 26 deletions integrations/heap/src/script.raw.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
const trackingID = '<TO_REPLACE>';

(function (win, doc, trackingID) {
win.heap=win.heap||[]
heap.load=function(e,t) {
win.heap.appid = e, win.heap.config=t=t||{};
var r=doc.createElement("script");
r.type="text/javascript",
r.async=!0,
r.src="https://cdn.heapanalytics.com/js/heap-"+e+".js";
var a=doc.getElementsByTagName("script")[0];
a.parentNode.insertBefore(r,a);
for(var n=function(e){
return function () {
heap.push([e].concat(Array.prototype.slice.call(arguments,0)))
}
}, p=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","removeEventProperty","setEventProperties","track","unsetEventProperty"],
o=0; o < p.length; o++)
heap[p[o]] = n(p[o])
};
heap.load(trackingID);
})(window, document, trackingID);




(function (win, doc) {
const trackingID = '<TO_REPLACE>';
win.heap = win.heap || [];
heap.load = function (e, t) {
(win.heap.appid = e), (win.heap.config = t = t || {});
var r = doc.createElement('script');
(r.type = 'text/javascript'),
(r.async = !0),
(r.src = 'https://cdn.heapanalytics.com/js/heap-' + e + '.js');
var a = doc.getElementsByTagName('script')[0];
a.parentNode.insertBefore(r, a);
for (
var n = function (e) {
return function () {
heap.push([e].concat(Array.prototype.slice.call(arguments, 0)));
};
},
p = [
'addEventProperties',
'addUserProperties',
'clearEventProperties',
'identify',
'resetIdentity',
'removeEventProperty',
'setEventProperties',
'track',
'unsetEventProperty',
],
o = 0;
o < p.length;
o++
)
heap[p[o]] = n(p[o]);
};
heap.load(trackingID);
})(window, document);
3 changes: 1 addition & 2 deletions integrations/hotjar/src/script.raw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const trackingID = '<TO_REPLACE>';

(function (h, o, t, j, a, r) {
const trackingID = '<TO_REPLACE>';
h.hj =
h.hj ||
function () {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 055dde6

Please sign in to comment.