Skip to content

Commit 2c8fda8

Browse files
committed
docs: migrate analytics scripts from old docs to docs-mintlify
Add GTM (GTM-52W7VM2) via Mintlify integrations config and add cube-tracking.js for cubedev-tracking page view tracking. Made-with: Cursor
1 parent ed93449 commit 2c8fda8

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

docs-mintlify/cube-tracking.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
(function () {
2+
var COOKIE_NAME = 'cubedev_anonymous';
3+
var MAX_AGE = 365 * 24 * 60 * 60;
4+
var TRACK_URL = 'https://track.cube.dev/track';
5+
var IDENTITY_URL = 'https://identity.cube.dev';
6+
7+
function getCookie(name) {
8+
var match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
9+
return match ? decodeURIComponent(match[1]) : null;
10+
}
11+
12+
function setCookie(name, value, maxAge, domain) {
13+
var cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value) +
14+
'; max-age=' + maxAge + '; path=/; SameSite=Lax';
15+
if (domain) cookie += '; domain=' + domain;
16+
document.cookie = cookie;
17+
}
18+
19+
function getTopDomain() {
20+
var parts = location.hostname.split('.');
21+
if (parts.length <= 1) return location.hostname;
22+
for (var i = parts.length - 2; i >= 0; i--) {
23+
var candidate = parts.slice(i).join('.');
24+
setCookie('__tld__', '1', 10, '.' + candidate);
25+
if (getCookie('__tld__')) {
26+
setCookie('__tld__', '', -1, '.' + candidate);
27+
return candidate;
28+
}
29+
}
30+
return location.hostname;
31+
}
32+
33+
function newUUID() {
34+
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
35+
return crypto.randomUUID();
36+
}
37+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
38+
var r = (Math.random() * 16) | 0;
39+
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
40+
});
41+
}
42+
43+
function getAnonymousId(domain, callback) {
44+
var existing = getCookie(COOKIE_NAME);
45+
if (existing) return callback(existing);
46+
47+
fetch(IDENTITY_URL, { credentials: 'include' })
48+
.then(function (r) { return r.status < 400 ? r.text() : Promise.reject(); })
49+
.catch(function () { return newUUID(); })
50+
.then(function (id) {
51+
setCookie(COOKIE_NAME, id, MAX_AGE, domain ? '.' + domain : null);
52+
callback(id);
53+
});
54+
}
55+
56+
function trackPage() {
57+
var topDomain = getTopDomain();
58+
getAnonymousId(topDomain, function (anonymousId) {
59+
var payload = [{
60+
event: 'page',
61+
href: location.href,
62+
pathname: location.pathname,
63+
search: location.search,
64+
hash: location.hash,
65+
referrer: document.referrer,
66+
id: newUUID(),
67+
clientAnonymousId: anonymousId,
68+
clientTimestamp: new Date().toJSON(),
69+
sentAt: new Date().toJSON(),
70+
}];
71+
72+
fetch(TRACK_URL, {
73+
method: 'POST',
74+
body: JSON.stringify(payload),
75+
headers: { 'Content-Type': 'application/json' },
76+
}).catch(function () {});
77+
});
78+
}
79+
80+
if (document.readyState === 'loading') {
81+
document.addEventListener('DOMContentLoaded', trackPage);
82+
} else {
83+
trackPage();
84+
}
85+
})();

docs-mintlify/docs.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,11 @@
598598
}
599599
]
600600
},
601+
"integrations": {
602+
"gtm": {
603+
"tagId": "GTM-52W7VM2"
604+
}
605+
},
601606
"styling": {
602607
"codeblocks": "dark"
603608
},

0 commit comments

Comments
 (0)