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

Add consent mode

This commit is contained in:
Julien Blatecky 2018-07-29 09:54:01 +02:00
parent a96e8ea5f8
commit 6d2ae9e0d8
2 changed files with 10 additions and 7 deletions

View File

@ -18,6 +18,7 @@ Plugin uses sensible defaults prioritizing user experience & privacy:
- use image tracking fallback for `noscript` - use image tracking fallback for `noscript`
- don't load anything when visitor has Do Not Track enabled - don't load anything when visitor has Do Not Track enabled
- don't load anything in non-production environments - don't load anything in non-production environments
- consent mode for privacy
- allow loading tracking script locally - allow loading tracking script locally
- dev mode for local development - dev mode for local development
@ -51,13 +52,14 @@ _NOTE: By default, this plugin only generates output when run in production mode
## Options ## Options
Option | Explanation Option | Explanation
--------------|--------- -----------------|---------
`siteId` | Your Matomo site ID configured in your Matomo installation. `siteId` | Your Matomo site ID configured in your Matomo installation.
`matomoUrl` | The url of your Matomo installation. `matomoUrl` | The url of your Matomo installation.
`siteUrl` | The url of your site, usually the same as `siteMetadata.siteUrl`. Only used for generating the url for `noscript` image tracking fallback. `siteUrl` | The url of your site, usually the same as `siteMetadata.siteUrl`. Only used for generating the url for `noscript` image tracking fallback.
`localScript` | (optional) Set path to load local `piwik.js` script, instead of loading it from your `matomoUrl`. `requireConsent` | (optional) If true, tracking will be disabled until you call `window._paq.push(['setConsentGiven']);`
`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. `localScript` | (optional) Set path to load local `piwik.js` script, 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.
## Development ## Development

View File

@ -9,6 +9,7 @@ function buildTrackingCode(pluginOptions) {
window.dev = ${pluginOptions.dev} window.dev = ${pluginOptions.dev}
if (window.dev === true || !(navigator.doNotTrack == '1' || window.doNotTrack == '1')) { if (window.dev === true || !(navigator.doNotTrack == '1' || window.doNotTrack == '1')) {
window._paq = window._paq || []; window._paq = window._paq || [];
${pluginOptions.requireConsent ? 'window._paq.push([\'requireConsent\']);' : ''}
window._paq.push(['setTrackerUrl', '${pluginOptions.matomoUrl}/piwik.php']); window._paq.push(['setTrackerUrl', '${pluginOptions.matomoUrl}/piwik.php']);
window._paq.push(['setSiteId', '${pluginOptions.siteId}']); window._paq.push(['setSiteId', '${pluginOptions.siteId}']);
window._paq.push(['trackPageView']); window._paq.push(['trackPageView']);