Skip to content

Commit aac2fa5

Browse files
authored
fix(docs): add GA4 consent mode to enable analytics tracking (#230)
- Add default consent configuration before gtag config - Grant analytics_storage to allow page view tracking - Deny ad_storage, ad_user_data, ad_personalization (no ads) Fixes #229
1 parent b863dee commit aac2fa5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docs/.vitepress/theme/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ function initGoogleAnalytics() {
3333
window.gtag = function (...args: unknown[]) {
3434
window.dataLayer!.push(args);
3535
};
36+
37+
// Set default consent - required for GA4 to send data
38+
// This grants analytics by default (no ads tracking)
39+
window.gtag("consent", "default", {
40+
analytics_storage: "granted",
41+
ad_storage: "denied",
42+
ad_user_data: "denied",
43+
ad_personalization: "denied",
44+
});
45+
3646
window.gtag("js", new Date());
3747
// Disable automatic page_view - we send manually to track SPA navigation
3848
window.gtag("config", GA_ID, { send_page_view: false });

0 commit comments

Comments
 (0)