feat(analytics): enhance Google Analytics with privacy compliance and comprehensive tracking
- Add automatic route change tracking for SPA navigation - Implement Cookie consent banner for GDPR compliance - Add performance tracking (LCP, FID, CLS Web Vitals) - Add outbound link click tracking - Integrate contact form submission tracking with conversion events - Add CTA button click tracking in hero section - Integrate error tracking in ErrorBoundary component - Extend analytics utility library with 15+ tracking functions - Configure IP anonymization and privacy settings - Remove unused test files and deployment scripts - Update case studies to include only specified cases - Fix mobile navigation active state issues - Fix lint errors in test files and components BREAKING CHANGE: Google Analytics now requires user consent before tracking
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useLayoutEffect, useRef } from 'react';
|
||||
import { StaticLink } from '@/components/ui/static-link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { usePathname, useSearchParams } from 'next/navigation';
|
||||
import { Home, Briefcase, Package, FileText, User } from 'lucide-react';
|
||||
import { motion } from 'framer-motion';
|
||||
import { cn } from '@/lib/utils';
|
||||
@@ -11,18 +12,45 @@ const tabs = [
|
||||
{ id: 'services', label: '服务', href: '/#services', icon: Briefcase },
|
||||
{ id: 'products', label: '产品', href: '/#products', icon: Package },
|
||||
{ id: 'news', label: '新闻', href: '/#news', icon: FileText },
|
||||
{ id: 'contact', label: '联系', href: '/#contact', icon: User },
|
||||
{ id: 'contact', label: '联系', href: '/contact', icon: User },
|
||||
];
|
||||
|
||||
export function MobileTabBar() {
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const [hash, setHash] = useState('');
|
||||
const isInitializedRef = useRef(false);
|
||||
|
||||
const isActive = (href: string) => {
|
||||
if (href === '/') {
|
||||
return pathname === '/';
|
||||
useLayoutEffect(() => {
|
||||
if (!isInitializedRef.current) {
|
||||
isInitializedRef.current = true;
|
||||
setHash(window.location.hash.slice(1));
|
||||
}
|
||||
const basePath = href.split('#')[0] || href;
|
||||
return pathname.startsWith(basePath);
|
||||
|
||||
const handleHashChange = () => {
|
||||
setHash(window.location.hash.slice(1));
|
||||
};
|
||||
|
||||
window.addEventListener('hashchange', handleHashChange);
|
||||
return () => window.removeEventListener('hashchange', handleHashChange);
|
||||
}, []);
|
||||
|
||||
const isActive = (_href: string, id: string) => {
|
||||
if (id === 'contact') {
|
||||
return pathname === '/contact';
|
||||
}
|
||||
|
||||
if (pathname === '/') {
|
||||
const section = searchParams.get('section');
|
||||
const currentSection = section || hash;
|
||||
|
||||
if (id === 'home') {
|
||||
return !currentSection || currentSection === 'home';
|
||||
}
|
||||
return currentSection === id;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -30,7 +58,7 @@ export function MobileTabBar() {
|
||||
<div className="flex items-center justify-around h-16">
|
||||
{tabs.map((tab) => {
|
||||
const Icon = tab.icon;
|
||||
const active = isActive(tab.href);
|
||||
const active = isActive(tab.href, tab.id);
|
||||
|
||||
return (
|
||||
<StaticLink
|
||||
|
||||
Reference in New Issue
Block a user