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

Merge pull request #24 from ArneZsng/master

Add support for custom JS and PHP script names
This commit is contained in:
Matthias Kretschmann 2020-03-22 16:02:01 +01:00 committed by GitHub
commit 30a58365bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -70,6 +70,8 @@ _NOTE: By default, this plugin only generates output when run in production mode
| `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. |
| `matomoPhpScript`| (optional) The name of your Matomo PHP script. Defaults to `piwik.php` |
| `matomoJsScript` | (optional) The name of your Matomo JS script. Defaults to `piwik.js` |
| `exclude` | (optional) Specify an array of pathnames where tracking code will be excluded. The pathname `/offline-plugin-app-shell-fallback/` is excluded by default. | | `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']);`. | | `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. | | `disableCookies` | (optional) If true, no cookie will be used by Matomo. |
@ -86,6 +88,8 @@ plugins: [
matomoUrl: 'https://YOUR_MATOMO_URL.COM', matomoUrl: 'https://YOUR_MATOMO_URL.COM',
siteUrl: 'https://YOUR_LIVE_SITE_URL.COM', siteUrl: 'https://YOUR_LIVE_SITE_URL.COM',
// All the optional settings // All the optional settings
matomoPhpScript: 'piwik.php',
matomoJsScript: 'piwik.js',
exclude: ['/offline-plugin-app-shell-fallback/'], exclude: ['/offline-plugin-app-shell-fallback/'],
requireConsent: false, requireConsent: false,
disableCookies: false, disableCookies: false,

View File

@ -4,6 +4,8 @@ import React from 'react'
function buildTrackingCode(pluginOptions) { function buildTrackingCode(pluginOptions) {
const { const {
matomoUrl, matomoUrl,
matomoPhpScript = 'piwik.php',
matomoJsScript = 'piwik.js',
siteId, siteId,
dev, dev,
localScript, localScript,
@ -12,7 +14,7 @@ function buildTrackingCode(pluginOptions) {
cookieDomain cookieDomain
} = pluginOptions } = pluginOptions
const script = localScript ? localScript : `${matomoUrl}/piwik.js` const script = localScript ? localScript : `${matomoUrl}/${matomoJsScript}`
const html = ` const html = `
window.dev = ${dev} window.dev = ${dev}
@ -21,11 +23,11 @@ function buildTrackingCode(pluginOptions) {
${requireConsent ? "window._paq.push(['requireConsent']);" : ''} ${requireConsent ? "window._paq.push(['requireConsent']);" : ''}
${disableCookies ? "window._paq.push(['disableCookies']);" : ''} ${disableCookies ? "window._paq.push(['disableCookies']);" : ''}
${ ${
cookieDomain cookieDomain
? `window._paq.push(['setCookieDomain', '${cookieDomain}']);` ? `window._paq.push(['setCookieDomain', '${cookieDomain}']);`
: '' : ''
} }
window._paq.push(['setTrackerUrl', '${matomoUrl}/piwik.php']); window._paq.push(['setTrackerUrl', '${matomoUrl}/${matomoPhpScript}']);
window._paq.push(['setSiteId', '${siteId}']); window._paq.push(['setSiteId', '${siteId}']);
window._paq.push(['enableHeartBeatTimer']); window._paq.push(['enableHeartBeatTimer']);
window.start = new Date(); window.start = new Date();
@ -51,8 +53,8 @@ function buildTrackingCode(pluginOptions) {
} }
function buildTrackingCodeNoJs(pluginOptions, pathname) { function buildTrackingCodeNoJs(pluginOptions, pathname) {
const { matomoUrl, siteId, siteUrl } = pluginOptions const { matomoUrl, matomoPhpScript = 'piwik.php', siteId, siteUrl } = pluginOptions
const html = `<img src="${matomoUrl}/piwik.php?idsite=${siteId}&rec=1&url=${siteUrl + const html = `<img src="${matomoUrl}/${matomoPhpScript}?idsite=${siteId}&rec=1&url=${siteUrl +
pathname}" style="border:0" alt="tracker" />` pathname}" style="border:0" alt="tracker" />`
return ( return (