diff --git a/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 b/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 index 06653ce1752..f11760ec6c5 100644 --- a/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 +++ b/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 @@ -1,6 +1,7 @@ import { cleanDOM } from "discourse/lib/clean-dom"; import { startPageTracking, + resetPageTracking, googleTagManagerPageChanged } from "discourse/lib/page-tracker"; import { viewTrackingRequired } from "discourse/lib/ajax"; @@ -49,5 +50,9 @@ export default { } }); } + }, + + teardown() { + resetPageTracking(); } }; diff --git a/app/assets/javascripts/discourse/lib/page-tracker.js.es6 b/app/assets/javascripts/discourse/lib/page-tracker.js.es6 index 0c9e9445c98..e6390e08ea4 100644 --- a/app/assets/javascripts/discourse/lib/page-tracker.js.es6 +++ b/app/assets/javascripts/discourse/lib/page-tracker.js.es6 @@ -1,6 +1,5 @@ let _started = false; - -const cache = {}; +let cache = {}; let transitionCount = 0; export function setTransient(key, data, count) { @@ -11,6 +10,12 @@ export function getTransient(key) { return cache[key]; } +export function resetPageTracking() { + _started = false; + transitionCount = 0; + cache = {}; +} + export function startPageTracking(router, appEvents) { if (_started) { return;