@@ -5,7 +5,7 @@ import Script from "next/script"
55import { hasConsent , onConsentChange } from "@/lib/analytics/consent-manager"
66
77// Google Ads Conversion ID
8- const GTM_ID = "AW-17391954825"
8+ const GADS_ID = "AW-17391954825"
99
1010/**
1111 * Google Analytics Provider with Consent Mode v2
@@ -31,12 +31,13 @@ export function GoogleAnalyticsProvider({ children }: { children: React.ReactNod
3131 personalization_storage : "denied" ,
3232 security_storage : "granted" , // Always granted for security
3333 wait_for_update : 2000 , // Wait up to 2 seconds for consent update
34- // Enable cookieless pings for conversion measurement
35- // This allows Google Ads to measure conversions without cookies
36- url_passthrough : true , // Pass click information via URL parameters
37- ads_data_redaction : true , // Redact ads data when consent is denied
3834 } )
3935
36+ // Enable cookieless pings for conversion measurement
37+ // These must be set separately with gtag 'set' command
38+ window . gtag ( "set" , "ads_data_redaction" , true ) // Redact ads data when consent is denied
39+ window . gtag ( "set" , "url_passthrough" , true ) // Pass click information via URL parameters
40+
4041 // Check initial consent status and update if already consented
4142 if ( hasConsent ( ) ) {
4243 updateConsentState ( true )
@@ -63,28 +64,28 @@ export function GoogleAnalyticsProvider({ children }: { children: React.ReactNod
6364 personalization_storage : consented ? "granted" : "denied" ,
6465 } )
6566
66- console . log ( `Google Consent Mode updated: ${ consented ? "granted" : "denied" } ` )
67+ if ( process . env . NODE_ENV === "development" ) {
68+ console . log ( `Google Consent Mode updated: ${ consented ? "granted" : "denied" } ` )
69+ }
6770 }
6871 }
6972
7073 return (
7174 < >
72- { /* Google tag (gtag.js) - Loads immediately for Consent Mode v2 */ }
75+ { /* Google tag (gtag.js) - Loads with Consent Mode v2 */ }
7376 < Script
74- src = { `https://www.googletagmanager.com/gtag/js?id=${ GTM_ID } ` }
77+ src = { `https://www.googletagmanager.com/gtag/js?id=${ GADS_ID } ` }
7578 strategy = "afterInteractive"
7679 onLoad = { ( ) => {
77- console . log ( "Google Analytics loaded with Consent Mode v2" )
80+ if ( process . env . NODE_ENV === "development" ) {
81+ console . log ( "Google Analytics loaded with Consent Mode v2" )
82+ }
7883 } }
7984 />
80- < Script id = "google-analytics-consent-mode " strategy = "afterInteractive" >
85+ < Script id = "google-ads-config " strategy = "afterInteractive" >
8186 { `
82- window.dataLayer = window.dataLayer || [];
83- function gtag(){dataLayer.push(arguments);}
84- gtag('js', new Date());
85-
86- // Configure with enhanced measurement and cookieless pings
87- gtag('config', '${ GTM_ID } ', {
87+ // Configure Google Ads with enhanced measurement
88+ gtag('config', '${ GADS_ID } ', {
8889 allow_google_signals: false, // Disable by default, enabled when consent granted
8990 allow_ad_personalization_signals: false, // Disable by default
9091 // Enable enhanced conversions for better measurement
0 commit comments