Contentful Personalization & Analytics
    Preparing search index...

    Configuration for InsightsApiClient.

    interface InsightsApiClientConfig {
        baseUrl?: string;
        beaconHandler?: (
            url: string | URL,
            data: {
                events: {
                    channel: "mobile" | "server" | "web";
                    componentId: string;
                    componentType: "Entry" | "Variable";
                    context: {
                        app?: { name: string; version: string };
                        campaign: {
                            content?: string;
                            medium?: string;
                            name?: string;
                            source?: string;
                            term?: string;
                        };
                        gdpr: { isConsentGiven: boolean };
                        library: { name: string; version: string };
                        locale: string;
                        location?: {
                            city?: string;
                            continent?: string;
                            coordinates?: { latitude: ...; longitude: ... };
                            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 };
                        userAgent?: string;
                    };
                    experienceId?: string;
                    messageId: string;
                    originalTimestamp: string;
                    sentAt: string;
                    timestamp: string;
                    type: "component";
                    userId?: string;
                    variantIndex: number;
                }[];
                profile: { id: string; [key: string]: JSONType };
            }[],
        ) => boolean;
        clientId: string;
        environment?: string;
        fetchOptions?: Omit<ProtectedFetchMethodOptions, "apiName">;
    }

    Hierarchy (View Summary)

    • ApiConfig
    • RequestOptions
      • InsightsApiClientConfig
    Index

    Properties

    baseUrl?: string

    Base URL for the API.

    When omitted, the concrete client is expected to construct full URLs internally.

    beaconHandler?: (
        url: string | URL,
        data: {
            events: {
                channel: "mobile" | "server" | "web";
                componentId: string;
                componentType: "Entry" | "Variable";
                context: {
                    app?: { name: string; version: string };
                    campaign: {
                        content?: string;
                        medium?: string;
                        name?: string;
                        source?: string;
                        term?: string;
                    };
                    gdpr: { isConsentGiven: boolean };
                    library: { name: string; version: string };
                    locale: string;
                    location?: {
                        city?: string;
                        continent?: string;
                        coordinates?: { latitude: ...; longitude: ... };
                        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 };
                    userAgent?: string;
                };
                experienceId?: string;
                messageId: string;
                originalTimestamp: string;
                sentAt: string;
                timestamp: string;
                type: "component";
                userId?: string;
                variantIndex: number;
            }[];
            profile: { id: string; [key: string]: JSONType };
        }[],
    ) => boolean

    Handler used to enqueue events via the Beacon API or a similar mechanism.

    Type declaration

      • (
            url: string | URL,
            data: {
                events: {
                    channel: "mobile" | "server" | "web";
                    componentId: string;
                    componentType: "Entry" | "Variable";
                    context: {
                        app?: { name: string; version: string };
                        campaign: {
                            content?: string;
                            medium?: string;
                            name?: string;
                            source?: string;
                            term?: string;
                        };
                        gdpr: { isConsentGiven: boolean };
                        library: { name: string; version: string };
                        locale: string;
                        location?: {
                            city?: string;
                            continent?: string;
                            coordinates?: { latitude: ...; longitude: ... };
                            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 };
                        userAgent?: string;
                    };
                    experienceId?: string;
                    messageId: string;
                    originalTimestamp: string;
                    sentAt: string;
                    timestamp: string;
                    type: "component";
                    userId?: string;
                    variantIndex: number;
                }[];
                profile: { id: string; [key: string]: JSONType };
            }[],
        ): boolean
      • Parameters

        • url: string | URL

          Target URL for the batched events.

        • data: {
              events: {
                  channel: "mobile" | "server" | "web";
                  componentId: string;
                  componentType: "Entry" | "Variable";
                  context: {
                      app?: { name: string; version: string };
                      campaign: {
                          content?: string;
                          medium?: string;
                          name?: string;
                          source?: string;
                          term?: string;
                      };
                      gdpr: { isConsentGiven: boolean };
                      library: { name: string; version: string };
                      locale: string;
                      location?: {
                          city?: string;
                          continent?: string;
                          coordinates?: { latitude: ...; longitude: ... };
                          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 };
                      userAgent?: string;
                  };
                  experienceId?: string;
                  messageId: string;
                  originalTimestamp: string;
                  sentAt: string;
                  timestamp: string;
                  type: "component";
                  userId?: string;
                  variantIndex: number;
              }[];
              profile: { id: string; [key: string]: JSONType };
          }[]

          Array of batched insights events to be sent.

          • events: {
                channel: "mobile" | "server" | "web";
                componentId: string;
                componentType: "Entry" | "Variable";
                context: {
                    app?: { name: string; version: string };
                    campaign: {
                        content?: string;
                        medium?: string;
                        name?: string;
                        source?: string;
                        term?: string;
                    };
                    gdpr: { isConsentGiven: boolean };
                    library: { name: string; version: string };
                    locale: string;
                    location?: {
                        city?: string;
                        continent?: string;
                        coordinates?: { latitude: ...; longitude: ... };
                        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 };
                    userAgent?: string;
                };
                experienceId?: string;
                messageId: string;
                originalTimestamp: string;
                sentAt: string;
                timestamp: string;
                type: "component";
                userId?: string;
                variantIndex: number;
            }[]

            Insights events that should be recorded for this profile.

            InsightsEventArray

          • profile: { id: string; [key: string]: JSONType }

            Partial profile information used to associate events with a user.

            PartialProfile

            • id: string

              Identifier of the profile.

              Used to associate events with an existing profile.

        Returns boolean

        true if the events were successfully queued, false otherwise.

    When provided, this handler is preferred over direct fetch calls. If it returns false, the client falls back to emitting events immediately via fetch.

    clientId: string

    Client identifier used for authentication or tracking.

    environment?: string

    Contentful environment identifier.

    Defaults to main when not provided.

    fetchOptions?: Omit<ProtectedFetchMethodOptions, "apiName">

    Options used to configure the underlying protected fetch method.

    apiName is derived from the client name and must not be provided here.