Analytics + Remarketing Layer
The measurement + remarketing foundation. Without consistent events and pixels, conversion work isn’t measurable and there’s no audience to remarket to. This layer gives every component one event funnel and gates ad/remarketing storage behind consent.
src/lib/analytics.ts · src/components/growth/ConsentBanner.tsx · tags in Layout.astro
The event helper
Section titled “The event helper”import { track, trackLead, EVENTS } from '../lib/analytics';
track(EVENTS.ctaClicked, { location: 'hero' });trackLead({ source: 'pricing_page' });One call fans out to GA4 (gtag), GTM (dataLayer), and Meta Pixel (fbq) when each is present. SSR-safe (no-ops on the server).
| Export | Purpose |
|---|---|
track(event, props) | Fire any event across all channels. |
trackLead(props) | The conversion signal — also emits GA4 generate_lead + Meta Lead for audiences/conversions. |
EVENTS | Canonical event-name constants — ctaClicked, formSubmitted, leadCaptured, leadPopupShown, draftRequested, pricingViewed, demoOpened. |
Tags (Layout.astro)
Section titled “Tags (Layout.astro)”| Tag | Loads when |
|---|---|
| GA4 base | always (business.googleAnalyticsId) |
| Google Ads remarketing | business.googleAdsId is set |
| Meta Pixel | business.metaPixelId is set |
Empty in brand.json = nothing loads. Set them to switch remarketing on per brand.
Consent Mode v2
Section titled “Consent Mode v2”Analytics is on by default (AU-first); ad/remarketing storage (ad_storage, ad_user_data, ad_personalization) is denied until consent. The ConsentBanner (global, client:idle) flips them to granted on Accept and persists velocity.consent; once chosen it never re-shows.
Compliance
Section titled “Compliance”Honest analytics-vs-ads split, a clear Accept/Decline banner, and no ad signals fire before consent — suitable for AU and defensible for EU/UK traffic.