UNPKG

multi-platform-tracking-sdk

Version:

🚀 Professional Multi-Platform Tracking SDK for Facebook/Meta Pixel, Instagram Analytics & Google Tag Manager | Zero Dependencies | TypeScript Ready | Privacy Compliant GDPR/CCPA | Created by A. Z. M. Arif | Code Encover

124 lines (123 loc) • 4.59 kB
import { UserData, ValidationResult, TrackingError, MetaPixelConfig, ConversionAPIConfig, HybridTrackerConfig } from './types'; /** * Utility functions for multi platform tracking sdk */ /** * Hash user data using SHA256 as required by Facebook Conversion API * Uses crypto module in Node.js or SubtleCrypto in browsers * @param data - The data to hash * @returns Hashed data in hexadecimal format */ export declare function hashData(data: string): Promise<string>; /** * Synchronous version of hashData for compatibility * Uses simple hash in browsers, crypto in Node.js * @param data - The data to hash * @returns Hashed data in hexadecimal format */ export declare function hashDataSync(data: string): string; /** * Normalize and hash user data for privacy compliance * @param userData - User data to normalize and hash * @returns Normalized and hashed user data */ export declare function normalizeUserData(userData: UserData): UserData; /** * Generate a unique event ID * @param prefix - Optional prefix for the event ID * @returns Unique event ID */ export declare function generateEventId(prefix?: string): string; /** * Get current timestamp in Unix seconds * @returns Current timestamp in seconds */ export declare function getCurrentTimestamp(): number; /** * Validate pixel ID format * @param pixelId - The pixel ID to validate * @returns True if valid, false otherwise */ export declare function isValidPixelId(pixelId: string): boolean; /** * Validate access token format (basic validation) * @param accessToken - The access token to validate * @returns True if valid format, false otherwise */ export declare function isValidAccessToken(accessToken: string): boolean; /** * Validate email format * @param email - The email to validate * @returns True if valid email format, false otherwise */ export declare function isValidEmail(email: string): boolean; /** * Validate phone number format (international) * @param phone - The phone number to validate * @returns True if valid phone format, false otherwise */ export declare function isValidPhone(phone: string): boolean; /** * Validate currency code (ISO 4217) * @param currency - The currency code to validate * @returns True if valid currency code, false otherwise */ export declare function isValidCurrency(currency: string): boolean; /** * Validate event configuration * @param config - Configuration object to validate * @returns Validation result with errors and warnings */ export declare function validateConfig(config: Record<string, unknown> | MetaPixelConfig | ConversionAPIConfig | HybridTrackerConfig): ValidationResult; /** * Validate Meta Conversion API specific configuration * @param config - ConversionAPIConfig to validate * @returns Validation result with errors and warnings */ export declare function validateConversionAPIConfig(config: ConversionAPIConfig): ValidationResult; /** * Sanitize URL for tracking * @param url - URL to sanitize * @returns Sanitized URL */ export declare function sanitizeUrl(url: string): string; /** * Deep clone an object (for avoiding mutations) * @param obj - Object to clone * @returns Deep cloned object */ export declare function deepClone<T>(obj: T): T; /** * Retry function with exponential backoff * @param fn - Function to retry * @param maxRetries - Maximum number of retries * @param delay - Initial delay in milliseconds * @returns Promise that resolves with function result or rejects after max retries */ export declare function retry<T>(fn: () => Promise<T>, maxRetries?: number, delay?: number): Promise<T>; /** * Create a tracking error with additional context * @param message - Error message * @param code - Error code * @param details - Additional error details * @returns Formatted tracking error */ export declare function createTrackingError(message: string, code?: string, details?: unknown): TrackingError; /** * Check if code is running in browser environment * @returns True if in browser, false otherwise */ export declare function isBrowser(): boolean; /** * Check if code is running in Node.js environment * @returns True if in Node.js, false otherwise */ export declare function isNode(): boolean; /** * Safely get nested object property * @param obj - Object to get property from * @param path - Property path (e.g., 'user.profile.name') * @param defaultValue - Default value if property doesn't exist * @returns Property value or default value */ export declare function safeGet(obj: Record<string, unknown>, path: string, defaultValue?: unknown): unknown;