From 767fd53206a6c6dab571225cd0d21fe772323296 Mon Sep 17 00:00:00 2001 From: SvenAlHamad Date: Fri, 8 May 2026 16:59:03 +0200 Subject: [PATCH] Migrate from legacy wts client to @webiny/wts-client v3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces the git-URL-pinned `wts` dep with the npm-published @webiny/wts-client@^3 — a TypeScript rewrite that actually proxies through t.webiny.com instead of loading Heap directly. Removes the inline Heap loader and the Banquet tracking script from _document.js. PostHog is now the sole destination via the t.webiny.com proxy; Heap is no longer fanned out to. Removes the broken legacy integration in _app.js — the setTimeout 500ms dance plus `Router.onRouteChangeComplete` (note: that's not a real Next.js Router API; route-change pageviews never fired). Replaces it with a proper React-context provider mounted in _app.js, which auto-tracks page-view events using router.asPath on every route change. GTM and Kapa.ai widget kept as-is. Co-Authored-By: Claude Opus 4.7 (1M context) --- package.json | 4 +- src/components/Telemetry.js | 21 ++++++++++ src/pages/_app.js | 36 ++++------------- src/pages/_document.js | 45 --------------------- yarn.lock | 79 ++++++------------------------------- 5 files changed, 44 insertions(+), 141 deletions(-) create mode 100644 src/components/Telemetry.js diff --git a/package.json b/package.json index 515b9c1d4..9ac2e23c7 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "@webiny/react-composition": "^5.44.0", "@webiny/react-properties": "^5.44.0", "@webiny/utils": "^5.44.0", + "@webiny/wts-client": "^3.0.1", "autoprefixer": "^10.4.0", "babel-plugin-module-resolver": "^4.1.0", "brotli-size": "^4.0.0", @@ -99,8 +100,7 @@ "tinytime": "^0.2.6", "titlecase": "^1.1.3", "walk": "^2.3.15", - "write-json-file": "^4.3.0", - "wts": "https://github.com/webiny/wts#ae82e59470d79dc448a74239bf9d2328f4b93499" + "write-json-file": "^4.3.0" }, "devDependencies": { "@anthropic-ai/sdk": "^0.80.0", diff --git a/src/components/Telemetry.js b/src/components/Telemetry.js new file mode 100644 index 000000000..e4480552d --- /dev/null +++ b/src/components/Telemetry.js @@ -0,0 +1,21 @@ +import { useRouter } from "next/router"; +import { TelemetryProvider, useTrackPageView } from "@webiny/wts-client/react"; + +function PageViewTracker() { + const router = useRouter(); + useTrackPageView(router.asPath); + return null; +} + +/** + * Wraps the app in the WTS telemetry provider and auto-tracks page-view events + * on every route change. Posts to t.webiny.com. + */ +export function Telemetry({ children }) { + return ( + + + {children} + + ); +} diff --git a/src/pages/_app.js b/src/pages/_app.js index 685d4500d..1e557240c 100644 --- a/src/pages/_app.js +++ b/src/pages/_app.js @@ -3,9 +3,9 @@ import Router from "next/router"; import { NavigationProvider } from "@/components/page/Navigation"; import { Page } from "@/components/page/Page"; import { PageProvider } from "@/components/page/PageProvider"; +import { Telemetry } from "@/components/Telemetry"; import ProgressBar from "@badrap/bar-of-progress"; import { ResizeObserver } from "@juggle/resize-observer"; -import { WTS } from "wts/src/web"; import "../css/fonts.css"; import "../css/main.css"; @@ -31,34 +31,14 @@ Router.events.on("routeChangeStart", () => progress.start()); Router.events.on("routeChangeComplete", () => progress.finish()); Router.events.on("routeChangeError", () => progress.finish()); -const isBrowser = typeof window !== "undefined"; - -if (isBrowser) { - // For the first page load - setTimeout(async () => { - if (window.heap) { - window.wts = new WTS(); - window.wts.identify(); - } - }, 500); - - // Subsequent route changes - Router.onRouteChangeComplete = _url => { - // Webiny Telemetry System - // trigger telemetry when changing routes - - if (window.wts) { - window.wts.identify(); - } - }; -} - export default function App({ Component, pageProps }) { return ( - - - - - + + + + + + + ); } diff --git a/src/pages/_document.js b/src/pages/_document.js index feafc2180..66f551a00 100644 --- a/src/pages/_document.js +++ b/src/pages/_document.js @@ -62,45 +62,6 @@ export default class Document extends NextDocument { }} /> - -