-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLayoutEmbedScripts.astro
More file actions
197 lines (178 loc) · 6.22 KB
/
LayoutEmbedScripts.astro
File metadata and controls
197 lines (178 loc) · 6.22 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
---
// src/components/LayoutEmbedScripts.astro
/** Third-party embed loaders: Fathom events, HelpScout, Hyperping, MaxMind, WebMCP. */
interface LayoutEmbedScriptsProps {
isProduction: boolean;
}
const { isProduction } = Astro.props as LayoutEmbedScriptsProps;
---
{/* Fathom event tracking - fires on any element with data-fathom-event */}
<script is:inline>
document.addEventListener('click', function (e) {
var el = e.target.closest('[data-fathom-event]');
if (el && window.fathom) {
window.fathom.trackEvent(el.getAttribute('data-fathom-event'));
}
});
</script>
{/* HelpScout Beacon open trigger handler */}
<script>
document.addEventListener('DOMContentLoaded', function () {
const beaconTriggers = document.querySelectorAll('.open-beacon');
beaconTriggers.forEach((trigger) => {
trigger.addEventListener('click', function (e) {
e.preventDefault();
// @ts-expect-error Beacon is loaded from HelpScout script
if (window.Beacon) {
// @ts-expect-error Beacon is loaded from HelpScout script
window.Beacon('open');
}
});
});
});
</script>
{/* Hyperping Status Badge - Load on idle to not block main thread */}
<script is:inline>
/* eslint-disable no-undef */
(function () {
function initHyperping() {
var script = document.createElement('script');
script.src = 'https://hyperping.com/badge.js';
script.async = true;
script.onload = function () {
if (typeof Hyperping !== 'undefined') {
Hyperping.init({
statuspage: 'https://www.datumstatus.net',
border: 'none',
borderColor: '#30363D',
uptime: false,
dot: true,
dotSize: 10,
isNeutral: false,
dotOk: '#2BAC76',
dotIncident: '#FFAF36',
dotOutage: '#E95858',
dotMaintenance: '#0070F3',
dotNeutral: '#0070F3',
operational: 'All systems normal',
incident: 'Under investigation',
outage: 'System outage',
maintenance: 'Under maintenance',
});
}
};
document.body.appendChild(script);
}
// Load on idle or after 3s timeout (whichever comes first)
if ('requestIdleCallback' in window) {
requestIdleCallback(initHyperping, { timeout: 3000 });
} else {
setTimeout(initHyperping, 2000);
}
})();
</script>
{/* HelpScout Beacon - Deferred loading on first interaction or 5s timeout */}
<script is:inline data-production={isProduction ? 'true' : 'false'}>
(function () {
var isProduction = document.currentScript.getAttribute('data-production') === 'true';
if (!isProduction) return;
function loadHelpScout() {
if (window.__helpScoutLoaded) return;
window.__helpScoutLoaded = true;
// Initialize Beacon stub
window.Beacon =
window.Beacon ||
function (method, options, data) {
window.Beacon.readyQueue = window.Beacon.readyQueue || [];
window.Beacon.readyQueue.push({ method: method, options: options, data: data });
};
window.Beacon.readyQueue = [];
// Load HelpScout script
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.src = 'https://beacon-v2.helpscout.net';
script.onload = function () {
window.Beacon('init', '57a7245e-772c-4d51-bdb1-6b898f34f2cb');
};
document.body.appendChild(script);
}
var events = ['mousemove', 'touchstart', 'scroll', 'keydown'];
var loaded = false;
function onInteraction() {
if (loaded) return;
loaded = true;
events.forEach(function (e) {
document.removeEventListener(e, onInteraction);
});
loadHelpScout();
}
events.forEach(function (e) {
document.addEventListener(e, onInteraction, { once: true, passive: true });
});
setTimeout(function () {
if (!loaded) {
loaded = true;
loadHelpScout();
}
}, 5000);
})();
</script>
{/* MaxMind minFraud device tracking - feeds fingerprint into signup fraud check */}
<script is:inline data-production={isProduction ? 'true' : 'false'} data-account-id="1313245">
(function () {
var isProduction = document.currentScript.getAttribute('data-production') === 'true';
if (!isProduction) return;
var accountId = document.currentScript.getAttribute('data-account-id');
var mmapiws = (window.__mmapiws = window.__mmapiws || {});
mmapiws.accountId = accountId;
function loadMaxMind() {
var script = document.createElement('script');
script.src = 'https://device.maxmind.com/js/device.js';
script.async = true;
document.body.appendChild(script);
}
if ('requestIdleCallback' in window) {
requestIdleCallback(loadMaxMind, { timeout: 4000 });
} else {
setTimeout(loadMaxMind, 3000);
}
})();
</script>
{/* WebMCP — expose site tools to AI agents via the browser model context API */}
<script is:inline>
if ('modelContext' in navigator && typeof navigator.modelContext.registerTool === 'function') {
const controller = new AbortController();
navigator.modelContext.registerTool({
name: 'search_docs',
description:
'Search Datum documentation for information about network cloud features, configuration, and API usage',
inputSchema: {
type: 'object',
properties: {
query: { type: 'string', description: 'Search query' },
},
required: ['query'],
},
execute: async ({ query }) => ({ url: '/docs/?q=' + encodeURIComponent(query) }),
signal: controller.signal,
});
navigator.modelContext.registerTool({
name: 'navigate',
description:
'Navigate to a page on the Datum website. Use paths like /docs/, /features/, /download/, /contact/, /changelog/, /blog/',
inputSchema: {
type: 'object',
properties: {
path: { type: 'string', description: 'Site-relative path to navigate to' },
},
required: ['path'],
},
execute: async ({ path }) => {
window.location.href = path;
return { navigated: path };
},
signal: controller.signal,
});
}
</script>