yandex和google更新
This commit is contained in:
@@ -250,7 +250,11 @@ SMOKE_PUBLIC_ONLY=1 PREVIEW_URL=http://127.0.0.1:21021 npm run smoke:api
|
||||
- `tests/routing.test.mjs`:路径解析、搜索关键词编码、hash 地址不转换与原生页面导航测试。
|
||||
- `src/lib/client/startup.ts` 与 `tests/startup.test.mjs`:年龄确认、广告队列和会话进度,以及控制器与浏览器事件适配测试。
|
||||
|
||||
## 访问统计
|
||||
|
||||
生产环境(`APP_ENV=production`)在全部页面加载 Google Analytics 4(`G-7ZYCTGDJ4F`)和 Yandex.Metrika(`113827715`,含 webvisor、clickmap 及 noscript 像素),代码在 `src/components/site/SiteAnalytics.tsx`,由根布局引入;开发、测试环境不加载,避免污染统计数据。页面均为原生整页跳转,每次加载各自初始化,无需额外发送路由 hit。
|
||||
|
||||
## 已删除的功能
|
||||
|
||||
已移除 Web SDK 埋点(含 `X-SDK-Common`、`X-Tracker-*` 请求头透传)、意见反馈/在线客服、充值与 VIP、个人中心(收藏/历史/点赞/已购/设置)、登录注册以及付费章节解锁。对应页面返回 404,代理白名单不再放行 `auth/login`、`auth/register`、`auth/resetPassword`、`auth/profile`、`coin/*`、`vip/*`、`recharge/*`、`playlet/chapter/unlock`、个人列表和 `upload/image`。
|
||||
已移除原有的 Web SDK 埋点(含 `X-SDK-Common`、`X-Tracker-*` 请求头透传)、意见反馈/在线客服、充值与 VIP、个人中心(收藏/历史/点赞/已购/设置)、登录注册以及付费章节解锁。对应页面返回 404,代理白名单不再放行 `auth/login`、`auth/register`、`auth/resetPassword`、`auth/profile`、`coin/*`、`vip/*`、`recharge/*`、`playlet/chapter/unlock`、个人列表和 `upload/image`。
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
import "./.next/types/routes.d.ts";
|
||||
import "./.next/types/root-params.d.ts";
|
||||
import "./.next-dev/dev/types/routes.d.ts";
|
||||
import "./.next-dev/dev/types/root-params.d.ts";
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
||||
|
||||
+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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -438,7 +438,7 @@ test('SSR emits configured TDK, site_name, canonical and bounded pagination link
|
||||
assert.match(head,/<meta name="twitter:card" content="summary_large_image"/);
|
||||
assert.equal(calls.slice(start).filter(call=>call.path==='/api/app/playlet/home').length,1,'SSR and metadata share one homepage request');
|
||||
assert.equal(calls.slice(start).filter(call=>call.path==='/api/app/config/info').length,1,'SSR and metadata share one configuration request');
|
||||
assert.ok(!/googletagmanager|google-analytics|mc\.yandex/.test(head));
|
||||
if(testEnvironment==='production'){const html=home;assert.ok(html.includes('googletagmanager.com/gtag/js?id=G-7ZYCTGDJ4F'));assert.ok(html.includes('metrika/tag.js?id=113827715'));assert.ok(html.includes('mc.yandex.ru/watch/113827715'));}
|
||||
for(const agent of ['Mozilla/5.0 Chrome/130','Googlebot','facebookexternalhit']){
|
||||
for(const [path,page] of [['/shorts/',1],['/shorts/page/2/',2],['/shorts/page/3/',3]]){
|
||||
const response=await fetch(base+path+'?channel=campaign',{redirect:'manual',headers:{'User-Agent':agent}});
|
||||
|
||||
Reference in New Issue
Block a user