-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathanalytics.js
More file actions
121 lines (115 loc) · 5.47 KB
/
analytics.js
File metadata and controls
121 lines (115 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
(function () {
"use strict";
window.RudderSnippetVersion = "3.0.60";
var identifier = "rudderanalytics";
if (!window[identifier]) {
window[identifier] = [];
}
var rudderanalytics = window[identifier];
if (Array.isArray(rudderanalytics)) {
if (rudderanalytics.snippetExecuted === true && window.console && console.error) {
console.error("RudderStack JavaScript SDK snippet included more than once.");
} else {
rudderanalytics.snippetExecuted = true;
window.rudderAnalyticsBuildType = "legacy";
var sdkBaseUrl = "https://cdn.rudderlabs.com";
var sdkVersion = "v3";
var sdkFileName = "rsa.min.js";
var scriptLoadingMode = "async";
var methods = ["setDefaultInstanceKey", "load", "ready", "page", "track", "identify", "alias", "group", "reset", "setAnonymousId", "startSession", "endSession", "consent"];
for (var i = 0; i < methods.length; i++) {
var method = methods[i];
rudderanalytics[method] = function (methodName) {
return function () {
if (Array.isArray(window[identifier])) {
rudderanalytics.push([methodName].concat(Array.prototype.slice.call(arguments)));
} else {
var _methodName;
(_methodName = window[identifier][methodName]) === null || _methodName === undefined || _methodName.apply(window[identifier], arguments);
}
};
}(method);
}
try {
new Function('class Test{field=()=>{};test({prop=[]}={}){return prop?(prop?.property??[...prop]):import("");}}');
window.rudderAnalyticsBuildType = "modern";
} catch (e) {
}
var head = document.head || document.getElementsByTagName("head")[0];
var body = document.body || document.getElementsByTagName("body")[0];
window.rudderAnalyticsAddScript = function (url, extraAttributeKey, extraAttributeVal) {
var scriptTag = document.createElement("script");
scriptTag.src = url;
scriptTag.setAttribute("data-loader", "RS_JS_SDK");
if (extraAttributeKey && extraAttributeVal) {
scriptTag.setAttribute(extraAttributeKey, extraAttributeVal);
}
if (scriptLoadingMode === "async") {
scriptTag.async = true;
} else if (scriptLoadingMode === "defer") {
scriptTag.defer = true;
}
if (head) {
head.insertBefore(scriptTag, head.firstChild);
} else {
body.insertBefore(scriptTag, body.firstChild);
}
};
window.rudderAnalyticsMount = function () {
(function () {
if (typeof globalThis === "undefined") {
var getGlobal = function getGlobal() {
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
return null;
};
var global = getGlobal();
if (global) {
Object.defineProperty(global, "globalThis", {
value: global,
configurable: true
});
}
}
})();
window.rudderAnalyticsAddScript("".concat(sdkBaseUrl, "/").concat(sdkVersion, "/").concat(window.rudderAnalyticsBuildType, "/").concat(sdkFileName), "data-rsa-write-key", "1tLM5JN9u3GhRUidt5zjU0Uc5Qf");
};
if (typeof Promise === "undefined" || typeof globalThis === "undefined") {
window.rudderAnalyticsAddScript("https://polyfill-fastly.io/v3/polyfill.min.js?version=3.111.0&features=Symbol%2CPromise&callback=rudderAnalyticsMount");
} else {
window.rudderAnalyticsMount();
}
var loadOptions = {};
rudderanalytics.load("1tLM5JN9u3GhRUidt5zjU0Uc5Qf", "https://analytics.lightdash.com", loadOptions);
}
}
// Store current URL
let currentUrl = undefined;
// Store the original pushState and replaceState functions
const originalPushState = history.pushState;
const originalReplaceState = history.replaceState;
// Function to call RudderStack's page view
function trackPageView() {
// Double-check if the URL has changed
if( currentUrl !== window.location.href) {
currentUrl = window.location.href;
window.rudderanalytics.page();
}
}
// Override pushState to track page view
history.pushState = function () {
originalPushState.apply(this, arguments);
trackPageView();
};
// Override replaceState to track page view
history.replaceState = function () {
originalReplaceState.apply(this, arguments);
trackPageView();
};
// Listen for popstate event (browser back/forward buttons) to track page view
window.addEventListener('popstate', trackPageView);
})();