Skip to content

Commit e3c4f5c

Browse files
author
Andréas HANSS
committed
Add feature usePathAnalytics.
1 parent 41f26e7 commit e3c4f5c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const install = function (Vue, initConf = {}) {
1212
/*eslint-disable*/
1313
// Load the analytics snippet
1414
(function (i, s, o, g, r, a, m) {
15-
i[ 'GoogleAnalyticsObject' ] = r;
16-
i[ r ] = i[ r ] || function () {
17-
(i[ r ].q = i[ r ].q || []).push(arguments)
18-
}, i[ r ].l = 1 * new Date();
15+
i['GoogleAnalyticsObject'] = r;
16+
i[r] = i[r] || function () {
17+
(i[r].q = i[r].q || []).push(arguments)
18+
}, i[r].l = 1 * new Date();
1919
a = s.createElement(o),
20-
m = s.getElementsByTagName(o)[ 0 ];
20+
m = s.getElementsByTagName(o)[0];
2121
a.async = 1;
2222
a.src = g;
2323
m.parentNode.insertBefore(a, m)
@@ -83,8 +83,11 @@ const initVueRouterGuard = function (Vue, vueRouter, ignoredViews, trackPage) {
8383
return
8484
}
8585

86-
// Dispatch vue event using meta analytics value if defined otherwise fallback to route name
87-
Vue.analytics.trackView(to.meta.analytics || to.name, trackPage)
86+
// If specified : the system will use the path instead of the route name.
87+
const viewName = to.meta.usePathAnalytics ? to.path : to.name
88+
89+
// Dispatch vue event using meta analytics value if defined otherwise fallback to route name/path.
90+
Vue.analytics.trackView(to.meta.analytics || viewName, trackPage)
8891
})
8992

9093
return ignoredViews

0 commit comments

Comments
 (0)