b207bfa7af
test: 添加单元测试和端到端测试 refactor: 重构登录页面和上传模块 ci: 更新测试覆盖率阈值至42% build: 添加测试相关依赖 docs: 更新测试文档 style: 修复代码格式问题
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
export const GA_MEASUREMENT_ID = process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID || '';
|
|
|
|
declare global {
|
|
interface Window {
|
|
gtag: (command: string, targetId: string, config?: Record<string, unknown>) => void;
|
|
}
|
|
}
|
|
|
|
export const pageview = (url: string) => {
|
|
if (typeof window !== 'undefined' && window.gtag && GA_MEASUREMENT_ID) {
|
|
window.gtag('config', GA_MEASUREMENT_ID, {
|
|
page_path: url,
|
|
});
|
|
}
|
|
};
|
|
|
|
export const event = (action: string, category: string, label?: string, value?: number) => {
|
|
if (typeof window !== 'undefined' && window.gtag && GA_MEASUREMENT_ID) {
|
|
window.gtag('event', action, {
|
|
event_category: category,
|
|
event_label: label,
|
|
value: value,
|
|
});
|
|
}
|
|
};
|
|
|
|
export const trackContactForm = (_formData: Record<string, string>) => {
|
|
event('submit', 'contact_form', 'contact_form_submission');
|
|
};
|
|
|
|
export const trackButtonClick = (buttonName: string, location: string) => {
|
|
event('click', 'button', `${location}_${buttonName}`);
|
|
};
|
|
|
|
export const trackPageView = (pageTitle: string, _pagePath: string) => {
|
|
event('page_view', 'navigation', pageTitle);
|
|
};
|