Skip to content

Commit 0d96979

Browse files
Merge pull request #70 from newfish-cmyk/add-baidu
feat: add baidu conversion tracking
2 parents b5b23d0 + bfa76ce commit 0d96979

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

projects/fastgpt/app/BdVidHandler.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use client';
2+
3+
export default function BdVidHandler() {
4+
if (typeof window !== 'undefined') {
5+
const urlParams = new URLSearchParams(window.location.search);
6+
const bd_vid = urlParams.get('bd_vid');
7+
if (bd_vid) {
8+
localStorage.setItem('bd_vid', bd_vid);
9+
}
10+
}
11+
return null;
12+
}

projects/fastgpt/app/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Analytics } from '@vercel/analytics/react';
1212
import { Viewport } from 'next';
1313
import { Inter as FontSans } from 'next/font/google';
1414
import Script from 'next/script';
15+
import BdVidHandler from './BdVidHandler';
1516

1617
const fontSans = FontSans({
1718
subsets: ['latin'],
@@ -83,6 +84,7 @@ export default async function RootLayout({
8384
</ThemeProvider>
8485
<GoogleAnalytics />
8586
<BaiDuAnalytics />
87+
<BdVidHandler />
8688
</body>
8789
</html>
8890
);

projects/fastgpt/components/home/CTAButton.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { useEffect, useState } from 'react';
88

99
const CTAButton = ({ locale, stars: initialStars, showGithub = true }: { locale: any; stars: number, showGithub?: boolean }) => {
1010
const [stars, setStars] = useState(initialStars);
11+
const [bd_vid, setBdVid] = useState<string | null>(null);
12+
13+
useEffect(() => {
14+
setBdVid(typeof window !== 'undefined' ? localStorage.getItem('bd_vid') : null);
15+
}, []);
1116

1217
useEffect(() => {
1318
const getStars = async () => {
@@ -42,7 +47,7 @@ const CTAButton = ({ locale, stars: initialStars, showGithub = true }: { locale:
4247
</Button>
4348
</Link>)
4449
}
45-
<Link href={siteConfig.userUrl} rel="noopener noreferrer nofollow">
50+
<Link href={`${siteConfig.userUrl}?bd_vid=${bd_vid}`} rel="noopener noreferrer nofollow">
4651
<Button
4752
variant="default"
4853
className="flex items-center gap-3 bg-[#B9DFFF] hover:bg-[#91C2EB] text-[#3941DD] px-6 py-4 text-sm"

0 commit comments

Comments
 (0)