add google gats

This commit is contained in:
oiov
2024-07-30 18:55:57 +08:00
parent 265b0aa460
commit 1151766da6
8 changed files with 70 additions and 22 deletions

View File

@@ -35,4 +35,6 @@ NEXT_PUBLIC_FREE_RECORD_QUOTA=3
NEXT_PUBLIC_FREE_URL_QUOTA=100
# Open Signup
NEXT_PUBLIC_OPEN_SIGNUP=1
NEXT_PUBLIC_OPEN_SIGNUP=1
NEXT_PUBLIC_GOOGLE_ID=

37
app/GoogleAnalytics.tsx Normal file
View File

@@ -0,0 +1,37 @@
"use client";
import Script from "next/script";
import * as gtag from "../gtag.js";
const GoogleAnalytics = () => {
return (
<>
{gtag.GA_TRACKING_ID ? (
<>
<Script
strategy="afterInteractive"
src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
/>
<Script
id="gtag-init"
strategy="afterInteractive"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gtag.GA_TRACKING_ID}', {
page_path: window.location.pathname,
});
`,
}}
/>
</>
) : (
<></>
)}
</>
);
};
export default GoogleAnalytics;

View File

@@ -10,6 +10,8 @@ import { Toaster } from "@/components/ui/sonner";
import ModalProvider from "@/components/modals/providers";
import { TailwindIndicator } from "@/components/tailwind-indicator";
import GoogleAnalytics from "./GoogleAnalytics";
interface RootLayoutProps {
children: React.ReactNode;
}
@@ -48,6 +50,7 @@ export default function RootLayout({ children }: RootLayoutProps) {
<TailwindIndicator />
</ThemeProvider>
</SessionProvider>
<GoogleAnalytics />
</body>
</html>
</ViewTransitions>

View File

@@ -109,16 +109,6 @@ export function NavMobile() {
Sign in
</Link>
</li>
<li className="py-3">
<Link
href="/register"
onClick={() => setOpen(false)}
className="flex w-full font-medium capitalize"
>
Sign up
</Link>
</li>
</>
)}
</ul>

View File

@@ -45,6 +45,7 @@ export default async function HeroLanding() {
variant: "outline",
rounded: "xl",
size: "lg",
className: "bg-primary-foreground hover:opacity-70",
}),
"px-4 text-[15px]",
)}

View File

@@ -26,16 +26,16 @@ export const docsConfig: DocsConfig = {
href: "/docs/short-urls",
icon: "page",
},
{
title: "Terms of Service",
href: "/terms",
icon: "page",
},
{
title: "Privacy Policy",
href: "/privacy",
icon: "page",
},
// {
// title: "Terms of Service",
// href: "/terms",
// icon: "page",
// },
// {
// title: "Privacy Policy",
// href: "/privacy",
// icon: "page",
// },
// {
// title: "Newsletter",
// href: "/docs/newsletter",

View File

@@ -28,7 +28,7 @@ See docs about [guide](/docs/quick-start) for quick start.
- [Cloudflare](https://dash.cloudflare.com/) account
- A **domain** name hosted on Cloudflare
See docs about [developer](/docs/installation).
See docs about [developer](/docs/developer/installation).
## Local development

15
gtag.js Normal file
View File

@@ -0,0 +1,15 @@
export const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GOOGLE_ID || null;
export const pageview = (url) => {
window.gtag("config", GA_TRACKING_ID, {
page_path: url,
});
};
export const event = ({ action, category, label, value }) => {
window.gtag("event", action, {
event_category: category,
event_label: label,
value: value,
});
};