Shared analytics, consent (via vanilla-cookieconsent v3), and error-tracking (GlitchTip) for PrudAI marketing sites.
Consumed by prudai-website, product-page-alex, product-page-vera, product-page-zia, legal-center, and trust-center.
bun add github:Prudai/marketing-analytics#v0.3.1 @sentry/react @vercel/speed-insights// src/main.tsx
import { initAnalytics } from "@prudai/marketing-analytics";
import "vanilla-cookieconsent/dist/cookieconsent.css"; // required
initAnalytics({
siteId: "product-page-alex",
environment: import.meta.env.MODE,
release: import.meta.env.VITE_GIT_SHA,
ga4: { measurementId: import.meta.env.VITE_GA4_MEASUREMENT_ID },
googleAds: { conversionId: "AW-XXXXXXXXXXX" }, // optional: Google Ads conversion tag
sentry: { dsn: import.meta.env.VITE_SENTRY_DSN },
consent: { policyHref: "https://legal.prudai.com/privacy" },
});Event helpers:
import { trackCta, trackOutboundClick } from "@prudai/marketing-analytics";
trackCta("Probeer Alex", "hero");
trackOutboundClick("https://app.prudai.com/signup", "hero-signup");Vercel Speed Insights (optional):
import { SpeedInsights } from "@prudai/marketing-analytics";
export function App() {
return (
<>
{/* your app */}
<SpeedInsights />
</>
);
}- Google Consent Mode v2 is set to all denied before
gtag.jsloads. - vanilla-cookieconsent shows an AVG-compliant banner (NL/EN, auto-detects).
- When the user accepts the "analytics" category, we call
gtag('consent', 'update', { analytics_storage: 'granted', ... })and emit apage_viewevent so GA4 Realtime populates. - With
googleAdsconfigured, a "Marketing" category is added to the banner; accepting it grantsad_storage/ad_user_data/ad_personalization. Without acceptance, Google Ads still receives cookieless conversion pings (Consent Mode modeling). Enabling the category also bumps the consentrevision, so returning visitors are asked again once. - Without
googleAds, ad categories stay denied and no Marketing category is shown.
bun install
bun run typecheck
bun test
bun run build