Skip to content

Commit 2b10b01

Browse files
committed
Remove leftover code
tentative fix on docs utm persistence
1 parent f0ecc9f commit 2b10b01

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

content/300-accelerate/index.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pagination_next: 'accelerate/getting-started'
1010

1111
import {
1212
Bolt,
13-
BorderBox,
1413
BoxTitle,
1514
Database,
1615
Grid,

content/700-optimize/index.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pagination_next: 'optimize/getting-started'
1010

1111
import {
1212
Bolt,
13-
BorderBox,
1413
BoxTitle,
1514
Database,
1615
Grid,

src/hooks/useUTMParams.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useEffect, useState } from 'react';
2+
3+
export const useUTMParams = (): string => {
4+
const [utmParams, setUTMParams] = useState('');
5+
6+
useEffect(() => {
7+
// Check if we're on the client side
8+
if (typeof window !== 'undefined') {
9+
const storedParams = sessionStorage.getItem('utm_params');
10+
setUTMParams(storedParams || '');
11+
}
12+
}, []);
13+
14+
return utmParams;
15+
};

src/theme/NavbarItem/NavbarNavLink.tsx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {isRegexpStringMatch} from '@docusaurus/theme-common';
66
import IconExternalLink from '@theme/Icon/ExternalLink';
77
import type {Props} from '@theme/NavbarItem/NavbarNavLink';
88
import { Icon } from '@site/src/components/Icon';
9+
import { useUTMParams } from '@site/src/hooks/useUTMParams';
910

1011

1112
type CustomProps = Props & {
@@ -31,6 +32,28 @@ export default function NavbarNavLink({
3132
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
3233
const isExternalLink = label && href && !isInternalUrl(href);
3334

35+
// Get UTM parameters from sessionStorage using custom hook
36+
const utmParams = useUTMParams();
37+
38+
// Helper function to append UTM params to URL
39+
const appendUtmParams = (url: string): string => {
40+
if (!utmParams) {
41+
console.log('NavbarNavLink: No UTM params for URL:', url);
42+
return url;
43+
}
44+
45+
const [baseUrl, existingQuery] = url.split('?');
46+
if (existingQuery) {
47+
const result = `${baseUrl}?${existingQuery}&${utmParams}`;
48+
console.log('NavbarNavLink: Adding UTM params to existing query:', url, '->', result);
49+
return result;
50+
} else {
51+
const result = `${baseUrl}?${utmParams}`;
52+
console.log('NavbarNavLink: Adding UTM params to URL:', url, '->', result);
53+
return result;
54+
}
55+
};
56+
3457
// Link content is set through html XOR label
3558
const linkContentProps = html
3659
? {dangerouslySetInnerHTML: {__html: html}}
@@ -54,18 +77,35 @@ export default function NavbarNavLink({
5477
};
5578

5679
if (href) {
80+
// For external links, return as-is
81+
if (isExternalLink) {
82+
return (
83+
<Link
84+
href={prependBaseUrlToHref ? normalizedHref : href}
85+
{...props}
86+
{...linkContentProps}
87+
/>
88+
);
89+
}
90+
91+
// For internal links, append UTM parameters if available
92+
const finalHref = prependBaseUrlToHref ? normalizedHref : href;
93+
const urlWithUtms = appendUtmParams(finalHref);
94+
5795
return (
5896
<Link
59-
href={prependBaseUrlToHref ? normalizedHref : href}
97+
href={urlWithUtms}
6098
{...props}
6199
{...linkContentProps}
62100
/>
63101
);
64102
}
65103

104+
const urlWithUtms = appendUtmParams(toUrl);
105+
66106
return (
67107
<Link
68-
to={toUrl}
108+
to={urlWithUtms}
69109
isNavLink
70110
{...((activeBasePath || activeBaseRegex) && {
71111
isActive: (_match, location) =>

0 commit comments

Comments
 (0)