فهرست منبع

seperate gtag script

AykutSarac 3 سال پیش
والد
کامیت
6d7bd390b4
4فایلهای تغییر یافته به همراه34 افزوده شده و 4 حذف شده
  1. 0 0
      public/sw.js.map
  2. 30 0
      src/components/GoogleAnalytics/index.tsx
  3. 2 0
      src/pages/_app.tsx
  4. 2 4
      src/pages/_document.tsx

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
public/sw.js.map


+ 30 - 0
src/components/GoogleAnalytics/index.tsx

@@ -0,0 +1,30 @@
+import Script from "next/script";
+import React from "react";
+
+const isDevelopment = process.env.NODE_ENV === "development";
+
+export const GoogleAnalytics = () => {
+  if (isDevelopment) return null;
+
+  return (
+    <>
+      <Script
+        strategy="afterInteractive"
+        src={`https://www.googletagmanager.com/gtag/js?id=G-JKZEHMJBMH`}
+      />
+      <Script
+        strategy="afterInteractive"
+        dangerouslySetInnerHTML={{
+          __html: `
+            window.dataLayer = window.dataLayer || [];
+            function gtag(){dataLayer.push(arguments);}
+            gtag('js', new Date());
+            gtag('config', 'G-JKZEHMJBMH', {
+                page_path: window.location.pathname,
+            });
+        `,
+        }}
+      />
+    </>
+  );
+};

+ 2 - 0
src/pages/_app.tsx

@@ -6,6 +6,7 @@ import GlobalStyle from "src/constants/globalStyle";
 import { darkTheme, lightTheme } from "src/constants/theme";
 import { darkTheme, lightTheme } from "src/constants/theme";
 import { Toaster } from "react-hot-toast";
 import { Toaster } from "react-hot-toast";
 import { useConfig, withConfig } from "src/hocs/config";
 import { useConfig, withConfig } from "src/hocs/config";
+import { GoogleAnalytics } from "src/components/GoogleAnalytics";
 
 
 function JsonVisio({ Component, pageProps }: AppProps) {
 function JsonVisio({ Component, pageProps }: AppProps) {
   const {
   const {
@@ -14,6 +15,7 @@ function JsonVisio({ Component, pageProps }: AppProps) {
 
 
   return (
   return (
     <>
     <>
+      <GoogleAnalytics />
       <ThemeProvider theme={settings.lightmode ? lightTheme : darkTheme}>
       <ThemeProvider theme={settings.lightmode ? lightTheme : darkTheme}>
         <GlobalStyle />
         <GlobalStyle />
         <Component {...pageProps} />
         <Component {...pageProps} />

+ 2 - 4
src/pages/_document.tsx

@@ -9,8 +9,6 @@ import Document, {
 import { SeoTags } from "src/components/SeoTags";
 import { SeoTags } from "src/components/SeoTags";
 import { ServerStyleSheet } from "styled-components";
 import { ServerStyleSheet } from "styled-components";
 
 
-const isDevelopment = process.env.NODE_ENV === "development";
-
 class MyDocument extends Document {
 class MyDocument extends Document {
   static async getInitialProps(
   static async getInitialProps(
     ctx: DocumentContext
     ctx: DocumentContext
@@ -39,13 +37,13 @@ class MyDocument extends Document {
     return (
     return (
       <Html lang="en">
       <Html lang="en">
         <Head>
         <Head>
-          <link rel="manifest" href="/manifest.json" />
-          <meta name="theme-color" content="#36393E" />
           <SeoTags
           <SeoTags
             description="Simple visualization tool for your JSON data. No forced structure, paste your JSON and view it instantly."
             description="Simple visualization tool for your JSON data. No forced structure, paste your JSON and view it instantly."
             title="JSON Visio - Directly onto graphs"
             title="JSON Visio - Directly onto graphs"
             image="https://jsonvisio.com/jsonvisio.png"
             image="https://jsonvisio.com/jsonvisio.png"
           />
           />
+          <meta name="theme-color" content="#36393E" />
+          <link rel="manifest" href="/manifest.json" />
           <link rel="icon" href="/favicon.ico" />
           <link rel="icon" href="/favicon.ico" />
           <link rel="preconnect" href="https://fonts.googleapis.com" />
           <link rel="preconnect" href="https://fonts.googleapis.com" />
           <link
           <link

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است