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

Merge pull request #17 from kremalicious/feature/preconnect

preconnect to configured Matomo host url
This commit is contained in:
Matthias Kretschmann 2019-06-10 02:33:03 +02:00 committed by GitHub
commit 7a2b3962d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View File

@ -20,7 +20,7 @@
## Features ## 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 - include tracking code in all server-side rendered routes
- track all route views as custom events - track all route views as custom events
@ -31,6 +31,7 @@ Plugin uses sensible defaults prioritizing user experience & privacy:
- consent mode for privacy - consent mode for privacy
- allow loading tracking script locally - allow loading tracking script locally
- define paths to be excluded from tracking - define paths to be excluded from tracking
- `preconnect` to configured Matomo host url
- dev mode for local development - dev mode for local development
## Usage ## 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/'] let excludePaths = ['/offline-plugin-app-shell-fallback/']
if (typeof pluginOptions.exclude !== 'undefined') { if (typeof pluginOptions.exclude !== 'undefined') {
@ -72,10 +85,13 @@ exports.onRenderBody = ({ setPostBodyComponents, pathname }, pluginOptions) => {
(process.env.NODE_ENV === 'production' || pluginOptions.dev === true) && (process.env.NODE_ENV === 'production' || pluginOptions.dev === true) &&
!isPathExcluded !isPathExcluded
) { ) {
return setPostBodyComponents([ return (
buildTrackingCode(pluginOptions), setHeadComponents([buildHead(pluginOptions)]) &&
buildTrackingCodeNoJs(pluginOptions, pathname) setPostBodyComponents([
]) buildTrackingCode(pluginOptions),
buildTrackingCodeNoJs(pluginOptions, pathname)
])
)
} }
return null return null
} }