FIX: prevents google to track certain pages (#7455)

This commit is contained in:
Joffrey JAFFEUX 2019-04-30 07:59:55 +02:00 committed by Guo Xiang Tan
parent 1fdeec564b
commit c863e62998
1 changed files with 23 additions and 1 deletions

View File

@ -24,6 +24,8 @@ export default {
// if it is present
if (typeof window._gaq !== "undefined") {
appEvents.on("page:changed", data => {
if (!this._shouldTrack(data.currentRouteName)) return;
window._gaq.push(["_set", "title", data.title]);
window._gaq.push(["_trackPageview", data.url]);
});
@ -33,13 +35,33 @@ export default {
// Also use Universal Analytics if it is present
if (typeof window.ga !== "undefined") {
appEvents.on("page:changed", data => {
if (!this._shouldTrack(data.currentRouteName)) return;
window.ga("send", "pageview", { page: data.url, title: data.title });
});
}
// And Google Tag Manager too
if (typeof window.dataLayer !== "undefined") {
appEvents.on("page:changed", googleTagManagerPageChanged);
appEvents.on("page:changed", data => {
if (!this._shouldTrack(data.currentRouteName)) return;
googleTagManagerPageChanged(data);
});
}
},
_shouldTrack(routeName) {
const excludedRoutes = [
"adminSiteText.index",
"adminSiteText.edit",
"adminSiteSettingsCategory"
];
if (excludedRoutes.includes(routeName)) {
return false;
}
return true;
}
};