PageSourceSearch

https://site.fr/_static/ad2521ddc1b5acb4/scripts/matomo-pageview-owner.js

js site.fr collected 2026-10-02 04:05:41 UTC 1,637 bytes, 45 lines download raw bytes

1// GTM keeps loading/configuring Matomo. frontend-new owns pageviews because GTM's
2// automatic calls can happen before rendering, omit Back, or use stale page data.
3// Install through Matomo's lifecycle hook before its initial _paq is processed.
4const initializedWindows = new WeakSet();
5const initializedMatomo = new WeakSet();
6const protectedTrackers = new WeakSet();
7const activePageviews = new WeakSet();
8
9const protectTracker = (tracker) => {
10  if (!tracker || protectedTrackers.has(tracker) || typeof tracker.trackPageView !== 'function') return;
11  const original = tracker.trackPageView;
12  tracker.trackPageView = function (...args) {
13    if (activePageviews.has(this)) return original.apply(this, args);
14  };
15  protectedTrackers.add(tracker);
16};
17
18const initMatomoPageviewOwnership = (windowRef = globalThis.window) => {
19  if (!windowRef || initializedWindows.has(windowRef)) return;
20  const initialize = () => {
21    const matomo = windowRef.Matomo;
22    if (!matomo?.on || initializedMatomo.has(matomo)) return;
23    matomo.on('TrackerSetup', protectTracker);
24    matomo.getAsyncTrackers?.().forEach(protectTracker);
25    initializedMatomo.add(matomo);
26  };
27  if (windowRef.Matomo) initialize();
28  else {
29    const callbacks = windowRef.matomoPluginAsyncInit || [];
30    callbacks.push(initialize);
31    windowRef.matomoPluginAsyncInit = callbacks;
32  }
33  initializedWindows.add(windowRef);
34};
35
36const trackMatomoPageView = (tracker) => {
37  activePageviews.add(tracker);
38  try {
39    return tracker.trackPageView();
40  } finally {
41    activePageviews.delete(tracker);
42  }
43};
44
45export { initMatomoPageviewOwnership, trackMatomoPageView };

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.