From 2e48410f4a76b7a0cd77183ee01f73bbbca908a8 Mon Sep 17 00:00:00 2001 From: Eve Weinberg Date: Wed, 30 Sep 2026 11:45:49 -0700 Subject: [PATCH] Track click destination and untagged intent links - Add a destination property (the link URL) to every tracked click; href stays the page URL. - Skip elements whose data-analytics-onclick is empty instead of sending a blank event. - Untagged links to /request-demo fire RequestDemoClicked and untagged links to console.modular.com/signup fire GetStartedClicked, with location Inline-{page path}. Covers blog post body links and anything added without a tag. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/tracking/amplitude.js | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/tracking/amplitude.js b/src/tracking/amplitude.js index 6432c3b..824f649 100644 --- a/src/tracking/amplitude.js +++ b/src/tracking/amplitude.js @@ -3,15 +3,33 @@ import { trackEvent } from '../utils/amplitude'; export function initAmplitude() { SniffEmailForAmplitude(); - function amplitudeTrack(anchorTag, trackTitle) { + function amplitudeTrack(anchorTag, trackTitle, location = anchorTag.dataset.analyticsLocation) { return () => { trackEvent(trackTitle, { href: window.location.href, - location: anchorTag.dataset.analyticsLocation, + destination: anchorTag.href || anchorTag.getAttribute('href') || '', + location, }); }; } + // Untagged links to intent destinations still get tracked, named by where they go. + function intentEventFor(anchorTag) { + let url; + try { + url = new URL(anchorTag.href); + } catch (e) { + return null; + } + if (url.pathname.replace(/\/$/, '') === '/request-demo') { + return 'RequestDemoClicked'; + } + if (url.hostname === 'console.modular.com' && url.pathname.startsWith('/signup')) { + return 'GetStartedClicked'; + } + return null; + } + // Delay these calls to avoid blocking main thread setTimeout(() => { [...document.querySelectorAll('a')] @@ -29,9 +47,20 @@ export function initAmplitude() { }); }, 200); setTimeout(() => { - [...document.querySelectorAll('[data-analytics-onclick]')].forEach((a) => { - a.onclick = amplitudeTrack(a, a.dataset.analyticsOnclick); - }); + [...document.querySelectorAll('[data-analytics-onclick]')] + .filter((a) => a.dataset.analyticsOnclick) + .forEach((a) => { + a.onclick = amplitudeTrack(a, a.dataset.analyticsOnclick); + }); + + [...document.querySelectorAll('a')] + .filter((a) => !a.dataset.analyticsOnclick) + .forEach((a) => { + const eventName = intentEventFor(a); + if (eventName) { + a.onclick = amplitudeTrack(a, eventName, `Inline-${window.location.pathname}`); + } + }); }, 300); let timeStartedOnPage = new Date();