Skip to content

Commit 5568a65

Browse files
authored
feat: add basic cookie consent mechanism for analytics (#685)
* feat: add basic cookie consent mechanism for analytics * npm run format * ci: attempt linter fix
1 parent bebd335 commit 5568a65

File tree

6 files changed

+115
-49
lines changed

6 files changed

+115
-49
lines changed

.github/workflows/ci_pr.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ jobs:
5252
workdir: website
5353
continue-on-error: true
5454
- if: ${{ steps.yamllint.outcome == 'failure' }}
55-
run: echo "yamllint" >> results.txt
55+
run: mkdir -p lint && echo "yamllint" >> lint/results.txt
5656
- if: ${{ steps.eslint.outcome == 'failure' }}
57-
run: echo "eslint" >> results.txt
57+
run: mkdir -p lint && echo "eslint" >> lint/results.txt
5858
- uses: actions/upload-artifact@v4
5959
with:
6060
name: lint
@@ -102,7 +102,7 @@ jobs:
102102
env:
103103
GITHUB_TOKEN: ${{ secrets.github_token }}
104104
- if: ${{ always() && steps.prettier.outcome == 'failure' }}
105-
run: echo "prettier" >> results.txt
105+
run: mkdir -p format-lint && echo "prettier" >> format-lint/results.txt
106106
- if: ${{ always() && steps.prettier.outcome == 'failure' }}
107107
uses: actions/upload-artifact@v4
108108
with:

website/docusaurus.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
favicon: 'img/favicon.ico',
1010
organizationName: 'EPMatt',
1111
projectName: 'awesome-ha-blueprints',
12+
scripts: ['/awesome-ha-blueprints/js/google-tag-manager.js'],
1213
themeConfig: {
1314
announcementBar: {
1415
id: 'support_us',

website/package-lock.json

+24-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"clsx": "^2.1.1",
2121
"react": "^19.0.0",
2222
"react-bootstrap-icons": "^1.11.5",
23+
"react-cookie-consent": "^9.0.0",
2324
"react-dom": "^19.0.0",
2425
"react-json-view-lite": "^2.3.0"
2526
},

website/src/pages/index.jsx

+73-44
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,86 @@ import Link from '@docusaurus/Link'
55
import useDocusaurusContext from '@docusaurus/useDocusaurusContext'
66
import useBaseUrl from '@docusaurus/useBaseUrl'
77
import styles from './styles.module.css'
8+
import CookieConsent, { Cookies } from 'react-cookie-consent'
9+
import { useLocation } from '@docusaurus/router'
810

911
export default function Home() {
12+
let location = useLocation()
13+
14+
React.useEffect(() => {
15+
// check if dataLayer exists i.e can we track or not?
16+
if (typeof dataLayer !== 'undefined') {
17+
// send new event to Google Tag Manager
18+
dataLayer.push({ event: 'pageview' })
19+
}
20+
}, [location])
21+
1022
const context = useDocusaurusContext()
1123
const { siteConfig = {} } = context
1224
return (
13-
<Layout title={`${siteConfig.title}`} description={`${siteConfig.tagline}`}>
14-
<header
15-
className={clsx('hero hero--primary', styles.heroBanner)}
16-
style={{ minHeight: '70vh' }}
25+
<>
26+
<CookieConsent
27+
location='bottom'
28+
buttonText='Accept cookies'
29+
cookieName='AnalyticsConsent'
30+
style={{ background: '#2B373B' }}
31+
buttonStyle={{ color: '#4e503b', fontSize: '13px' }}
32+
expires={150}
33+
enableDeclineButton
34+
declineButtonText='Reject cookies'
1735
>
18-
<div className='container'>
19-
<img
20-
alt='Awesome HA Blueprints logo'
21-
src={useBaseUrl('img/logo.svg')}
22-
className='margin-bottom--lg'
23-
style={{ width: 80 }}
24-
/>
25-
<h1 className='hero__title' style={{ color: 'white' }}>
26-
{siteConfig.title}
27-
</h1>
28-
<p className='hero__subtitle' style={{ color: 'white' }}>
29-
A curated collection of blueprints for Home Assistant.
30-
<br />
31-
Reliable, customizable, fully tested by the community.
32-
</p>
33-
<div className={`row margin-top--xl ${styles.buttons}`}>
34-
<div className='col margin-bottom--lg'>
35-
<Link
36-
className={clsx(
37-
'button button button--secondary button--lg margin-horiz--sm',
38-
styles.getStarted,
39-
)}
40-
to={useBaseUrl('docs/introduction')}
41-
>
42-
Get Started
43-
</Link>
44-
</div>
45-
<div className='col margin-bottom--lg'>
46-
<Link
47-
className={clsx(
48-
'button button button--secondary button--lg margin-horiz--sm',
49-
styles.getStarted,
50-
)}
51-
to={useBaseUrl('docs/blueprints')}
52-
>
53-
Browse Blueprints
54-
</Link>
36+
This website uses cookies to enhance the user experience.
37+
</CookieConsent>
38+
<Layout
39+
title={`${siteConfig.title}`}
40+
description={`${siteConfig.tagline}`}
41+
>
42+
<header
43+
className={clsx('hero hero--primary', styles.heroBanner)}
44+
style={{ minHeight: '70vh' }}
45+
>
46+
<div className='container'>
47+
<img
48+
alt='Awesome HA Blueprints logo'
49+
src={useBaseUrl('img/logo.svg')}
50+
className='margin-bottom--lg'
51+
style={{ width: 80 }}
52+
/>
53+
<h1 className='hero__title' style={{ color: 'white' }}>
54+
{siteConfig.title}
55+
</h1>
56+
<p className='hero__subtitle' style={{ color: 'white' }}>
57+
A curated collection of blueprints for Home Assistant.
58+
<br />
59+
Reliable, customizable, fully tested by the community.
60+
</p>
61+
<div className={`row margin-top--xl ${styles.buttons}`}>
62+
<div className='col margin-bottom--lg'>
63+
<Link
64+
className={clsx(
65+
'button button button--secondary button--lg margin-horiz--sm',
66+
styles.getStarted,
67+
)}
68+
to={useBaseUrl('docs/introduction')}
69+
>
70+
Get Started
71+
</Link>
72+
</div>
73+
<div className='col margin-bottom--lg'>
74+
<Link
75+
className={clsx(
76+
'button button button--secondary button--lg margin-horiz--sm',
77+
styles.getStarted,
78+
)}
79+
to={useBaseUrl('docs/blueprints')}
80+
>
81+
Browse Blueprints
82+
</Link>
83+
</div>
5584
</div>
5685
</div>
57-
</div>
58-
</header>
59-
</Layout>
86+
</header>
87+
</Layout>
88+
</>
6089
)
6190
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
;(function (w, d, s, l, i) {
2+
w[l] = w[l] || []
3+
w[l].push({
4+
'gtm.start': new Date().getTime(),
5+
event: 'gtm.js',
6+
})
7+
var f = d.getElementsByTagName(s)[0],
8+
j = d.createElement(s),
9+
dl = l != 'dataLayer' ? '&l=' + l : ''
10+
j.async = true
11+
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl
12+
f.parentNode.insertBefore(j, f)
13+
})(window, document, 'script', 'dataLayer', 'GTM-PGF34H9G')

0 commit comments

Comments
 (0)