Skip to content

Commit 21bd760

Browse files
feat: add HubSpot tracking with consent-based loading (#10885)
Co-authored-by: Roo Code <roomote@roocode.com>
1 parent 971885d commit 21bd760

3 files changed

Lines changed: 84 additions & 9 deletions

File tree

apps/web-roo-code/src/app/legal/cookies/page.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ export default function CookiePolicy() {
100100
<td className="border border-border px-4 py-3">1 year</td>
101101
<td className="border border-border px-4 py-3 font-mono text-sm">ph_*</td>
102102
</tr>
103+
<tr>
104+
<td className="border border-border px-4 py-3 font-medium">HubSpot</td>
105+
<td className="border border-border px-4 py-3">
106+
Marketing automation and visitor tracking
107+
</td>
108+
<td className="border border-border px-4 py-3">
109+
Analytics (only with your consent)
110+
</td>
111+
<td className="border border-border px-4 py-3">13 months</td>
112+
<td className="border border-border px-4 py-3 font-mono text-sm">
113+
hubspotutk, __hstc, __hssrc, __hssc
114+
</td>
115+
</tr>
103116
</tbody>
104117
</table>
105118
</div>
@@ -122,6 +135,15 @@ export default function CookiePolicy() {
122135
PostHog Privacy Policy
123136
</a>
124137
</p>
138+
<p>
139+
<a
140+
href="https://legal.hubspot.com/privacy-policy"
141+
target="_blank"
142+
rel="noopener noreferrer"
143+
className="text-primary hover:underline">
144+
HubSpot Privacy Policy
145+
</a>
146+
</p>
125147

126148
<h2 className="mt-12 text-2xl font-bold">Essential cookies</h2>
127149
<p>
@@ -133,10 +155,10 @@ export default function CookiePolicy() {
133155

134156
<h2 className="mt-12 text-2xl font-bold">Analytics cookies</h2>
135157
<p>
136-
We use PostHog analytics cookies to understand how visitors interact with our website. This
137-
helps us improve our services and user experience. Analytics cookies are placed only if you give
138-
consent through our cookie banner. The lawful basis for processing these cookies is your
139-
consent, which you can withdraw at any time.
158+
We use PostHog and HubSpot analytics cookies to understand how visitors interact with our
159+
website. This helps us improve our services, user experience, and marketing efforts. Analytics
160+
cookies are placed only if you give consent through our cookie banner. The lawful basis for
161+
processing these cookies is your consent, which you can withdraw at any time.
140162
</p>
141163

142164
<h2 className="mt-12 text-2xl font-bold">Third-party services</h2>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
// HubSpot Account ID
8+
const HUBSPOT_ID = "243714031"
9+
10+
/**
11+
* HubSpot Tracking Provider
12+
* Loads HubSpot tracking script only after user consent is given, following GDPR requirements
13+
*/
14+
export function HubSpotProvider({ 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+
{/* HubSpot Embed Code */}
38+
<Script
39+
id="hs-script-loader"
40+
src={`//js-na2.hs-scripts.com/${HUBSPOT_ID}.js`}
41+
strategy="afterInteractive"
42+
async
43+
defer
44+
/>
45+
</>
46+
)}
47+
{children}
48+
</>
49+
)
50+
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
44
import { ThemeProvider } from "next-themes"
55

66
import { GoogleTagManagerProvider } from "./google-tag-manager-provider"
7+
import { HubSpotProvider } from "./hubspot-provider"
78
import { PostHogProvider } from "./posthog-provider"
89

910
const queryClient = new QueryClient()
@@ -12,11 +13,13 @@ export const Providers = ({ children }: { children: React.ReactNode }) => {
1213
return (
1314
<QueryClientProvider client={queryClient}>
1415
<GoogleTagManagerProvider>
15-
<PostHogProvider>
16-
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem={false}>
17-
{children}
18-
</ThemeProvider>
19-
</PostHogProvider>
16+
<HubSpotProvider>
17+
<PostHogProvider>
18+
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem={false}>
19+
{children}
20+
</ThemeProvider>
21+
</PostHogProvider>
22+
</HubSpotProvider>
2023
</GoogleTagManagerProvider>
2124
</QueryClientProvider>
2225
)

0 commit comments

Comments
 (0)