Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add baidu conversion tracking #70

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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