Skip to content

Commit 62636ad

Browse files
feat: add Google Tag Manager to marketing website (#9148)
* feat: add Google Tag Manager to marketing website using Next.js Script component * refactor: remove Google Ads implementation in favor of Tag Manager * fix: wrap GTM script in consent-checking client component for GDPR compliance --------- Co-authored-by: Roo Code <roomote@roocode.com>
1 parent 4da9c3a commit 62636ad

File tree

5 files changed

+68
-83
lines changed

5 files changed

+68
-83
lines changed

apps/web-roo-code/src/app/shared/AgentLandingContent.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { Button } from "@/components/ui"
1919
import { AnimatedBackground } from "@/components/homepage"
2020
import { AgentCarousel } from "@/components/reviewer/agent-carousel"
2121
import { EXTERNAL_LINKS } from "@/lib/constants"
22-
import { trackGoogleAdsConversion } from "@/lib/analytics/google-ads"
2322
import { type AgentPageContent, type IconName } from "./agent-page-content"
2423

2524
/**
@@ -97,7 +96,6 @@ export function AgentLandingContent({ content }: { content: AgentPageContent })
9796
href={EXTERNAL_LINKS.CLOUD_APP_SIGNUP_PRO}
9897
target="_blank"
9998
rel="noopener noreferrer"
100-
onClick={trackGoogleAdsConversion}
10199
className="flex w-full items-center justify-center">
102100
{content.hero.cta.buttonText}
103101
<ArrowRight className="ml-2" />
@@ -219,7 +217,6 @@ export function AgentLandingContent({ content }: { content: AgentPageContent })
219217
href={EXTERNAL_LINKS.CLOUD_APP_SIGNUP_PRO}
220218
target="_blank"
221219
rel="noopener noreferrer"
222-
onClick={trackGoogleAdsConversion}
223220
className="flex items-center justify-center">
224221
{content.cta.buttonText}
225222
<ArrowRight className="ml-2 h-4 w-4" />

apps/web-roo-code/src/components/providers/google-analytics-provider.tsx

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"use client"
2+
3+
import { useEffect, useState } from "react"
4+
import Script from "next/script"
5+
import { hasConsent, onConsentChange } from "@/lib/analytics/consent-manager"
6+
7+
// Google Tag Manager Container ID
8+
const GTM_ID = "GTM-M2JZHV8N"
9+
10+
/**
11+
* Google Tag Manager Provider
12+
* Loads GTM only after user consent is given, following GDPR requirements
13+
*/
14+
export function GoogleTagManagerProvider({ children }: { children: React.ReactNode }) {
15+
const [shouldLoad, setShouldLoad] = useState(false)
16+
17+
useEffect(() => {
18+
// Check initial consent status
19+
if (hasConsent()) {
20+
setShouldLoad(true)
21+
}
22+
23+
// Listen for consent changes
24+
const unsubscribe = onConsentChange((consented) => {
25+
if (consented) {
26+
setShouldLoad(true)
27+
}
28+
})
29+
30+
return unsubscribe
31+
}, [])
32+
33+
return (
34+
<>
35+
{shouldLoad && (
36+
<>
37+
{/* Google Tag Manager Script */}
38+
<Script
39+
id="google-tag-manager"
40+
strategy="afterInteractive"
41+
dangerouslySetInnerHTML={{
42+
__html: `
43+
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
44+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
45+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
46+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
47+
})(window,document,'script','dataLayer','${GTM_ID}');
48+
`,
49+
}}
50+
/>
51+
{/* Google Tag Manager (noscript) */}
52+
<noscript>
53+
<iframe
54+
src={`https://www.googletagmanager.com/ns.html?id=${GTM_ID}`}
55+
height="0"
56+
width="0"
57+
style={{ display: "none", visibility: "hidden" }}
58+
/>
59+
</noscript>
60+
</>
61+
)}
62+
{children}
63+
</>
64+
)
65+
}

apps/web-roo-code/src/components/providers/providers.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
44
import { ThemeProvider } from "next-themes"
55

6+
import { GoogleTagManagerProvider } from "./google-tag-manager-provider"
67
import { PostHogProvider } from "./posthog-provider"
7-
import { GoogleAnalyticsProvider } from "./google-analytics-provider"
88

99
const queryClient = new QueryClient()
1010

1111
export const Providers = ({ children }: { children: React.ReactNode }) => {
1212
return (
1313
<QueryClientProvider client={queryClient}>
14-
<GoogleAnalyticsProvider>
14+
<GoogleTagManagerProvider>
1515
<PostHogProvider>
1616
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem={false}>
1717
{children}
1818
</ThemeProvider>
1919
</PostHogProvider>
20-
</GoogleAnalyticsProvider>
20+
</GoogleTagManagerProvider>
2121
</QueryClientProvider>
2222
)
2323
}

apps/web-roo-code/src/lib/analytics/google-ads.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)