Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/components/analytics/La51Analytics.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
interface Props {
analyticsId: string;
sdkUrl?: string;
ck?: string;
autoTrack?: boolean;
hashMode?: boolean;
screenRecord?: boolean;
}

const {
analyticsId,
sdkUrl,
ck,
autoTrack = true,
hashMode = false,
screenRecord = true,
} = Astro.props;
---

<script is:inline data-swup-ignore-script define:vars={{ analyticsId, sdkUrl, ck, autoTrack, hashMode, screenRecord }}>
!(function (p) {
"use strict";
!(function (t) {
var s = window,
e = document,
i = p,
c = sdkUrl || "".concat(
"https:" === e.location.protocol ? "https://" : "http://",
"sdk.51.la/js-sdk-pro.min.js"
),
n = e.createElement("script"),
r = e.getElementsByTagName("script")[0];
(n.type = "text/javascript"),
n.setAttribute("charset", "UTF-8"),
(n.async = !0),
(n.src = c),
(n.id = "LA_COLLECT"),
(i.d = n);
var o = function () {
s.LA.ids.push(i);
};
s.LA
? s.LA.ids && o()
: ((s.LA = p), (s.LA.ids = []), o()),
r.parentNode.insertBefore(n, r);
})();
})({ id: analyticsId, ck: ck || analyticsId, autoTrack: autoTrack, hashMode: hashMode, screenRecord: screenRecord });
</script>
10 changes: 10 additions & 0 deletions src/config/siteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ export const siteConfig: SiteConfig = {
googleAnalyticsId: "",
// Microsoft Clarity ID
microsoftClarityId: "",
// 51la 统计 ID
la51AnalyticsId: "",
// 51la 配置
la51Config: {
// sdkUrl: "", // 自定义 SDK JS 地址,防止 DNS 污染,留空使用默认地址
// ck: "", // 多个统计 ID 的数据分离标识,留空则使用 la51AnalyticsId
autoTrack: false, // 开启事件分析功能
hashMode: false, // Hash路由模式, 项目使用History API路由, 所以不必开启默认false
screenRecord: true, // 开启网站录屏功能
},
},

// 图像优化及响应式配置
Expand Down
11 changes: 11 additions & 0 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import GoogleAnalytics from "@components/analytics/GoogleAnalytics.astro";
import La51Analytics from "@components/analytics/La51Analytics.astro";
import MicrosoftClarity from "@components/analytics/MicrosoftClarity.astro";
import FancyboxManager from "@components/features/FancyboxManager.astro";
import FontManager from "@components/features/FontManager.astro";
Expand Down Expand Up @@ -102,6 +103,16 @@ const siteLang = lang.replace("_", "-");
{siteConfig.analytics?.microsoftClarityId && (
<MicrosoftClarity clarityId={siteConfig.analytics.microsoftClarityId} />
)}
{siteConfig.analytics?.la51AnalyticsId && (
<La51Analytics
analyticsId={siteConfig.analytics.la51AnalyticsId}
sdkUrl={siteConfig.analytics.la51Config?.sdkUrl}
ck={siteConfig.analytics.la51Config?.ck}
autoTrack={siteConfig.analytics.la51Config?.autoTrack}
hashMode={siteConfig.analytics.la51Config?.hashMode}
screenRecord={siteConfig.analytics.la51Config?.screenRecord}
/>
)}

<title>{pageTitle}</title>
<meta
Expand Down
8 changes: 8 additions & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ export type SiteConfig = {
analytics?: {
googleAnalyticsId?: string; // Google Analytics ID
microsoftClarityId?: string; // Microsoft Clarity ID
la51AnalyticsId?: string; // 51la 统计 ID
la51Config?: {
sdkUrl?: string; // 自定义 SDK 地址,防止 DNS 污染,默认为 "//sdk.51.la/js-sdk-pro.min.js"
ck?: string; // 多个统计 ID 的数据分离标识,默认与 id 相同
autoTrack?: boolean; // 开启事件分析功能,默认 true
hashMode?: boolean; // 单页面应用统计(Vue/React 等),默认 false
screenRecord?: boolean; // 开启网站录屏功能,默认 true
};
};

// 图片优化配置
Expand Down
Loading