1
0
mirror of https://github.com/kremalicious/gatsby-plugin-matomo.git synced 2024-12-22 09:13:19 +01:00

Merge pull request #22 from kremalicious/featue/cookie-domain

add cookieDomain setting
This commit is contained in:
Matthias Kretschmann 2020-02-24 01:01:16 +01:00 committed by GitHub
commit 82b7606c6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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
}

View File

@ -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']);