@@ -28,9 +28,10 @@ const HALL_API_KEY = import.meta.env.HALL_API_KEY;
28
28
'Referer': document.referrer,
29
29
'Accept-Language': navigator.language,
30
30
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
31
- 'Sec-Ch-Ua': navigator.userAgent.includes('Chrome') ? '"Not_A Brand";v="8", "Chromium";v="120"' : '',
32
- 'Sec-Ch-Ua-Mobile': /Mobile|Android|iPhone|iPad/.test(navigator.userAgent) ? '?1' : '?0',
33
- 'Sec-Ch-Ua-Platform': `"${navigator.platform}"`
31
+ ...(navigator.userAgentData ? {
32
+ 'Sec-Ch-Ua-Mobile': navigator.userAgentData.mobile ? '?1' : '?0',
33
+ 'Sec-Ch-Ua-Platform': `"${navigator.userAgentData.platform}"`
34
+ } : {})
34
35
};
35
36
36
37
const analyticsData = {
@@ -67,6 +68,9 @@ const HALL_API_KEY = import.meta.env.HALL_API_KEY;
67
68
trackPageView();
68
69
}
69
70
71
+ // Store observers for potential cleanup
72
+ const observers = [];
73
+
70
74
// Also track when body becomes available (fallback)
71
75
if (!document.body) {
72
76
const bodyObserver = new MutationObserver(() => {
@@ -75,6 +79,7 @@ const HALL_API_KEY = import.meta.env.HALL_API_KEY;
75
79
trackPageView();
76
80
}
77
81
});
82
+ observers.push(bodyObserver);
78
83
bodyObserver.observe(document.documentElement, {
79
84
childList: true,
80
85
subtree: true
@@ -90,12 +95,18 @@ const HALL_API_KEY = import.meta.env.HALL_API_KEY;
90
95
setTimeout(trackPageView, 100); // Small delay to ensure new page is loaded
91
96
}
92
97
});
98
+ observers.push(observer);
93
99
94
100
observer.observe(document.body, {
95
101
childList: true,
96
102
subtree: true
97
103
});
98
104
}
105
+
106
+ // Cleanup on page unload
107
+ window.addEventListener('beforeunload', () => {
108
+ observers.forEach(observer => observer.disconnect());
109
+ });
99
110
100
111
})();
101
112
</script >
0 commit comments