mirror of
https://github.com/kremalicious/gatsby-plugin-matomo.git
synced 2024-12-22 17:23:23 +01:00
Merge pull request #4 from kremalicious/feature/gatsby-v2
Updates for Gatsby v2
This commit is contained in:
commit
cff8490e21
12
package.json
12
package.json
@ -7,16 +7,18 @@
|
|||||||
"url": "https://github.com/kremalicious/gatsby-plugin-matomo/issues"
|
"url": "https://github.com/kremalicious/gatsby-plugin-matomo/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-runtime": "^6.26.0"
|
"babel-runtime": "^6.26.0",
|
||||||
|
"react": "^16.4.1",
|
||||||
|
"react-hot-loader": "^4.3.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-cli": "^6.26.0",
|
"babel-cli": "^6.26.0",
|
||||||
"babel-preset-env": "^1.7.0",
|
"babel-preset-env": "^1.7.0",
|
||||||
"babel-preset-react": "^6.24.1",
|
"babel-preset-react": "^6.24.1",
|
||||||
"cross-env": "^5.1.5",
|
"cross-env": "^5.2.0",
|
||||||
"eslint": "^4.19.1",
|
"eslint": "^4.19.1",
|
||||||
"eslint-plugin-react": "^7.8.2",
|
"eslint-plugin-react": "^7.9.1",
|
||||||
"release-it": "^7.4.3"
|
"release-it": "^7.4.7"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/kremalicious/gatsby-plugin-matomo",
|
"homepage": "https://github.com/kremalicious/gatsby-plugin-matomo",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -28,7 +30,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"gatsby": "^1.9.0"
|
"gatsby": ">=1.9.0"
|
||||||
},
|
},
|
||||||
"repository": "github:kremalicious/gatsby-plugin-matomo",
|
"repository": "github:kremalicious/gatsby-plugin-matomo",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
function buildTrackingCode(pluginOptions) {
|
function buildTrackingCode(pluginOptions) {
|
||||||
const script = pluginOptions.localScript ? pluginOptions.localScript : `${pluginOptions.matomoUrl}/piwik.js`
|
const script = pluginOptions.localScript
|
||||||
|
? pluginOptions.localScript
|
||||||
|
: `${pluginOptions.matomoUrl}/piwik.js`
|
||||||
|
|
||||||
const html = `
|
const html = `
|
||||||
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 || [];
|
||||||
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(['enableLinkTracking']);
|
window._paq.push(['enableLinkTracking']);
|
||||||
window._paq.push(['trackPageView']);
|
window._paq.push(['trackPageView']);
|
||||||
@ -15,7 +19,9 @@ function buildTrackingCode(pluginOptions) {
|
|||||||
window.start = new Date();
|
window.start = new Date();
|
||||||
if (window.dev === true) {
|
if (window.dev === true) {
|
||||||
console.log('[Matomo] Tracking initialized')
|
console.log('[Matomo] Tracking initialized')
|
||||||
console.log('[Matomo] matomoUrl: ${pluginOptions.matomoUrl}, siteId: ${pluginOptions.siteId}')
|
console.log('[Matomo] matomoUrl: ${pluginOptions.matomoUrl}, siteId: ${
|
||||||
|
pluginOptions.siteId
|
||||||
|
}')
|
||||||
}
|
}
|
||||||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||||
g.defer=true; g.async=true; g.src='${script}'; s.parentNode.insertBefore(g,s);
|
g.defer=true; g.async=true; g.src='${script}'; s.parentNode.insertBefore(g,s);
|
||||||
@ -31,7 +37,10 @@ function buildTrackingCode(pluginOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildTrackingCodeNoJs(pluginOptions, pathname) {
|
function buildTrackingCodeNoJs(pluginOptions, pathname) {
|
||||||
const html = `<img src="${pluginOptions.matomoUrl}/piwik.php?idsite=${pluginOptions.siteId}&rec=1&url=${pluginOptions.siteUrl + pathname}" style="border:0" alt="tracker" />`
|
const html = `<img src="${pluginOptions.matomoUrl}/piwik.php?idsite=${
|
||||||
|
pluginOptions.siteId
|
||||||
|
}&rec=1&url=${pluginOptions.siteUrl +
|
||||||
|
pathname}" style="border:0" alt="tracker" />`
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<noscript
|
<noscript
|
||||||
|
Loading…
Reference in New Issue
Block a user