Skip to content

Commit

Permalink
Merge pull request #70 from newfish-cmyk/add-baidu
Browse files Browse the repository at this point in the history
feat: add baidu conversion tracking
  • Loading branch information
yangchuansheng authored Oct 31, 2024
2 parents b5b23d0 + bfa76ce commit 0d96979
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions projects/fastgpt/app/BdVidHandler.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use client';

export default function BdVidHandler() {
if (typeof window !== 'undefined') {
const urlParams = new URLSearchParams(window.location.search);
const bd_vid = urlParams.get('bd_vid');
if (bd_vid) {
localStorage.setItem('bd_vid', bd_vid);
}
}
return null;
}
2 changes: 2 additions & 0 deletions projects/fastgpt/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Analytics } from '@vercel/analytics/react';
import { Viewport } from 'next';
import { Inter as FontSans } from 'next/font/google';
import Script from 'next/script';
import BdVidHandler from './BdVidHandler';

const fontSans = FontSans({
subsets: ['latin'],
Expand Down Expand Up @@ -83,6 +84,7 @@ export default async function RootLayout({
</ThemeProvider>
<GoogleAnalytics />
<BaiDuAnalytics />
<BdVidHandler />
</body>
</html>
);
Expand Down
7 changes: 6 additions & 1 deletion projects/fastgpt/components/home/CTAButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { useEffect, useState } from 'react';

const CTAButton = ({ locale, stars: initialStars, showGithub = true }: { locale: any; stars: number, showGithub?: boolean }) => {
const [stars, setStars] = useState(initialStars);
const [bd_vid, setBdVid] = useState<string | null>(null);

useEffect(() => {
setBdVid(typeof window !== 'undefined' ? localStorage.getItem('bd_vid') : null);
}, []);

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

0 comments on commit 0d96979

Please sign in to comment.