From 3959a4c0cf4d9935bfe22cd1a68db67b1261ad2d Mon Sep 17 00:00:00 2001 From: katzino Date: Wed, 15 Oct 2025 10:36:22 +0200 Subject: [PATCH 1/2] fix: missing `url` param on page view [internal] --- src/plugins/docusaurus-plugin-segment/segment.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/docusaurus-plugin-segment/segment.js b/src/plugins/docusaurus-plugin-segment/segment.js index 8572c5d9a..5e74f9153 100644 --- a/src/plugins/docusaurus-plugin-segment/segment.js +++ b/src/plugins/docusaurus-plugin-segment/segment.js @@ -29,15 +29,15 @@ function getOneTrustConsentContext() { } export default ExecutionEnvironment.canUseDOM ? { - onRouteUpdate({ location }) { + onRouteUpdate() { // Don't track page views on development if (process.env.NODE_ENV === 'production' && window.analytics) { window.analytics.page({ app: 'docs', page_type: 'DOCS_PAGE', - path: location.pathname, - url: location.href, - search: location.search, + path: window.location.pathname, + url: window.location.href, + search: window.location.search, ...getOneTrustConsentContext(), }); } From 393f217ee80cc785e65cda2d73de3f431312c156 Mon Sep 17 00:00:00 2001 From: katzino Date: Wed, 15 Oct 2025 11:53:57 +0200 Subject: [PATCH 2/2] chore: defer `window.location` --- .../docusaurus-plugin-segment/segment.js | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/plugins/docusaurus-plugin-segment/segment.js b/src/plugins/docusaurus-plugin-segment/segment.js index 5e74f9153..e9e3ac850 100644 --- a/src/plugins/docusaurus-plugin-segment/segment.js +++ b/src/plugins/docusaurus-plugin-segment/segment.js @@ -30,16 +30,19 @@ function getOneTrustConsentContext() { export default ExecutionEnvironment.canUseDOM ? { onRouteUpdate() { - // Don't track page views on development - if (process.env.NODE_ENV === 'production' && window.analytics) { - window.analytics.page({ - app: 'docs', - page_type: 'DOCS_PAGE', - path: window.location.pathname, - url: window.location.href, - search: window.location.search, - ...getOneTrustConsentContext(), - }); - } + // this forces deferred execution that ensures `window.location` is in sync + setTimeout(() => { + // Don't track page views on development + if (process.env.NODE_ENV === 'production' && window.analytics) { + window.analytics.page({ + app: 'docs', + page_type: 'DOCS_PAGE', + path: window.location.pathname, + url: window.location.href, + search: window.location.search, + ...getOneTrustConsentContext(), + }); + } + }, 0); }, } : null;