Skip to content

Commit

Permalink
feat(google-tag-manager): add pageViewEventName option (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
reegodev authored and pi0 committed Oct 7, 2019
1 parent f0dd65f commit f718a6a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/google-tag-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ id: () => {
id: 'GTM-XXXXXXX',
layer: 'dataLayer',
pageTracking: false,
pageViewEventName: 'nuxtRoute',
respectDoNotTrack: false,
dev: true, // set to false to disable in dev mode
query: {
Expand All @@ -62,6 +63,8 @@ You can optionally set `pageTracking` option to `true` to track page views.

This is disabled by default to prevent double events when using alongside with Google Analytics so take care before enabling this option.

The default event name for page views is "nuxtRoute", you can change it by setting the `pageViewEventName` option.

## Usage

### Pushing events
Expand Down
1 change: 1 addition & 0 deletions packages/google-tag-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = async function nuxtTagManager(_options) {
id: null,
layer: 'dataLayer',
pageTracking: false,
pageViewEventName: 'nuxtRoute',
respectDoNotTrack: false,
dev: true,
query: {},
Expand Down
2 changes: 1 addition & 1 deletion packages/google-tag-manager/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GTM {
initPageTracking() {
this.ctx.app.router.afterEach((to, from) => {
setTimeout(() => {
window[this.options.layer].push(to.gtm || { event: 'nuxtRoute', pageType: 'PageView', pageUrl: to.fullPath, routeName: to.name })
window[this.options.layer].push(to.gtm || { event: this.options.pageViewEventName, pageType: 'PageView', pageUrl: to.fullPath, routeName: to.name })
}, 0)
})
}
Expand Down

0 comments on commit f718a6a

Please sign in to comment.