PageSourceSearch

https://compliance.tf/js/plausible-init.js

js compliance.tf collected 2026-10-02 14:58:58 UTC 2,115 bytes, 46 lines download raw bytes

1/* Plausible analytics init (bug web-9zd).
2 *
3 * Externalized from <script>...</script> inside layout.tsx so the
4 * site-wide CSP can drop `'unsafe-inline'` from `script-src`.
5 * Same-origin `<script src="/js/plausible-init.js">` is allowed by the
6 * `'self'` keyword already present in the policy.
7 *
8 * No-op in non-production builds because layout.tsx only injects this
9 * script tag when NEXT_PUBLIC_SITE_ENV === "production"; keeping the
10 * file always present in /public/ keeps the build/deploy graph simple.
11 */
12window.plausible =
13  window.plausible ||
14  function () {
15    (window.plausible.q = window.plausible.q || []).push(arguments);
16  };
17plausible.init =
18  plausible.init ||
19  function (i) {
20    plausible.o = i || {};
21  };
22// 404 renders (Next's not-found page) flag themselves with a <meta>. On such
23// a page the automatic pageview is rewritten into the Plausible-native "404"
24// goal: URL collapsed to /404/, real path in a prop, so scanner probes for
25// paths like /forgotPassword or /oauth2/authorize stop filling Top Pages.
26// (Plausible counts a visitor on a page for ANY event there, so suppressing
27// the pageview alone did not hide them.) The match is on the PATH captured at
28// load, not on the meta being in the DOM at event time: on a client-side
29// navigation away from the 404 the tracker fires the next pageview at
30// pushState, before React removes the meta, so a DOM check turned the
31// pageview for / into a second 404 goal (seen live). Disabling
32// autoCapturePageviews instead silenced every pageview for the rest of the
33// session. The goal must exist in the dashboard.
34var notFoundPath = document.querySelector('meta[name="ctf-page"][content="not-found"]')
35  ? location.pathname
36  : null;
37function ctfNotFoundGoal(payload) {
38  if (!notFoundPath || payload.n !== "pageview") return payload;
39  if (new URL(payload.u, location.origin).pathname !== notFoundPath) return payload;
40  return Object.assign({}, payload, {
41    n: "404",
42    u: location.origin + "/404/",
43    p: { path: notFoundPath },
44  });
45}
46plausible.init({ endpoint: "/api/event", transformRequest: ctfNotFoundGoal });

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.