-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #32
- Loading branch information
pooya parsa
committed
Jun 1, 2020
1 parent
d2fa3c0
commit ec85699
Showing
5 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ dist | |
coverage | ||
|
||
# Plugin | ||
lib/plugin.js | ||
lib/plugin*.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
const defaults = { | ||
dev: true, | ||
enabled: undefined, | ||
|
||
id: null, | ||
id: undefined, | ||
layer: 'dataLayer', | ||
variables: {}, | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// This is a mock version because gtm module is disabled | ||
// You can explicitly enable module using `gtm.enabled: true` in nuxt.config | ||
|
||
const _layer = '<%= options.layer %>' | ||
const _id = '<%= options.id %>' | ||
|
||
function startPageTracking (ctx) { | ||
ctx.app.router.afterEach((to) => { | ||
setTimeout(() => { | ||
ctx.$gtm.push(to.gtm || { | ||
routeName: to.name, | ||
pageType: 'PageView', | ||
pageUrl: '<%= options.routerBase %>' + to.fullPath, | ||
pageTitle: (typeof document !== 'undefined' && document.title) || '', | ||
event: '<%= options.pageViewEventName %>' | ||
}) | ||
}, 250) | ||
}) | ||
} | ||
|
||
export default function (ctx, inject) { | ||
// eslint-disable-next-line no-console | ||
const logSyle = 'background: #2E495E;border-radius: 0.5em;color: white;font-weight: bold;padding: 2px 0.5em;' | ||
const log = (...args) => console.log('%cGTM', logSyle, ...args) | ||
|
||
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); }<% } %> | ||
} |