This repository was archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelemetry.js
More file actions
34 lines (30 loc) · 1.4 KB
/
telemetry.js
File metadata and controls
34 lines (30 loc) · 1.4 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
import amplitude from 'amplitude-js';
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
const amplitudeKey = 'c9d876059e7c9a83e44dcef855e77f48';
function addDeviceId() {
const deviceId = amplitude.getInstance().options.deviceId;
document.querySelectorAll("[href='https://app.iasql.com']")
.forEach(n => n.href = `https://app.iasql.com?amp_device_id=${deviceId}`);
document.querySelectorAll("[href='https://blog.iasql.com']")
.forEach(n => n.href = `https://blog.iasql.com?amp_device_id=${deviceId}`);
document.querySelectorAll("[href='https://iasql.com']")
.forEach(n => n.href = `https://iasql.com?amp_device_id=${deviceId}`);
}
export function onRouteDidUpdate({location, previousLocation}) {
// Don't execute if we are still on the same page; the lifecycle may be fired
// because the hash changes (e.g. when navigating between headings)
if (location.pathname !== previousLocation?.pathname) {
amplitude.getInstance().logEvent("DOCS", {
route: location.pathname,
});
addDeviceId();
}
}
// browser only
if (ExecutionEnvironment.canUseDOM) {
// https://developers.amplitude.com/docs/advanced-settings#cross-domain-tracking-javascript
amplitude.getInstance().init(amplitudeKey, null, {includeReferrer: true, includeUtm: true, deviceIdFromUrlParam: true}, addDeviceId);
amplitude.getInstance().logEvent("DOCS", {
route: document.location.pathname,
});
}