Contentful Personalization & Analytics
    Preparing search index...

    Analytics implementation that maintains local state (consent, profile) and queues events until flushed or the queue reaches a maximum size.

    Hierarchy

    • AnalyticsBase
      • AnalyticsStateful

    Implements

    • ConsentGuard
    Index

    Constructors

    Properties

    allowedEventTypes?: string[]

    Allow‑list of event type keys permitted when consent is not present.

    api: default

    Optimization API client used to send events to the Experience and Insights APIs.

    builder: EventBuilder

    Event builder used to construct strongly‑typed events.

    duplicationDetector: ValuePresence

    Deduplication helper used to track previously seen values within optional scopes

    interceptors: LifecycleInterceptors

    Interceptors that can mutate/augment outgoing events or optimization state.

    states: AnalyticsStates = ...

    Exposed observable state references.

    Methods

    • Send all queued events grouped by profile and clear the queue.

      Returns Promise<void>

      Only under rare circumstances should there be more than one profile in a stateful application.

    • Determine whether the named operation is permitted based on consent and allowed event type configuration.

      Parameters

      • name: string

        The method name; 'trackComponentView' is normalized to 'component' for allow‑list checks.

      Returns boolean

      true if the operation is permitted; otherwise false.

    • Guard used to suppress duplicate component/flag view events based on a duplication key and the component identifier.

      Parameters

      • _name: string

        The operation name (unused).

      • payload: [
            {
                campaign?: {
                    content?: string;
                    medium?: string;
                    name?: string;
                    source?: string;
                    term?: string;
                };
                componentId: string;
                experienceId?: string;
                locale?: string;
                location?: {
                    city?: string;
                    continent?: string;
                    coordinates?: { latitude: number; longitude: number };
                    country?: string;
                    countryCode?: string;
                    postalCode?: string;
                    region?: string;
                    regionCode?: string;
                    timezone?: string;
                };
                page?: {
                    path: string;
                    query: Record<string, string>;
                    referrer: string;
                    search: string;
                    title?: string;
                    url: string;
                    [key: string]: JSONType;
                };
                screen?: { name: string; [key: string]: JSONType };
                sticky?: boolean;
                userAgent?: string;
                variantIndex?: number;
            },
            string,
        ]

        Tuple of [builderArgs, duplicationScope].

      Returns boolean

      true if the event is NOT a duplicate and should proceed.

    • Hook invoked when an operation is blocked due to missing consent.

      Parameters

      • name: string

        The blocked operation name.

      • payload: unknown[]

        The original arguments supplied to the operation.

      Returns void

    • Hook invoked when an operation is blocked by the duplication guard.

      Parameters

      • name: string

        The blocked operation name.

      • payload: unknown[]

        The original arguments supplied to the operation.

      Returns void

    • Queue a component view event for the active profile.

      Parameters

      • payload: {
            campaign?: {
                content?: string;
                medium?: string;
                name?: string;
                source?: string;
                term?: string;
            };
            componentId: string;
            experienceId?: string;
            locale?: string;
            location?: {
                city?: string;
                continent?: string;
                coordinates?: { latitude: number; longitude: number };
                country?: string;
                countryCode?: string;
                postalCode?: string;
                region?: string;
                regionCode?: string;
                timezone?: string;
            };
            page?: {
                path: string;
                query: Record<string, string>;
                referrer: string;
                search: string;
                title?: string;
                url: string;
                [key: string]: JSONType;
            };
            screen?: { name: string; [key: string]: JSONType };
            sticky?: boolean;
            userAgent?: string;
            variantIndex?: number;
        }

        Component view builder arguments.

      • _duplicationScope: string = ''

        Optional string used to scope duplication (used by guards); an empty string '' is converted to the undefined scope

      Returns Promise<void>

    • Queue a flag view event for the active profile.

      Parameters

      • payload: {
            campaign?: {
                content?: string;
                medium?: string;
                name?: string;
                source?: string;
                term?: string;
            };
            componentId: string;
            experienceId?: string;
            locale?: string;
            location?: {
                city?: string;
                continent?: string;
                coordinates?: { latitude: number; longitude: number };
                country?: string;
                countryCode?: string;
                postalCode?: string;
                region?: string;
                regionCode?: string;
                timezone?: string;
            };
            page?: {
                path: string;
                query: Record<string, string>;
                referrer: string;
                search: string;
                title?: string;
                url: string;
                [key: string]: JSONType;
            };
            screen?: { name: string; [key: string]: JSONType };
            sticky?: boolean;
            userAgent?: string;
            variantIndex?: number;
        }

        Flag view builder arguments.

      • _duplicationScope: string = ''

        Optional string used to scope duplication (used by guards); an empty string '' is converted to the undefined scope

      Returns Promise<void>