Warning: Undefined array key "HTTP_REFERER" in /var/www/html/source/js/analyticsjs.php on line 5
Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/source/js/analyticsjs.php on line 5
(function() {
const apikey = 'oovAe4LSfwkb8U903D3q';
const sessionId = localStorage.getItem("session_id") || (()=>{
const newSession = Math.random().toString(36).substr(2, 9);
localStorage.setItem("session_id", newSession);
return newSession;
})();
function sendAnalytics(eventType, eventData = {}) {
var data;
if('NULL' == 'NULL'){
data = JSON.stringify({
API: apikey, // API key required for every request
session_id: sessionId,
user_id: null,
project_id: 2,
project_url: window.location.href,
referrer: document.referrer,
screen_width: window.innerWidth,
screen_height: window.innerHeight,
event_type: eventType,
event_data: eventData
});
}else{
data = JSON.stringify({
API: apikey, // API key required for every request
session_id: sessionId,
user_id: NULL, // Replace with actual user ID if available
project_id: 2,
project_url: window.location.href,
referrer: document.referrer,
screen_width: window.innerWidth,
screen_height: window.innerHeight,
event_type: eventType,
event_data: eventData
});
}
// Use sendBeacon for reliable async tracking (even when closing the page)
if (navigator.sendBeacon) {
navigator.sendBeacon("https://arctechnologies.ca/analytics.php", data);
} else {
// Fallback to XMLHttpRequest for older browsers
const xhr = new XMLHttpRequest();
xhr.open("POST", "https://arctechnologies.ca/analytics.php", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
}
}
// Track Page Views
sendAnalytics("page_view");
// Track Click Events
document.addEventListener("click", (e) => {
sendAnalytics("click", {
tag: e.target.tagName,
id: e.target.id,
class: e.target.className
});
});
// Track Scroll Depth
let lastScroll = 0;
window.addEventListener("scroll", () => {
const scrollDepth = Math.round(window.scrollY / document.body.scrollHeight * 100);
if (Math.abs(scrollDepth - lastScroll) > 10) {
sendAnalytics("scroll", { depth: scrollDepth });
lastScroll = scrollDepth;
}
});
})();