feat(analytics): implement total transparency suite and SEO metadata standardization

- Added global ScrollDepthTracker (25%, 50%, 75%, 100%)
- Implemented ProductEngagementTracker for deep product analytics
- Added field-level tracking to ContactForm and RequestQuoteForm
- Standardized SEO metadata (canonical, alternates, x-default) across all routes
- Created reusable TrackedLink and TrackedButton components for server components
- Fixed 'useAnalytics' hook error in Footer.tsx by adding 'use client'
This commit is contained in:
2026-02-16 18:30:29 +01:00
parent c2e790e533
commit 58d83a7fa1
22 changed files with 634 additions and 98 deletions

View File

@@ -5,11 +5,30 @@ import { useTranslations } from 'next-intl';
import { Button, Heading, Card, Input, Textarea, Label } from '@/components/ui';
import { sendContactFormAction } from '@/app/actions/contact';
import { useAnalytics } from '@/components/analytics/useAnalytics';
import { AnalyticsEvents } from '@/components/analytics/analytics-events';
export default function ContactForm() {
const t = useTranslations('Contact');
const { trackEvent } = useAnalytics();
const [status, setStatus] = useState<'idle' | 'submitting' | 'success' | 'error'>('idle');
const [hasStarted, setHasStarted] = useState(false);
const handleFocus = (fieldId: string) => {
// Initial form start
if (!hasStarted) {
setHasStarted(true);
trackEvent(AnalyticsEvents.FORM_START, {
form_id: 'contact_form',
form_name: 'Contact',
});
}
// Field-level transparency
trackEvent(AnalyticsEvents.FORM_FIELD_FOCUS, {
form_id: 'contact_form',
field_id: fieldId,
});
};
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
@@ -29,10 +48,18 @@ export default function ContactForm() {
(e.target as HTMLFormElement).reset();
} else {
console.error('Contact form submission failed:', { email, error: result.error });
trackEvent(AnalyticsEvents.FORM_ERROR, {
form_id: 'contact_form',
error: result.error || 'submission_failed',
});
setStatus('error');
}
} catch (error) {
console.error('Contact form submission error:', { email, error });
trackEvent(AnalyticsEvents.FORM_ERROR, {
form_id: 'contact_form',
error: (error as Error).message || 'unexpected_error',
});
setStatus('error');
}
}
@@ -112,7 +139,7 @@ export default function ContactForm() {
name="name"
autoComplete="name"
enterKeyHint="next"
placeholder={t('form.namePlaceholder')}
onFocus={() => handleFocus('name')}
required
/>
</div>
@@ -126,6 +153,7 @@ export default function ContactForm() {
inputMode="email"
enterKeyHint="next"
placeholder={t('form.emailPlaceholder')}
onFocus={() => handleFocus('email')}
required
/>
</div>
@@ -137,6 +165,7 @@ export default function ContactForm() {
rows={4}
enterKeyHint="send"
placeholder={t('form.messagePlaceholder')}
onFocus={() => handleFocus('message')}
required
/>
</div>