Skip to content

Commit 5debc51

Browse files
jp-ayyappanclaude
andcommitted
fix(docs): refactor Google Analytics to use config and CSS classes
Address PR review feedback: - Move Google Analytics tracking ID to docusaurus.config.ts customFields - Use useDocusaurusContext hook to access config in Root.tsx - Move cookie consent inline styles to src/css/custom.css - Use CSS classes with Docusaurus theme variables for consistency - Add hover states for improved UX Addresses comments from PR #174 Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 942a659 commit 5debc51

File tree

3 files changed

+61
-46
lines changed

3 files changed

+61
-46
lines changed

docusaurus.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const config: Config = {
3636
trailingSlash: false,
3737
customFields: {
3838
javaSdkVersion,
39+
googleGtagId: 'G-JH0PNJK88L',
3940
},
4041

4142
// GitHub pages deployment config.

src/css/custom.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,54 @@ a[class*="embed_documentation_footer-"] {
200200
}
201201
}
202202

203+
/**************
204+
** COOKIE CONSENT BANNER
205+
***************/
206+
207+
.cookie-consent-banner {
208+
background: #1c1e21;
209+
align-items: center;
210+
padding: 1rem;
211+
}
212+
213+
.cookie-consent-banner a {
214+
color: var(--ifm-color-primary);
215+
text-decoration: underline;
216+
}
217+
218+
.cookie-consent-banner a:hover {
219+
color: var(--ifm-color-primary-light);
220+
}
221+
222+
.cookie-consent-accept-button {
223+
background: var(--ifm-color-primary);
224+
color: #fff;
225+
font-size: 14px;
226+
padding: 10px 24px;
227+
border-radius: 4px;
228+
border: none;
229+
cursor: pointer;
230+
}
231+
232+
.cookie-consent-accept-button:hover {
233+
background: var(--ifm-color-primary-dark);
234+
}
235+
236+
.cookie-consent-decline-button {
237+
background: transparent;
238+
color: #fff;
239+
font-size: 14px;
240+
padding: 10px 24px;
241+
border-radius: 4px;
242+
border: 1px solid #fff;
243+
cursor: pointer;
244+
margin-left: 10px;
245+
}
246+
247+
.cookie-consent-decline-button:hover {
248+
background: rgba(255, 255, 255, 0.1);
249+
}
250+
203251
/**************
204252
** HOMEPAGE
205253

src/theme/Root.tsx

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
import React from 'react';
22
import CookieConsent from 'react-cookie-consent';
3+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
34

4-
// This component wraps the entire application
55
export default function Root({ children }: { children: React.ReactNode }) {
6+
const { siteConfig } = useDocusaurusContext();
7+
const { googleGtagId } = siteConfig.customFields as { googleGtagId?: string };
8+
69
const handleAcceptCookie = () => {
7-
// Initialize Google Analytics when user accepts cookies
8-
if (typeof window !== 'undefined') {
9-
// Load gtag.js script
10+
if (typeof window !== 'undefined' && googleGtagId) {
1011
const script = document.createElement('script');
11-
script.src = 'https://www.googletagmanager.com/gtag/js?id=G-JH0PNJK88L';
12+
script.src = `https://www.googletagmanager.com/gtag/js?id=${googleGtagId}`;
1213
script.async = true;
1314
document.head.appendChild(script);
1415

15-
// Initialize gtag
1616
window.dataLayer = window.dataLayer || [];
1717
function gtag(...args: any[]) {
1818
window.dataLayer.push(args);
1919
}
2020
gtag('js', new Date());
21-
gtag('config', 'G-JH0PNJK88L', { anonymize_ip: true });
22-
23-
// Store gtag globally for future use
21+
gtag('config', googleGtagId, { anonymize_ip: true });
2422
(window as any).gtag = gtag;
2523
}
2624
};
@@ -33,56 +31,24 @@ export default function Root({ children }: { children: React.ReactNode }) {
3331
buttonText="Accept"
3432
declineButtonText="Decline"
3533
cookieName="opentdf-cookie-consent"
36-
style={{
37-
background: '#1c1e21',
38-
alignItems: 'center',
39-
padding: '1rem',
40-
}}
41-
buttonStyle={{
42-
background: '#4CAF50',
43-
color: '#fff',
44-
fontSize: '14px',
45-
padding: '10px 24px',
46-
borderRadius: '4px',
47-
border: 'none',
48-
cursor: 'pointer',
49-
}}
50-
declineButtonStyle={{
51-
background: 'transparent',
52-
color: '#fff',
53-
fontSize: '14px',
54-
padding: '10px 24px',
55-
borderRadius: '4px',
56-
border: '1px solid #fff',
57-
cursor: 'pointer',
58-
marginLeft: '10px',
59-
}}
34+
containerClasses="cookie-consent-banner"
35+
buttonClasses="cookie-consent-accept-button"
36+
declineButtonClasses="cookie-consent-decline-button"
6037
expires={365}
6138
enableDeclineButton
6239
onAccept={handleAcceptCookie}
6340
>
6441
This website uses cookies to improve user experience and analyze website traffic.
6542
By clicking "Accept", you consent to our use of cookies. See our{' '}
66-
<a
67-
href="/privacy-policy"
68-
style={{ color: '#4CAF50', textDecoration: 'underline' }}
69-
>
70-
Privacy Policy
71-
</a>
43+
<a href="/privacy-policy">Privacy Policy</a>
7244
{' '}and{' '}
73-
<a
74-
href="/cookie-policy"
75-
style={{ color: '#4CAF50', textDecoration: 'underline' }}
76-
>
77-
Cookie Policy
78-
</a>
45+
<a href="/cookie-policy">Cookie Policy</a>
7946
{' '}for more information.
8047
</CookieConsent>
8148
</>
8249
);
8350
}
8451

85-
// Extend Window interface for TypeScript
8652
declare global {
8753
interface Window {
8854
dataLayer: any[];

0 commit comments

Comments
 (0)