FIX: prevents google to track certain pages (#7463)
This commit is contained in:
parent
2ebe9e3a8b
commit
8e68244eea
|
@ -24,8 +24,10 @@ export default {
|
|||
// if it is present
|
||||
if (typeof window._gaq !== "undefined") {
|
||||
appEvents.on("page:changed", data => {
|
||||
window._gaq.push(["_set", "title", data.title]);
|
||||
window._gaq.push(["_trackPageview", data.url]);
|
||||
if (!data.replacedOnlyQueryParams) {
|
||||
window._gaq.push(["_set", "title", data.title]);
|
||||
window._gaq.push(["_trackPageview", data.url]);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -33,13 +35,19 @@ export default {
|
|||
// Also use Universal Analytics if it is present
|
||||
if (typeof window.ga !== "undefined") {
|
||||
appEvents.on("page:changed", data => {
|
||||
window.ga("send", "pageview", { page: data.url, title: data.title });
|
||||
if (!data.replacedOnlyQueryParams) {
|
||||
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 (!data.replacedOnlyQueryParams) {
|
||||
googleTagManagerPageChanged(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -15,7 +15,12 @@ export function startPageTracking(router, appEvents) {
|
|||
if (_started) {
|
||||
return;
|
||||
}
|
||||
router.on("routeDidChange", () => {
|
||||
router.on("routeDidChange", transition => {
|
||||
// we ocassionally prevent tracking of replaced pages when only query params changed
|
||||
// eg: google analytics
|
||||
const replacedOnlyQueryParams =
|
||||
transition.urlMethod === "replace" && transition.queryParamsOnly;
|
||||
|
||||
router.send("refreshTitle");
|
||||
const url = Discourse.getURL(router.get("url"));
|
||||
|
||||
|
@ -23,10 +28,12 @@ export function startPageTracking(router, appEvents) {
|
|||
// next runloop to have the correct title.
|
||||
Ember.run.next(() => {
|
||||
let title = Discourse.get("_docTitle");
|
||||
|
||||
appEvents.trigger("page:changed", {
|
||||
url,
|
||||
title,
|
||||
currentRouteName: router.get("currentRouteName")
|
||||
currentRouteName: router.get("currentRouteName"),
|
||||
replacedOnlyQueryParams
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue