From 9c645183222c0d484789d740cc68d6ec0aba1d1d Mon Sep 17 00:00:00 2001 From: Matt Bernstein Date: Wed, 26 Nov 2025 12:17:44 -0500 Subject: [PATCH 1/3] help fern load GA library --- fern/js/analytics-enterprise-cta.js | 53 ++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/fern/js/analytics-enterprise-cta.js b/fern/js/analytics-enterprise-cta.js index 33198cf..6caeb14 100644 --- a/fern/js/analytics-enterprise-cta.js +++ b/fern/js/analytics-enterprise-cta.js @@ -1,19 +1,40 @@ -document.addEventListener('DOMContentLoaded', function() { - const links = document.querySelectorAll('a[href^="https://humansignal.com/goenterprise"]'); - if (links.length === 0) { - return; +(function() { + + // help fern load GA library + + const MEASUREMENT_ID = 'G-326708547'; + + function loadGaScriptOnce() { + if (document.querySelector('script[data-ga4-loaded]')) return; + + const s = document.createElement('script'); + s.async = true; + s.src = `https://www.googletagmanager.com/gtag/js?id=${MEASUREMENT_ID}`; + s.setAttribute('data-ga4-loaded', 'true'); + document.head.appendChild(s); } - links.forEach((link, index) => { - link.addEventListener('click', function() { - if (typeof gtag === 'function') { - gtag('event', 'enterprise_cta_click', { - button_index: index, - button_text: link.innerText || '', - target_url: link.href, - page_path: window.location.pathname - }); - } + + loadGaScriptOnce(); + + // add tracking for enterprise CTA + + document.addEventListener('DOMContentLoaded', function() { + const links = document.querySelectorAll( + 'a[href^="https://humansignal.com/goenterprise"]' + ); + if (!links.length) return; + + links.forEach((link, index) => { + link.addEventListener('click', function() { + if (typeof gtag === 'function') { + gtag('event', 'enterprise_cta_click', { + button_index: index + 1, + button_text: link.innerText || '', + target_url: link.href, + page_path: window.location.pathname + }); + } + }); }); }); -}); - +})(); From b8490110d6d5f5c07743b046dd1ee3eabd9be6cd Mon Sep 17 00:00:00 2001 From: Matt Bernstein Date: Wed, 26 Nov 2025 12:58:48 -0500 Subject: [PATCH 2/3] debug --- fern/js/analytics-enterprise-cta.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fern/js/analytics-enterprise-cta.js b/fern/js/analytics-enterprise-cta.js index 6caeb14..33a9f9c 100644 --- a/fern/js/analytics-enterprise-cta.js +++ b/fern/js/analytics-enterprise-cta.js @@ -1,3 +1,7 @@ +console.log('[enterprise-cta] custom JS loaded', window.location.href); +window.__ENTERPRISE_CTA_LOADED__ = true; + + (function() { // help fern load GA library From a24e1428a67552c591a4603812594c6164a49142 Mon Sep 17 00:00:00 2001 From: Matt Bernstein Date: Wed, 26 Nov 2025 13:18:09 -0500 Subject: [PATCH 3/3] debug --- fern/js/analytics-enterprise-cta.js | 68 ++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/fern/js/analytics-enterprise-cta.js b/fern/js/analytics-enterprise-cta.js index 33a9f9c..2d2f8cd 100644 --- a/fern/js/analytics-enterprise-cta.js +++ b/fern/js/analytics-enterprise-cta.js @@ -1,35 +1,72 @@ console.log('[enterprise-cta] custom JS loaded', window.location.href); window.__ENTERPRISE_CTA_LOADED__ = true; - -(function() { - - // help fern load GA library - +(function () { const MEASUREMENT_ID = 'G-326708547'; function loadGaScriptOnce() { - if (document.querySelector('script[data-ga4-loaded]')) return; + try { + const existing = document.querySelector('script[data-ga4-loaded]'); + if (existing) { + console.log('[enterprise-cta] GA script already present', existing.src); + return; + } + + const head = + document.head || + document.getElementsByTagName('head')[0] || + document.documentElement; + + if (!head) { + console.warn('[enterprise-cta] no element found, cannot load GA'); + return; + } + + const s = document.createElement('script'); + s.async = true; + s.src = `https://www.googletagmanager.com/gtag/js?id=${MEASUREMENT_ID}`; + s.setAttribute('data-ga4-loaded', 'true'); + + s.onload = () => { + console.log('[enterprise-cta] GA4 script loaded OK', s.src); + }; - const s = document.createElement('script'); - s.async = true; - s.src = `https://www.googletagmanager.com/gtag/js?id=${MEASUREMENT_ID}`; - s.setAttribute('data-ga4-loaded', 'true'); - document.head.appendChild(s); + s.onerror = (e) => { + console.error('[enterprise-cta] GA4 script FAILED to load', e); + }; + + head.appendChild(s); + console.log('[enterprise-cta] GA4 script tag appended', s.src); + } catch (err) { + console.error('[enterprise-cta] loadGaScriptOnce threw', err); + } } - loadGaScriptOnce(); + // Make sure we only run after DOM is at least partially ready + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', loadGaScriptOnce); + } else { + loadGaScriptOnce(); + } - // add tracking for enterprise CTA + // --- Enterprise CTA tracking --- - document.addEventListener('DOMContentLoaded', function() { + document.addEventListener('DOMContentLoaded', function () { const links = document.querySelectorAll( 'a[href^="https://humansignal.com/goenterprise"]' ); + console.log('[enterprise-cta] found enterprise links:', links.length); + if (!links.length) return; links.forEach((link, index) => { - link.addEventListener('click', function() { + link.addEventListener('click', function () { + console.log('[enterprise-cta] click on enterprise link', { + index, + href: link.href, + gtagType: typeof gtag + }); + if (typeof gtag === 'function') { gtag('event', 'enterprise_cta_click', { button_index: index + 1, @@ -42,3 +79,4 @@ window.__ENTERPRISE_CTA_LOADED__ = true; }); }); })(); +