Skip to content

Commit 0b42c30

Browse files
committed
Fix: analytics tracking
1 parent 2c69322 commit 0b42c30

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

gatsby-browser.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,53 @@ const components = {
2424
export const wrapRootElement = ({ element }) => {
2525
return <MDXProvider components={components}>{element}</MDXProvider>;
2626
};
27+
/*
28+
* Copyright 2025 Adobe All Rights Reserved.
29+
* NOTICE: All information contained herein is, and remains the property of Adobe and its suppliers, if any.
30+
* The intellectual and technical concepts contained herein are proprietary to Adobe and its suppliers and are protected by all applicable intellectual property laws, including trade secret and copyright laws.
31+
* Dissemination of this information or reproduction of this material is strictly forbidden unless prior written permission is obtained from Adobe.
32+
*/
33+
34+
const isBrowser = typeof window !== "undefined";
35+
36+
export const onClientEntry = () => {
37+
// set adobe analytics window object
38+
if (isBrowser) {
39+
window._satellite = window._satellite || {};
40+
window.alloy_all = window.alloy_all || {};
41+
window.alloy_all.data = window.alloy_all.data || {};
42+
window.alloy_all.data._adobe_corpnew = window.alloy_all.data._adobe_corpnew || {};
43+
window.alloy_all.data._adobe_corpnew.web = window.alloy_all.data._adobe_corpnew.web || {};
44+
window.alloy_all.data._adobe_corpnew.web.webPageDetails = window.alloy_all.data._adobe_corpnew.web.webPageDetails || {};
45+
}
46+
};
47+
48+
export const onRouteUpdate = ({ location, prevLocation }) => {
49+
if (isBrowser) {
50+
function watchAndFireAnalytics() {
51+
// eslint-disable-next-line no-undef
52+
if (typeof window._satellite !== 'undefined') {
53+
// eslint-disable-next-line no-undef
54+
_satellite.track('state',
55+
{
56+
xdm: {},
57+
data: {
58+
_adobe_corpnew: {
59+
web: {
60+
webPageDetails: {
61+
customPageName: location.href
62+
}
63+
}
64+
}
65+
}
66+
}
67+
);
68+
69+
clearInterval(intervalId);
70+
}
71+
}
72+
73+
// watch if analytics is online then track page
74+
const intervalId = setInterval(watchAndFireAnalytics, 1000);
75+
}
76+
}

0 commit comments

Comments
 (0)