Skip to content

Commit fa5e30c

Browse files
authored
docs: missing url param on page view [internal] (#2017)
1 parent eeb0183 commit fa5e30c

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/plugins/docusaurus-plugin-segment/segment.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,20 @@ function getOneTrustConsentContext() {
2929
}
3030

3131
export default ExecutionEnvironment.canUseDOM ? {
32-
onRouteUpdate({ location }) {
33-
// Don't track page views on development
34-
if (process.env.NODE_ENV === 'production' && window.analytics) {
35-
window.analytics.page({
36-
app: 'docs',
37-
page_type: 'DOCS_PAGE',
38-
path: location.pathname,
39-
url: location.href,
40-
search: location.search,
41-
...getOneTrustConsentContext(),
42-
});
43-
}
32+
onRouteUpdate() {
33+
// this forces deferred execution that ensures `window.location` is in sync
34+
setTimeout(() => {
35+
// Don't track page views on development
36+
if (process.env.NODE_ENV === 'production' && window.analytics) {
37+
window.analytics.page({
38+
app: 'docs',
39+
page_type: 'DOCS_PAGE',
40+
path: window.location.pathname,
41+
url: window.location.href,
42+
search: window.location.search,
43+
...getOneTrustConsentContext(),
44+
});
45+
}
46+
}, 0);
4447
},
4548
} : null;

0 commit comments

Comments
 (0)