yandex和google更新
This commit is contained in:
+2
-1
@@ -1,5 +1,6 @@
|
||||
import type { Metadata, Viewport } from "next";
|
||||
import "./globals.css";
|
||||
import { SiteAnalytics } from "@/components/site/SiteAnalytics";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "黄果吃瓜 · 百万大神原创短剧",
|
||||
@@ -17,7 +18,7 @@ export const viewport: Viewport = {
|
||||
export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
|
||||
return (
|
||||
<html lang="zh-CN" suppressHydrationWarning>
|
||||
<body>{children}</body>
|
||||
<body>{children}<SiteAnalytics /></body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import Script from "next/script";
|
||||
|
||||
/** Google Analytics 4 */
|
||||
const GA_ID = "G-7ZYCTGDJ4F";
|
||||
/** Yandex.Metrika counter */
|
||||
const YM_ID = 113827715;
|
||||
|
||||
/**
|
||||
* Site statistics: GA4 + Yandex.Metrika, production only so development and test traffic is not counted.
|
||||
* Every page is a native document request, so each load runs init once; no client route hits are needed.
|
||||
*/
|
||||
export function SiteAnalytics() {
|
||||
if (process.env.APP_ENV !== "production") return null;
|
||||
return (
|
||||
<>
|
||||
<Script src={`https://www.googletagmanager.com/gtag/js?id=${GA_ID}`} strategy="afterInteractive" />
|
||||
<Script id="ga4" strategy="afterInteractive">
|
||||
{`window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', '${GA_ID}');`}
|
||||
</Script>
|
||||
<Script id="yandex-metrika" strategy="afterInteractive">
|
||||
{`(function(m,e,t,r,i,k,a){
|
||||
m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
|
||||
m[i].l=1*new Date();
|
||||
for (var j = 0; j < document.scripts.length; j++) {if (document.scripts[j].src === r) { return; }}
|
||||
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)
|
||||
})(window, document,'script','https://mc.yandex.ru/metrika/tag.js?id=${YM_ID}', 'ym');
|
||||
ym(${YM_ID}, 'init', {ssr:true, webvisor:true, clickmap:true, ecommerce:"dataLayer", referrer: document.referrer, url: location.href, accurateTrackBounce:true, trackLinks:true});`}
|
||||
</Script>
|
||||
<noscript>
|
||||
<div>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={`https://mc.yandex.ru/watch/${YM_ID}`} style={{ position: "absolute", left: "-9999px" }} alt="" />
|
||||
</div>
|
||||
</noscript>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user