fix(analytics): 更新Google Analytics配置和变量命名
更新环境变量命名以匹配GA4标准,并调整默认存储权限配置 添加页面浏览跟踪逻辑,当用户同意分析时发送页面数据
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
NEXT_PUBLIC_GA_ID=G-XXXXXXXXXX
|
NEXT_PUBLIC_GA_MEASUREMENT_ID=G-XXXXXXXXXX
|
||||||
|
|||||||
@@ -38,17 +38,19 @@ function GoogleAnalyticsContent() {
|
|||||||
function gtag(){dataLayer.push(arguments);}
|
function gtag(){dataLayer.push(arguments);}
|
||||||
gtag('js', new Date());
|
gtag('js', new Date());
|
||||||
|
|
||||||
// 默认禁用存储,等待用户同意
|
|
||||||
gtag('consent', 'default', {
|
gtag('consent', 'default', {
|
||||||
'analytics_storage': 'denied',
|
'analytics_storage': 'granted',
|
||||||
'ad_storage': 'denied',
|
'ad_storage': 'denied',
|
||||||
|
'functionality_storage': 'granted',
|
||||||
|
'personalization_storage': 'denied',
|
||||||
|
'security_storage': 'granted',
|
||||||
'wait_for_update': 500
|
'wait_for_update': 500
|
||||||
});
|
});
|
||||||
|
|
||||||
gtag('config', '${GA_MEASUREMENT_ID}', {
|
gtag('config', '${GA_MEASUREMENT_ID}', {
|
||||||
send_page_view: false,
|
send_page_view: false,
|
||||||
anonymize_ip: true,
|
anonymize_ip: true,
|
||||||
allow_google_signals: false,
|
allow_google_signals: true,
|
||||||
allow_ad_personalization_signals: false,
|
allow_ad_personalization_signals: false,
|
||||||
cookie_flags: 'SameSite=None;Secure'
|
cookie_flags: 'SameSite=None;Secure'
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -174,6 +174,14 @@ export const updateConsentDetailed = (preferences: CookiePreferences) => {
|
|||||||
personalization_storage: preferences.marketing ? 'granted' : 'denied',
|
personalization_storage: preferences.marketing ? 'granted' : 'denied',
|
||||||
security_storage: 'granted',
|
security_storage: 'granted',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (preferences.analytics) {
|
||||||
|
window.gtag('config', GA_MEASUREMENT_ID, {
|
||||||
|
page_path: window.location.pathname + window.location.search,
|
||||||
|
page_title: document.title,
|
||||||
|
page_location: window.location.href,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user