1
0
mirror of https://github.com/kremalicious/gatsby-plugin-matomo.git synced 2024-12-22 17:23:23 +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. |
| `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. |
| `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. |
| `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. |
@ -86,6 +88,8 @@ plugins: [
matomoUrl: 'https://YOUR_MATOMO_URL.COM',
siteUrl: 'https://YOUR_LIVE_SITE_URL.COM',
// All the optional settings
matomoPhpScript: 'piwik.php',
matomoJsScript: 'piwik.js',
exclude: ['/offline-plugin-app-shell-fallback/'],
requireConsent: false,
disableCookies: false,

View File

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