Skip to content
Permalink
Browse files

preconnect to configured Matomo host url

  • Loading branch information...
kremalicious committed Jun 9, 2019
1 parent 89da8bd commit 9b1833060c00c4af23df8597b30a92039c11f7fa
Showing with 23 additions and 6 deletions.
  1. +2 −1 README.md
  2. +21 −5 src/gatsby-ssr.js
@@ -20,7 +20,7 @@

## Features

Plugin uses sensible defaults prioritizing user experience & privacy:
Plugin uses sensible defaults prioritizing user experience, performance & privacy:

- include tracking code in all server-side rendered routes
- track all route views as custom events
@@ -31,6 +31,7 @@ Plugin uses sensible defaults prioritizing user experience & privacy:
- consent mode for privacy
- allow loading tracking script locally
- define paths to be excluded from tracking
- `preconnect` to configured Matomo host url
- dev mode for local development

## Usage
@@ -57,7 +57,20 @@ function buildTrackingCodeNoJs(pluginOptions, pathname) {
)
}

exports.onRenderBody = ({ setPostBodyComponents, pathname }, pluginOptions) => {
function buildHead(pluginOptions) {
return (
<link
rel="preconnect"
href={pluginOptions.matomoUrl}
key={'gatsby-plugin-matomo'}
/>
)
}

exports.onRenderBody = (
{ setHeadComponents, setPostBodyComponents, pathname },
pluginOptions
) => {
let excludePaths = ['/offline-plugin-app-shell-fallback/']

if (typeof pluginOptions.exclude !== 'undefined') {
@@ -72,10 +85,13 @@ exports.onRenderBody = ({ setPostBodyComponents, pathname }, pluginOptions) => {
(process.env.NODE_ENV === 'production' || pluginOptions.dev === true) &&
!isPathExcluded
) {
return setPostBodyComponents([
buildTrackingCode(pluginOptions),
buildTrackingCodeNoJs(pluginOptions, pathname)
])
return (
setHeadComponents([buildHead(pluginOptions)]) &&
setPostBodyComponents([
buildTrackingCode(pluginOptions),
buildTrackingCodeNoJs(pluginOptions, pathname)
])
)
}
return null
}

0 comments on commit 9b18330

Please sign in to comment.
You can’t perform that action at this time.