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

Add support for error tracking [Fixes #168] (#169)

* Add support for error tracking [Fixes #168]

* fix missing cookieDomain

Co-authored-by: Matthias Kretschmann <m@kretschmann.io>
This commit is contained in:
Sam Richards 2021-05-23 02:37:14 -07:00 committed by GitHub
parent 4858debe66
commit ae2e8e7a61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 17 deletions

View File

@ -66,7 +66,7 @@ _NOTE: By default, this plugin only generates output when run in production mode
### Options
| Option | Explanation |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `siteId` | Your Matomo site ID configured in your Matomo installation. |
| `matomoUrl` | The url of your Matomo installation. |
| `siteUrl` | The url of your site, usually the same as `siteMetadata.siteUrl`. Only used for generating the url for `noscript` image tracking fallback. |
@ -81,6 +81,7 @@ _NOTE: By default, this plugin only generates output when run in production mode
| `trackLoad` | (optional) If true, it will track the loading of the matomo library. Defaults to `true`. |
| `respectDnt` | (optional) If false, will load all scripts without respecting user preference to `Do Not Track` on browsers. Defaults to `true`. |
| `dev` | (optional) Activate dev mode by setting to `true`. Will load all scripts despite not running in `production` environment. Ignores your local browser's DNT header too. Outputs some information in console about what it is doing. Useful for local testing but careful: all hits will be send like in production. |
| `enableJSErrorTracking` | (optional) Enable basic JavaScript error tracking and reporting in Matomo by setting to `true`. |
```js
plugins: [
@ -99,7 +100,8 @@ plugins: [
disableCookies: false,
cookieDomain: '*.example.org',
localScript: '/piwik.js',
dev: false
dev: false,
enableJSErrorTracking: true,
}
}
]

View File

@ -93,6 +93,14 @@ describe('gatsby-plugin-google-analytics', () => {
expect(result).toMatch(/disableCookies/)
})
it('sets enableJSErrorTracking', () => {
const { setPostBodyComponents } = setup({
enableJSErrorTracking: true
})
const result = JSON.stringify(setPostBodyComponents.mock.calls[0][0])
expect(result).toMatch(/enableJSErrorTracking/)
})
it('sets localScript', () => {
const { setPostBodyComponents } = setup({
localScript: 'TEST_LOCAL_SCRIPT'

View File

@ -13,6 +13,7 @@ function buildTrackingCode(pluginOptions) {
requireCookieConsent,
disableCookies,
cookieDomain,
enableJSErrorTracking,
respectDnt = true
} = pluginOptions
@ -33,6 +34,11 @@ function buildTrackingCode(pluginOptions) {
: ''
}
${disableCookies ? "window._paq.push(['disableCookies']);" : ''}
${
enableJSErrorTracking
? "window._paq.push(['enableJSErrorTracking']);"
: ''
}
${
cookieDomain
? `window._paq.push(['setCookieDomain', '${cookieDomain}']);`