change owner

This commit is contained in:
afred 2024-12-11 12:32:38 +08:00
parent 00e54bf351
commit 7680ae40b4
2 changed files with 42 additions and 25 deletions

View File

@ -0,0 +1,34 @@
"use client";
import { useEffect } from "react";
export default function HotjarLoader() {
useEffect(() => {
// Hotjar Tracking Code
(function (h, o, t, j, a, r) {
h.hj =
h.hj ||
function () {
(h.hj.q = h.hj.q || []).push(arguments);
};
h._hjSettings = { hjid: 3414362, hjsv: 6 };
// 获取 <head> 元素
a = o.getElementsByTagName("head")[0];
if (!a) {
console.error("Head element not found in the document.");
return;
}
// 创建 <script> 元素
r = o.createElement("script");
r.async = 1;
r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
// 将 <script> 插入 <head>
a.appendChild(r);
})(window, document, "https://static.hotjar.com/c/hotjar-", ".js?sv=");
}, []);
return null; // 不需要渲染任何内容
}

View File

@ -1,37 +1,20 @@
"use client";
import React, { useEffect } from "react";
import { Analytics } from "@vercel/analytics/react";
import { Home } from "./components/home";
import { getServerSideConfig } from "./config/server";
import HotjarLoader from "./components/HotjarLoader"; // 引入 HotjarLoader
const serverConfig = getServerSideConfig();
export default function App() {
// 使用 useEffect 加载 Hotjar 脚本
useEffect(() => {
if (serverConfig?.isVercel) {
(function (h, o, t, j, a, r) {
h.hj =
h.hj ||
function () {
(h.hj.q = h.hj.q || []).push(arguments);
};
h._hjSettings = { hjid: 3414362, hjsv: 6 };
a = o.getElementsByTagName("head")[0];
r = o.createElement("script");
r.async = 1;
r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
a.appendChild(r);
})(window, document, "https://static.hotjar.com/c/hotjar-", ".js?sv=");
}
}, []); // 空依赖数组,确保只在组件加载时运行一次
export default async function App() {
return (
<>
<Home />
{serverConfig?.isVercel && <Analytics />}
{serverConfig?.isVercel && (
<>
<Analytics />
<HotjarLoader /> {/* 加入 HotjarLoader */}
</>
)}
</>
);
}