preconnect to configured Matomo host url

This commit is contained in:
Matthias Kretschmann 2019-06-10 01:47:38 +02:00
parent 89da8bdc05
commit 9b1833060c
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 23 additions and 6 deletions

View File

@ -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

View File

@ -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
}