mirror of
https://github.com/discourse/discourse.git
synced 2025-03-04 06:49:39 +08:00
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 it is present
|
||||||
if (typeof window._gaq !== "undefined") {
|
if (typeof window._gaq !== "undefined") {
|
||||||
appEvents.on("page:changed", data => {
|
appEvents.on("page:changed", data => {
|
||||||
window._gaq.push(["_set", "title", data.title]);
|
if (!data.replacedOnlyQueryParams) {
|
||||||
window._gaq.push(["_trackPageview", data.url]);
|
window._gaq.push(["_set", "title", data.title]);
|
||||||
|
window._gaq.push(["_trackPageview", data.url]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -33,13 +35,19 @@ export default {
|
|||||||
// Also use Universal Analytics if it is present
|
// Also use Universal Analytics if it is present
|
||||||
if (typeof window.ga !== "undefined") {
|
if (typeof window.ga !== "undefined") {
|
||||||
appEvents.on("page:changed", data => {
|
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
|
// And Google Tag Manager too
|
||||||
if (typeof window.dataLayer !== "undefined") {
|
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) {
|
if (_started) {
|
||||||
return;
|
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");
|
router.send("refreshTitle");
|
||||||
const url = Discourse.getURL(router.get("url"));
|
const url = Discourse.getURL(router.get("url"));
|
||||||
|
|
||||||
@ -23,10 +28,12 @@ export function startPageTracking(router, appEvents) {
|
|||||||
// next runloop to have the correct title.
|
// next runloop to have the correct title.
|
||||||
Ember.run.next(() => {
|
Ember.run.next(() => {
|
||||||
let title = Discourse.get("_docTitle");
|
let title = Discourse.get("_docTitle");
|
||||||
|
|
||||||
appEvents.trigger("page:changed", {
|
appEvents.trigger("page:changed", {
|
||||||
url,
|
url,
|
||||||
title,
|
title,
|
||||||
currentRouteName: router.get("currentRouteName")
|
currentRouteName: router.get("currentRouteName"),
|
||||||
|
replacedOnlyQueryParams
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user