Skip to content

Commit e534dd2

Browse files
committed
feat: add ga tag
1 parent f094328 commit e534dd2

File tree

5 files changed

+49
-12
lines changed

5 files changed

+49
-12
lines changed

src/components/ga/GA.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import Script from "next/script";
2+
3+
const GoogleAnalytics = ({ gaId }: { gaId: string }) => {
4+
return (
5+
<>
6+
<Script
7+
async
8+
src={`https://www.googletagmanager.com/gtag/js?
9+
id=${gaId}`}
10+
></Script>
11+
<Script
12+
id="google-analytics"
13+
dangerouslySetInnerHTML={{
14+
__html: `
15+
window.dataLayer = window.dataLayer || [];
16+
function gtag(){dataLayer.push(arguments);}
17+
gtag('js', new Date());
18+
19+
gtag('config', '${gaId}');
20+
`,
21+
}}
22+
></Script>
23+
</>
24+
);
25+
};
26+
export default GoogleAnalytics;

src/components/ga/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './GA';

src/pages/_app.tsx

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import "react-photo-view/dist/react-photo-view.css";
12
import "../globals.css";
2-
import 'react-photo-view/dist/react-photo-view.css';
33

4-
import { Analytics } from '@vercel/analytics/react';
4+
import { Analytics } from "@vercel/analytics/react";
55
import { PhotoProvider } from "react-photo-view";
6+
import GoogleAnalytics from "@/components/ga";
67

78
export default function MyApp({ Component, pageProps }: any) {
89
return (
9-
<PhotoProvider>
10-
<Component {...pageProps} />
11-
<Analytics />
12-
</PhotoProvider>
10+
<>
11+
<GoogleAnalytics gaId={"G-PZZ787TZQ5"} />
12+
<PhotoProvider>
13+
<Component {...pageProps} />
14+
<Analytics />
15+
</PhotoProvider>
16+
</>
1317
);
1418
}

src/pages/_document.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Html, Head, Main, NextScript } from "next/document";
1+
import { Head, Html, Main, NextScript } from "next/document";
22

33
export default function Document() {
44
const meta = {
@@ -12,10 +12,16 @@ export default function Document() {
1212
<meta name="robots" content="follow,index" />
1313
<meta name="description" content={meta.description} />
1414
<meta property="og:site_name" content={meta.title} />
15-
<meta property="og:image" content="https://blogs.sonht.io.vn/large-preview.png" />
15+
<meta
16+
property="og:image"
17+
content="https://blogs.sonht.io.vn/large-preview.png"
18+
/>
1619
<meta name="twitter:card" content="summary_large_image" />
1720
<meta name="twitter:site" content="@sonht1109" />
18-
<meta name="twitter:image" content="https://blogs.sonht.io.vn/large-preview.png" />
21+
<meta
22+
name="twitter:image"
23+
content="https://blogs.sonht.io.vn/large-preview.png"
24+
/>
1925

2026
<link rel="icon" href="/favicon.png" type="image/png" sizes="32x32" />
2127
</Head>

theme.config.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ const config = {
2020
viewBox="0 0 24 24"
2121
fill="none"
2222
stroke="currentColor"
23-
stroke-width="2"
24-
stroke-linecap="round"
25-
stroke-linejoin="round"
23+
strokeWidth="2"
24+
strokeLinecap="round"
25+
strokeLinejoin="round"
2626
class="icon icon-tabler icons-tabler-outline icon-tabler-world"
2727
>
2828
<path stroke="none" d="M0 0h24v24H0z" fill="none" />

0 commit comments

Comments
 (0)