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:
commit
7a2b3962d0
@ -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
|
||||||
|
@ -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 (
|
||||||
|
setHeadComponents([buildHead(pluginOptions)]) &&
|
||||||
|
setPostBodyComponents([
|
||||||
buildTrackingCode(pluginOptions),
|
buildTrackingCode(pluginOptions),
|
||||||
buildTrackingCodeNoJs(pluginOptions, pathname)
|
buildTrackingCodeNoJs(pluginOptions, pathname)
|
||||||
])
|
])
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user