-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathplugin.mock.js
More file actions
37 lines (33 loc) · 1.04 KB
/
plugin.mock.js
File metadata and controls
37 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// This is a mock version because gtm module is disabled
// You can explicitly enable module using `gtm.enabled: true` in nuxt.config
import { log } from './gtm.utils'
import Vue from 'vue'
const _layer = '<%= options.layer %>'
const _id = '<%= options.id %>'
function startPageTracking (ctx) {
ctx.app.router.afterEach((to) => {
Vue.nextTick().then(() => {
ctx.$gtm.push(to.gtm || {
routeName: to.name,
pageType: 'PageView',
pageUrl: '<%= options.routerBase %>' + to.fullPath,
pageTitle: (typeof document !== 'undefined' && document.title) || '',
event: '<%= options.pageViewEventName %>'
})
})
})
}
export default function (ctx, inject) {
log('Using mocked API. Real GTM events will not be reported.')
const gtm = {
init: (id) => {
log('init', id)
},
push: (event) => {
log('push', process.client ? event : JSON.stringify(event))
}
}
ctx.$gtm = gtm
inject('gtm', gtm)
<% if (options.pageTracking) { %>if (process.client) { startPageTracking(ctx); }<% } %>
}