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

Make PHP and JS script names configurable

This commit is contained in:
Arne Zeising 2020-03-21 16:15:27 +01:00
parent e899e371d3
commit 12a4ebed8d

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}
@ -25,7 +27,7 @@ function buildTrackingCode(pluginOptions) {
? `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();
@ -52,7 +54,7 @@ function buildTrackingCode(pluginOptions) {
function buildTrackingCodeNoJs(pluginOptions, pathname) { function buildTrackingCodeNoJs(pluginOptions, pathname) {
const { matomoUrl, siteId, siteUrl } = pluginOptions const { matomoUrl, 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 (