Skip to content

Commit

Permalink
released the 1.1.0 version:
Browse files Browse the repository at this point in the history
- added new configuration option: cookieFlags for Google Analytics and Google Ads
  • Loading branch information
Andreas Straub committed Jun 7, 2020
1 parent 9dd106f commit c07420e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ module.exports = {
// The property ID; the tracking code won't be generated without it.
trackingId: 'YOUR_GOOGLE_ANALYTICS_TRACKING_ID',
// Defines it google analytics should be started with out the cookie consent
autoStart: false, // <--- default
autoStart: true, // <--- default
// Setting this parameter is optional
anonymize: true, // <--- default
// Name of the cookie, that enables the tracking if it is true
controlCookieName: 'gdpr-analytics-enabled' // <--- default
controlCookieName: 'gdpr-analytics-enabled', // <--- default
cookieFlags: 'secure;samesite=none' // <--- default
},
googleAds: {
// The property ID; the tracking code won't be generated without it.
trackingId: 'YOUR_GOOGLE_ADS_TRACKING_ID',
// Setting this parameter is optional
anonymize: true, // <--- default
// Name of the cookie, that enables the tracking if it is true
controlCookieName: 'gdpr-marketing-enabled' // <--- default
controlCookieName: 'gdpr-marketing-enabled', // <--- default
cookieFlags: 'secure;samesite=none' // <--- default
},
hotjar: {
// The Hotjar ID; the tracking code won't be generated without it.
Expand Down Expand Up @@ -170,6 +172,18 @@ Some countries (such as Germany) require you to use the

Name of the control cookie. If the value of this cookie it set to `true`, then tracking is activated

#### `cookieFlags`

The new `cookieFlags` field allows you to set any cookie directive when the Google Analytics cookie is created.

The value of this setting is a semi-colon separated list of lowercase cookie directives and their respective values. For example, this is a possible value of cookieFlags:

`max-age=7200;domain=simoahava.com;path=/;secure;samesite=none`

The default value is: `secure;samesite=none`

See more details here: https://www.simoahava.com/analytics/cookieflags-field-google-analytics/

### Hotjar `hotjar` configuration object:

#### `trackingId`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-plugin-gdpr-tracking",
"description": "Gatsby Plugin to add analytics and tracking services: Google Analytics, Google Ads and Hotjar in a gdpr form.",
"version": "1.0.8",
"version": "1.1.0",
"author": "Andreas Straub",
"bugs": {
"url": "https://github.com/andreas-straub/gatsby-plugin-gdpr-tracking/issues"
Expand Down
12 changes: 8 additions & 4 deletions src/gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ const defaultOptions = {
googleAnalytics: {
anonymize: true,
controlCookieName: 'gdpr-analytics-enabled',
autoStart: true
autoStart: true,
cookieFlags: 'secure;samesite=none'
},
googleAds: {
controlCookieName: 'gdpr-marketing-enabled',
anonymize: true
anonymize: true,
cookieFlags: 'secure;samesite=none'
},
hotjar: {
controlCookieName: 'gdpr-analytics-enabled',
Expand Down Expand Up @@ -97,7 +99,8 @@ export const onRouteUpdate = ({location}, {environments = defaultOptions.environ
}
gtag('config', googleAnalyticsOpt.trackingId, {
'anonymize_ip': googleAnalyticsOpt.anonymize.toString(),
'page_path': location.pathname
'page_path': location.pathname,
'cookie_flags': googleAnalyticsOpt.cookieFlags
});
} else {
if (debug) {
Expand Down Expand Up @@ -126,7 +129,8 @@ export const onRouteUpdate = ({location}, {environments = defaultOptions.environ
if (Cookies.get(googleAdsOpt.controlCookieName) === "true" && googleAdsOpt.trackingId) {
gtag('config', googleAdsOpt.trackingId, {
'anonymize_ip': googleAdsOpt.anonymize.toString(),
'page_path': location.pathname
'page_path': location.pathname,
'cookie_flags': googleAdsOpt.cookieFlags
});
}
};
Expand Down

0 comments on commit c07420e

Please sign in to comment.