Skip to content

Commit

Permalink
FIX: prevents google to track certain pages (#7455)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux authored and tgxworld committed Apr 30, 2019
1 parent 1fdeec5 commit c863e62
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
Expand All @@ -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;
}
};

1 comment on commit c863e62

@jjaffeux
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.