-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
47 lines (39 loc) · 1.28 KB
/
script.js
File metadata and controls
47 lines (39 loc) · 1.28 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
(function () {
var navToggle = document.querySelector('.nav-toggle');
var nav = document.querySelector('.site-nav');
if (navToggle && nav) {
navToggle.addEventListener('click', function () {
var open = nav.classList.toggle('open');
navToggle.setAttribute('aria-expanded', String(open));
});
nav.addEventListener('click', function (event) {
if (event.target.matches('a')) {
nav.classList.remove('open');
navToggle.setAttribute('aria-expanded', 'false');
}
});
}
// Privacy-first outbound tracking hook. Sends events only if analytics is configured.
document.addEventListener('click', function (event) {
var link = event.target.closest('a[href]');
if (!link) return;
var url;
try {
url = new URL(link.href, window.location.origin);
} catch (e) {
return;
}
if (url.origin === window.location.origin) return;
var label = link.getAttribute('data-outbound') || 'outbound-link';
if (typeof window.plausible === 'function') {
window.plausible('Outbound Click', { props: { label: label, href: url.href } });
}
if (Array.isArray(window.dataLayer)) {
window.dataLayer.push({
event: 'outbound_click',
label: label,
href: url.href
});
}
});
})();