import { AnalyticsConfig } from '@jetshop/core/analytics/AnalyticsProvider'; import { Product, Cart, ProductVariant } from '@jetshop/core/types'; import TypedEventEmitter from 'typed-emitter'; export interface TrackingFunctionContext { trackerRegistry: TrackerRegistry; emit: (event: string, props: any) => void; list?: string; } type Consent = 'granted' | 'denied'; interface BaseConsentEvents { ad_storage: Consent; analytics_storage: Consent; personalization_storage: Consent; security_storage: Consent; [key: string]: Consent; } export interface TrackProductProps { action: 'view' | 'remove' | 'add' | 'click' | 'heed_recommendation'; product: Product; selectedVariation?: ProductVariant; list?: string; listName?: string; index?: number; /** The quantity of items added/removed from cart */ quantity?: number; category: string; } export interface TrackCartProps { cart: Cart; callback?: (response?: Response) => void; } export interface TrackListProps { listName: string; products: Product[]; category?: string; } export interface TrackPageProps { pathname: string; title: string; } export interface TrackExperimentProps { id: string; variant: number; } export interface TrackUserProps { userId: string; } export interface TrackAddToWishListProps { articleNumber: string; productName: string; } export interface TrackingProps { trackProduct: TrackProductProps; trackCartCheckout: TrackCartProps; trackCart: TrackCartProps; trackList: TrackListProps; trackPageView: TrackPageProps; trackExperiment: TrackExperimentProps; trackUser: TrackUserProps; trackLogin: null; trackRegister: null; trackAddToWishList: TrackAddToWishListProps; } export interface InitOptions { trackerRegistry: TrackerRegistry; config: AnalyticsConfig; } export interface BaseTrackingEvents { consent: (props: BaseConsentEvents, context: TrackingFunctionContext, eventId?: string) => void; trackProduct: (props: TrackProductProps, context: TrackingFunctionContext, eventId?: string) => void; trackCartCheckout: (props: TrackCartProps, context: TrackingFunctionContext, eventId?: string, callback?: (response: Response) => void) => void; trackCart: (props: TrackCartProps, context: TrackingFunctionContext, eventId?: string) => void; trackList: (props: TrackListProps, context: TrackingFunctionContext, eventId?: string) => void; trackPageView: (props: TrackPageProps, context: TrackingFunctionContext, eventId?: string) => void; trackExperiment: (props: TrackExperimentProps, context: TrackingFunctionContext, eventId?: string) => void; trackUser: (props: TrackUserProps, context: TrackingFunctionContext, eventId?: string) => void; trackLogin: (props: any, context: TrackingFunctionContext, eventId?: string) => void; trackRegister: (props: any, context: TrackingFunctionContext, eventId?: string) => void; trackAddToWishList: (props: TrackAddToWishListProps, context: TrackingFunctionContext, eventId?: string) => void; } export interface TrackingEvents extends BaseTrackingEvents { [key: string]: (props: any, context: TrackingFunctionContext, eventId?: string) => void; } export declare const trackingEvents: (keyof BaseTrackingEvents)[]; export interface Tracker extends Partial { name: string; initBrowser?: (opts: InitOptions) => void; } export type TrackerRegistryEventEmitter = TypedEventEmitter; export interface TrackerRegistry { on(event: E, args: TrackingEvents[E], opts?: { name?: string; }): void; emit(event: E, props: any, context: TrackingFunctionContext, eventId?: string): boolean; /** * Add `Tracker` to registry. * - Auto-binds built-in events (see `TrackingEvents`) * - Runs `initBrowser` */ add: (tracker: Tracker) => void; trackers: () => string[]; } export declare function createServerTracker({ currency, useArticleNumberAsId, pixelId, token }: { currency: string; useArticleNumberAsId: boolean; pixelId?: string; token?: string; }): Tracker; export declare function trackerRegistry({ config, inServer }: { config: AnalyticsConfig; inServer: boolean; }): TrackerRegistry; export {};