Skip to content
This repository was archived by the owner on Apr 7, 2025. It is now read-only.

Commit 42b0130

Browse files
author
Joel Worrall
committed
feat: adding cookie dialog
1 parent 58c23e9 commit 42b0130

File tree

4 files changed

+118
-27
lines changed

4 files changed

+118
-27
lines changed

gatsby-config.js

+12
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ module.exports = {
160160
// }
161161
}
162162
}
163+
},
164+
{
165+
resolve: `gatsby-plugin-gdpr-cookies`,
166+
options: {
167+
googleTagManager: {
168+
trackingId: 'BLAH', // leave empty if you want to disable the tracker
169+
cookieName: 'newrelic-gdpr-consent', // default
170+
dataLayerName: 'dataLayer', // default
171+
},
172+
// defines the environments where the tracking should be available - default is ["production"]
173+
environments: ['production', 'development']
174+
},
163175
}
164176
]
165177
};

package-lock.json

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

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"feather-icons": "^4.28.0",
1010
"gatsby": "^2.22.11",
1111
"gatsby-image": "^2.4.5",
12+
"gatsby-plugin-gdpr-cookies": "^1.0.7",
1213
"gatsby-plugin-manifest": "^2.4.9",
1314
"gatsby-plugin-mdx": "^1.2.12",
1415
"gatsby-plugin-newrelic": "https://github.com/newrelic/gatsby-plugin-newrelic.git#5cd42e832f0588764dc332ce7ebd05794de5106a",
@@ -22,6 +23,7 @@
2223
"gatsby-source-filesystem": "^2.3.8",
2324
"gatsby-transformer-json": "^2.4.3",
2425
"gatsby-transformer-sharp": "^2.5.3",
26+
"js-cookie": "^2.2.1",
2527
"js-search": "^2.0.0",
2628
"lodash": "^4.17.15",
2729
"node-sass": "^4.14.1",

src/components/CookieApprovalDialog.js

+61-27
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,69 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import styles from './CookieApprovalDialog.module.scss';
44
import withDarkMode from './withDarkMode';
5+
import Cookies from 'js-cookie';
56

6-
const CookieApprovalDialog = ({ className, darkMode }) => {
7-
return (
8-
<div className={`${styles.container} ${className || ''}`}>
9-
<div className={styles.content}>
10-
{/* <X className={styles.buttonClose} size={18} /> */}
11-
<div className={styles.primaryContent}>
12-
<h4 className={styles.heading}>This site uses cookies 🍪</h4>
13-
<p className={styles.description}>
14-
We rely on cookies to play videos, remember your preferences, and
15-
analyze our website traffic. You consent to our cookies if you click
16-
“OK”.
17-
</p>
18-
</div>
19-
<div className={styles.ctaContainer}>
20-
<button className={`button ${styles.approvalButton}`} type="button">
21-
OK
22-
</button>
23-
<button
24-
className={`button button-tertiary ${styles.ignoreButton}`}
25-
type="button"
26-
>
27-
Reject
28-
</button>
7+
class CookieApprovalDialog extends React.Component {
8+
constructor(props) {
9+
super(props);
10+
this.state = {
11+
cookieSet: Cookies.get('newrelic-gdpr-consent') !== undefined
12+
};
13+
this.writeCookies = this.writeCookies.bind(this);
14+
}
15+
16+
writeCookies(answer) {
17+
Cookies.set('newrelic-gdpr-consent', !!answer, {
18+
expires: 365
19+
});
20+
// console.debug(Cookies.get('newrelic-gdpr-consent'));
21+
this.setState({ cookieSet: true });
22+
}
23+
24+
render() {
25+
const { className, darkMode } = this.props; // eslint-disable-line no-unused-vars
26+
// console.debug(this.state.cookieSet);
27+
return (
28+
!this.state.cookieSet && (
29+
<div className={`${styles.container} ${className || ''}`}>
30+
<div className={styles.content}>
31+
{/* <X className={styles.buttonClose} size={18} /> */}
32+
<div className={styles.primaryContent}>
33+
<h4 className={styles.heading}>
34+
This site uses tracking cookies 🍪
35+
</h4>
36+
<p className={styles.description}>
37+
We rely on tracking instrumentation to deliver an optimal
38+
experience across our sites. If you consent to our cookies,
39+
please click “OK”.
40+
</p>
41+
</div>
42+
<div className={styles.ctaContainer}>
43+
<button
44+
className={`button ${styles.approvalButton}`}
45+
type="button"
46+
onClick={() => {
47+
this.writeCookies(true);
48+
}}
49+
>
50+
OK
51+
</button>
52+
<button
53+
className={`button button-tertiary ${styles.ignoreButton}`}
54+
type="button"
55+
onClick={() => {
56+
this.writeCookies(false);
57+
}}
58+
>
59+
Reject
60+
</button>
61+
</div>
62+
</div>
2963
</div>
30-
</div>
31-
</div>
32-
);
33-
};
64+
)
65+
);
66+
}
67+
}
3468

3569
CookieApprovalDialog.propTypes = {
3670
className: PropTypes.string,

0 commit comments

Comments
 (0)