auto-claude: subtask-2-3 - Add JSDoc to analytics.ts
This commit is contained in:
+38
-7
@@ -1,9 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* Analytics Service
|
||||||
|
* Zentrale Verwaltung von Google Analytics, Facebook Pixel und Cookie-basiertem Tracking
|
||||||
|
*/
|
||||||
|
|
||||||
import ReactGA from 'react-ga4';
|
import ReactGA from 'react-ga4';
|
||||||
|
|
||||||
const TRACKING_ID = 'G-N0PZBL7X18';
|
const TRACKING_ID = 'G-N0PZBL7X18';
|
||||||
const FB_PIXEL_ID = 'XXXXXXXXXXXXXXXXX'; // Ersetze mit deiner Facebook Pixel ID
|
const FB_PIXEL_ID = 'XXXXXXXXXXXXXXXXX'; // Ersetze mit deiner Facebook Pixel ID
|
||||||
|
|
||||||
// Prüft, ob eine bestimmte Cookie-Kategorie aktiviert ist
|
/**
|
||||||
|
* Prüft, ob eine bestimmte Cookie-Kategorie aktiviert ist
|
||||||
|
*/
|
||||||
export const isCookieCategoryEnabled = (category: string): boolean => {
|
export const isCookieCategoryEnabled = (category: string): boolean => {
|
||||||
try {
|
try {
|
||||||
const cookieSettings = localStorage.getItem('cookieSettings');
|
const cookieSettings = localStorage.getItem('cookieSettings');
|
||||||
@@ -17,7 +24,9 @@ export const isCookieCategoryEnabled = (category: string): boolean => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Entfernt alle Google Analytics Cookies
|
/**
|
||||||
|
* Entfernt alle Google Analytics Cookies
|
||||||
|
*/
|
||||||
const removeGACookies = (): void => {
|
const removeGACookies = (): void => {
|
||||||
const cookies = document.cookie.split(';');
|
const cookies = document.cookie.split(';');
|
||||||
for (let i = 0; i < cookies.length; i++) {
|
for (let i = 0; i < cookies.length; i++) {
|
||||||
@@ -33,7 +42,9 @@ const removeGACookies = (): void => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Google Analytics Initialisierung - mit strikter Zustimmungsprüfung
|
/**
|
||||||
|
* Initialisiert Google Analytics mit strikter Zustimmungsprüfung
|
||||||
|
*/
|
||||||
export const initGA = (): void => {
|
export const initGA = (): void => {
|
||||||
if (!isCookieCategoryEnabled('analytics')) {
|
if (!isCookieCategoryEnabled('analytics')) {
|
||||||
// Entferne bestehende GA-Cookies, falls keine Zustimmung
|
// Entferne bestehende GA-Cookies, falls keine Zustimmung
|
||||||
@@ -49,6 +60,9 @@ export const initGA = (): void => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loggt einen Seitenaufruf in Google Analytics
|
||||||
|
*/
|
||||||
export const logPageView = (): void => {
|
export const logPageView = (): void => {
|
||||||
if (!isCookieCategoryEnabled('analytics')) {
|
if (!isCookieCategoryEnabled('analytics')) {
|
||||||
return;
|
return;
|
||||||
@@ -61,6 +75,9 @@ export const logPageView = (): void => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trackt ein benutzerdefiniertes Event
|
||||||
|
*/
|
||||||
export const trackEvent = (category: string, action: string, label?: string): void => {
|
export const trackEvent = (category: string, action: string, label?: string): void => {
|
||||||
if (!isCookieCategoryEnabled('analytics')) {
|
if (!isCookieCategoryEnabled('analytics')) {
|
||||||
return;
|
return;
|
||||||
@@ -73,6 +90,9 @@ export const trackEvent = (category: string, action: string, label?: string): vo
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trackt eine Conversion
|
||||||
|
*/
|
||||||
export const trackConversion = (value?: number): void => {
|
export const trackConversion = (value?: number): void => {
|
||||||
if (!isCookieCategoryEnabled('analytics')) {
|
if (!isCookieCategoryEnabled('analytics')) {
|
||||||
return;
|
return;
|
||||||
@@ -85,6 +105,9 @@ export const trackConversion = (value?: number): void => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trackt Performance-Timing
|
||||||
|
*/
|
||||||
export const trackTiming = (category: string, variable: string, value: number): void => {
|
export const trackTiming = (category: string, variable: string, value: number): void => {
|
||||||
if (!isCookieCategoryEnabled('analytics')) {
|
if (!isCookieCategoryEnabled('analytics')) {
|
||||||
return;
|
return;
|
||||||
@@ -98,7 +121,9 @@ export const trackTiming = (category: string, variable: string, value: number):
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Facebook Pixel Initialisierung - nur mit Zustimmung
|
/**
|
||||||
|
* Initialisiert Facebook Pixel nur mit Zustimmung
|
||||||
|
*/
|
||||||
export const initFBPixel = (): void => {
|
export const initFBPixel = (): void => {
|
||||||
if (!isCookieCategoryEnabled('marketing')) {
|
if (!isCookieCategoryEnabled('marketing')) {
|
||||||
return;
|
return;
|
||||||
@@ -122,7 +147,9 @@ export const initFBPixel = (): void => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Facebook Event tracking
|
/**
|
||||||
|
* Trackt Facebook Pixel Events
|
||||||
|
*/
|
||||||
export const trackFBEvent = (event: string, params?: Record<string, unknown>): void => {
|
export const trackFBEvent = (event: string, params?: Record<string, unknown>): void => {
|
||||||
if (!isCookieCategoryEnabled('marketing') || typeof window === 'undefined' || !window.fbq) {
|
if (!isCookieCategoryEnabled('marketing') || typeof window === 'undefined' || !window.fbq) {
|
||||||
return;
|
return;
|
||||||
@@ -131,7 +158,9 @@ export const trackFBEvent = (event: string, params?: Record<string, unknown>): v
|
|||||||
window.fbq('track', event, params);
|
window.fbq('track', event, params);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Google Fonts Handling - nur mit funktionaler Cookie-Zustimmung
|
/**
|
||||||
|
* Initialisiert Google Fonts nur mit funktionaler Cookie-Zustimmung
|
||||||
|
*/
|
||||||
export const initGoogleFonts = (): void => {
|
export const initGoogleFonts = (): void => {
|
||||||
if (!isCookieCategoryEnabled('functional')) {
|
if (!isCookieCategoryEnabled('functional')) {
|
||||||
// Entferne bestehende Google Fonts
|
// Entferne bestehende Google Fonts
|
||||||
@@ -151,7 +180,9 @@ export const initGoogleFonts = (): void => {
|
|||||||
// Code hier zur lokalen Einbindung der Schriftarten
|
// Code hier zur lokalen Einbindung der Schriftarten
|
||||||
};
|
};
|
||||||
|
|
||||||
// Funktionale Cookies initialisieren
|
/**
|
||||||
|
* Initialisiert funktionale Cookies und Services
|
||||||
|
*/
|
||||||
export const initFunctionalCookies = (): void => {
|
export const initFunctionalCookies = (): void => {
|
||||||
if (!isCookieCategoryEnabled('functional')) {
|
if (!isCookieCategoryEnabled('functional')) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user