All files / src/scripts whatsapp-click.ts

100% Statements 4/4
100% Branches 2/2
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20                            7x 7x     1x  
// `whatsapp_click` tracking (#1086).
//
// Every www WhatsApp CTA (floater, home hero, designer contact card,
// how-it-works, find-us badge) is a plain `wa.me` link. One delegated
// listener on document pushes one GA4 `whatsapp_click` (via GTM) per tap,
// covering links rendered after view-transition navs too. Imported once from
// Layout.astro's bundled script, so it registers once per full page load.
// The shared helper picks chat links and reads `data-cta-location`.
 
import { whatsappClickParams } from "@interioring/utils/analytics/whatsapp-click";
import { pushDataLayerEvent } from "../lib/gtm";
import { firstTouch } from "./attribution";
 
export function handleWhatsAppClick(e: MouseEvent): void {
	const params = whatsappClickParams(e.target, location.pathname, firstTouch());
	if (params) pushDataLayerEvent("whatsapp_click", params);
}
 
document.addEventListener("click", handleWhatsAppClick);