Skip to content

Commit

Permalink
Merge pull request #4 from kremalicious/feature/gatsby-v2
Browse files Browse the repository at this point in the history
Updates for Gatsby v2
  • Loading branch information
kremalicious authored Jun 19, 2018
2 parents c531e47 + 356e68f commit cff8490
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
"url": "https://github.com/kremalicious/gatsby-plugin-matomo/issues"
},
"dependencies": {
"babel-runtime": "^6.26.0"
"babel-runtime": "^6.26.0",
"react": "^16.4.1",
"react-hot-loader": "^4.3.3"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"cross-env": "^5.1.5",
"cross-env": "^5.2.0",
"eslint": "^4.19.1",
"eslint-plugin-react": "^7.8.2",
"release-it": "^7.4.3"
"eslint-plugin-react": "^7.9.1",
"release-it": "^7.4.7"
},
"homepage": "https://github.com/kremalicious/gatsby-plugin-matomo",
"keywords": [
Expand All @@ -28,7 +30,7 @@
"license": "MIT",
"main": "index.js",
"peerDependencies": {
"gatsby": "^1.9.0"
"gatsby": ">=1.9.0"
},
"repository": "github:kremalicious/gatsby-plugin-matomo",
"scripts": {
Expand Down
17 changes: 13 additions & 4 deletions src/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import React from 'react'

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 = `
window.dev = ${pluginOptions.dev}
if (window.dev === true || !(navigator.doNotTrack == '1' || window.doNotTrack == '1')) {
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(['enableLinkTracking']);
window._paq.push(['trackPageView']);
window._paq.push(['enableHeartBeatTimer']);
window.start = new Date();
if (window.dev === true) {
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];
g.defer=true; g.async=true; g.src='${script}'; s.parentNode.insertBefore(g,s);
Expand All @@ -31,7 +37,10 @@ function buildTrackingCode(pluginOptions) {
}

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 (
<noscript
Expand Down

0 comments on commit cff8490

Please sign in to comment.