From 0867187becae0020de721d270853ece01a10eb69 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Mon, 24 Feb 2020 00:48:12 +0100 Subject: [PATCH] add cookieDomain setting --- README.md | 2 ++ src/gatsby-ssr.js | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b114cc0..0a6e65c 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ _NOTE: By default, this plugin only generates output when run in production mode | `exclude` | (optional) Specify an array of pathnames where tracking code will be excluded. The pathname `/offline-plugin-app-shell-fallback/` is excluded by default. | | `requireConsent` | (optional) If true, tracking will be disabled until you call `window._paq.push(['setConsentGiven']);`. | | `disableCookies` | (optional) If true, no cookie will be used by Matomo. | +| `cookieDomain` | (optional) Specify cookie domain. | | `localScript` | (optional) If set, load local `piwik.js` script from the given path, instead of loading it from your `matomoUrl`. | | `dev` | (optional) Activate dev mode by setting to `true`. Will load all scripts despite not running in `production` environment. Ignores your local browser's DNT header too. Outputs some information in console about what it is doing. Useful for local testing but careful: all hits will be send like in production. | @@ -88,6 +89,7 @@ plugins: [ exclude: ['/offline-plugin-app-shell-fallback/'], requireConsent: false, disableCookies: false, + cookieDomain: '*.example.org', localScript: '/piwik.js', dev: false } diff --git a/src/gatsby-ssr.js b/src/gatsby-ssr.js index 1dfaa1f..d8e9e15 100644 --- a/src/gatsby-ssr.js +++ b/src/gatsby-ssr.js @@ -8,7 +8,8 @@ function buildTrackingCode(pluginOptions) { dev, localScript, requireConsent, - disableCookies + disableCookies, + cookieDomain } = pluginOptions const script = localScript ? localScript : `${matomoUrl}/piwik.js` @@ -19,6 +20,11 @@ function buildTrackingCode(pluginOptions) { window._paq = window._paq || []; ${requireConsent ? "window._paq.push(['requireConsent']);" : ''} ${disableCookies ? "window._paq.push(['disableCookies']);" : ''} + ${ + cookieDomain + ? `window._paq.push(['setCookieDomain', '${cookieDomain}']);` + : '' + } window._paq.push(['setTrackerUrl', '${matomoUrl}/piwik.php']); window._paq.push(['setSiteId', '${siteId}']); window._paq.push(['enableHeartBeatTimer']);