// Helper functions - FIXED & SAFE function buildPageName(pathSegments) { return pathSegments.length > 0 ? "qc:edgeimpulse:" + pathSegments.join(":") : "qc:edgeimpulse:home page"; } function buildSiteSection(i, pathSegments) { if (i > pathSegments.length || i <= 0) return ""; const segments = pathSegments.slice(0, i); const joined = segments.join(":"); return joined ? "qc:edgeimpulse:" + joined : ""; } function getPreviousPageName() { const referrer = document.referrer; if (!referrer) return ""; try { const refUrl = new URL(referrer); if (refUrl.hostname !== window.location.hostname) return ""; const refPathname = refUrl.pathname.replace(/^\/+|\/+$/g, "").split("?")[0]; const refPathSegments = refPathname.split("/").filter((s) => s.length > 0); return buildPageName(refPathSegments); } catch (e) { // Silently ignore invalid referrer URLs (e.g. from mobile apps) return ""; } } // FIXED: extractFileName – now 100% safe for relative, absolute, and malformed URLs function extractFileName(url) { if (!url || typeof url !== "string") return null; // Extract the last path segment or filename before query/hash const match = url.match(/[^/]+(?=[?#]|$)/); if (!match) return null; let name = match[0]; try { name = decodeURIComponent(name); } catch (e) { // Ignore decode errors } // Remove common prefixes (Webflow/HubSpot IDs) name = name.replace( /^[0-9a-f]{8,}-[0-9a-f]{4,}-[0-9a-f]{4,}-[0-9a-f]{4,}-[0-9a-f]{12}[_-]/i, "" ); name = name.replace(/^[0-9a-f]{6,}[_-]/i, ""); // Remove file extension name = name.replace(/\.[^.\?#]+$/, ""); // Clean up separators name = name.replace(/[-_]+/g, " ").replace(/\s+/g, " ").trim(); return name || null; } // Click handler - SAFE against null target function handleEvent(event) { const target = event?.target; if (!target) return; const anchor = target.closest("a"); const label = (target.textContent || "").trim() || (anchor?.textContent || "").trim() || ""; const location = anchor?.href || ""; const linkDetail = (target.textContent || "").trim(); window.adobeDataLayer = window.adobeDataLayer || []; if (event.type !== "click") return; // === MEGAMENU === if (target.closest("[data-megamenu-login]")) { window.adobeDataLayer.push({ event: "sign in", eventInfo: { action: "click", detail: "megamenu", label: "Login", location: "studio.edgeimpulse.com/login", }, }); } if (target.closest("[data-banner-top-link]")) { window.adobeDataLayer.push({ event: "cta", eventInfo: { action: "click", detail: "banner", label: label || "Learn more", location: location || "https://edgeimpulse.com/arduino-integrations", }, }); } if (target.closest("[data-banner-bottom-link]")) { window.adobeDataLayer.push({ event: "cta", eventInfo: { action: "click", detail: "banner", label: label || "Read the Announcement", location: location || "https://www.edgeimpulse.com/blog/edge-impulse-qualcomm-acquisition/", }, }); } if (target.closest("[data-megamenu-logo]")) { window.adobeDataLayer.push({ event: "megamenu", eventInfo: { action: "click", detail: "megamenu logo", label: label || "megamenu", location: location || "https://edgeimpulse.com/", }, }); } if (target.closest("[data-megamenu-cta]")) { window.adobeDataLayer.push({ event: "create account", eventInfo: { action: "click", detail: "megamenu", label: label || "Get started", location: location || "https://studio.edgeimpulse.com/signup", }, }); } if (target.closest("[data-megamenu-blog]")) { window.adobeDataLayer.push({ event: "megamenu", eventInfo: { action: "click", detail: "", label: label || "blog", location: location || "https://www.edgeimpulse.com/blog", }, }); } if (target.closest("[data-megamenu-sublink]")) { const parent = target.closest("[data-megamenu-parent]"); const parentDetail = parent ?.querySelector("[data-megamenu-parent-detail]") ?.textContent?.trim() || "product"; window.adobeDataLayer.push({ event: "megamenu", eventInfo: { action: "click", detail: parentDetail, label: label || "algorithms", location: location || "https://edgeimpulse.com/product#algorithms", }, }); } // === FOOTER === if (target.closest("[data-footer-logo]")) { window.adobeDataLayer.push({ event: "footer", eventInfo: { action: "click", label: "footer", detail: "footer logo", location: location || "https://edgeimpulse.com/", }, }); } if (target.closest("[data-footer-link]")) { window.adobeDataLayer.push({ event: "footer", eventInfo: { action: "click", label: "footer", detail: linkDetail || "Home", location: location || "https://edgeimpulse.com/", }, }); } if (target.closest("[data-footer-social]")) { window.adobeDataLayer.push({ event: "footer", eventInfo: { action: "click", label: "footer", detail: linkDetail || "X", location: location || "https://twitter.com/edgeimpulse", }, }); } // === CTAs === if (target.closest("[data-cta-tile]")) { window.adobeDataLayer.push({ event: "cta", eventInfo: { action: "tile", label: label || "5 Trends for Manufacturing", location: location || "https://pages.edgeimpulse.com/5-rising-trends-for-ai-adoption-in-manufacturing", }, }); } if (target.closest("[data-cta-link]")) { window.adobeDataLayer.push({ event: "cta", eventInfo: { action: "click", label: label || "View all", location: location || "/contact", }, }); } // === DOWNLOADS (now safe with filename) === if (target.closest("[data-download]")) { const downloadLink = target.closest("[data-download]"); const url = (downloadLink?.getAttribute("href") || location || "").trim(); const fileName = extractFileName(url); window.adobeDataLayer.push({ event: "download", eventInfo: { action: "document", detail: fileName || "Unknown File", label: label || "Download", location: url || "unknown", }, }); console.log(`Download: ${fileName || "Unknown File"} → ${url}`); } // === TABS === if (target.closest("[data-tab]")) { window.adobeDataLayer.push({ event: "tab", eventInfo: { action: "tab_click", detail: label || "Tab 1", label: label || "Tab 1", location: location || "#", }, }); } } document.addEventListener("click", handleEvent); // Main Data Layer + Scroll + Form Tracking (IIFE) (function () { window.adobeDataLayer = window.adobeDataLayer || []; // === PAGE LOAD === const pathname = (window.location.pathname || "") .replace(/^\/+|\/+$/g, "") .split("?")[0]; const pathSegments = pathname.split("/").filter((s) => s.length > 0); const pageName = buildPageName(pathSegments); const sections = {}; for (let i = 1; i <= 9; i++) { sections[`sc_site_section_${i}`] = buildSiteSection(i, pathSegments); } const previousPageName = getPreviousPageName(); const deviceOrientation = window.innerWidth > window.innerHeight ? "landscape" : "portrait"; const isAuthenticated = !!document.cookie.match(/auth_token/); const pageLoadData = { event: "page-load", page: { device_orientation: deviceOrientation, language_code: "en", page_name: pageName, previous_page_name: previousPageName || "", ...sections, website_theme: "na", }, }; if (isAuthenticated) { pageLoadData.visitor = { org_name: "Edge Impulse", org_id: "1001", session_status: "logged_in", }; } window.adobeDataLayer.push(pageLoadData); console.log("Adobe Data Layer initialized:", window.adobeDataLayer); // === SCROLL TRACKING (25%, 50%, 75%, 100%) === (function () { const triggered = new Set(); function getScrollPct() { const viewportHeight = window.innerHeight; const documentHeight = Math.max( document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight ); if (documentHeight <= viewportHeight) return 100; const scrolled = window.scrollY + viewportHeight; return Math.min(100, Math.round((scrolled / documentHeight) * 100)); } function check() { const p = getScrollPct(); [25, 50, 75, 100].forEach((t) => { if (p >= t && !triggered.has(t)) { triggered.add(t); window.adobeDataLayer.push({ event: "scroll_track", eventInfo: { action: t.toString(), label: "page" }, }); console.log(`Scroll depth: ${t}%`); } }); } window.addEventListener("scroll", check, { passive: true }); window.addEventListener("resize", check, { passive: true }); check(); })(); })(); // const formEl = $form[0]; // const formId = formEl.getAttribute('data-form-id') || 'unknown'; // // push to adobeDataLayer here // hsLog('Form View', { formId }); // formEl.addEventListener('focusin', (evt) => { // hsLog('Form Start', { formId, fieldName: evt.target.name || evt.target.id || 'unknown' }); // }, { once: true });