Contentful Personalization & Analytics
    Preparing search index...

    Configuration options for creating an EventBuilder instance.

    The configuration is typically provided by the host application to adapt event payloads to the runtime environment (browser, framework, etc.).

    const builder = new EventBuilder({
    app: { name: 'my-app', version: '1.0.0' },
    channel: 'web',
    library: { name: '@contentful/optimization-sdk', version: '1.2.3' },
    getLocale: () => navigator.language,
    getPageProperties: () => ({
    path: window.location.pathname,
    url: window.location.href,
    title: document.title,
    query: {},
    referrer: document.referrer,
    search: window.location.search,
    }),
    })
    interface EventBuilderConfig {
        app?: { name: string; version: string };
        channel: "mobile" | "server" | "web";
        getLocale?: () => undefined | string;
        getPageProperties?: () => {
            path: string;
            query: Record<string, string>;
            referrer: string;
            search: string;
            title?: string;
            url: string;
            [key: string]: JSONType;
        };
        getUserAgent?: () => undefined | string;
        library: { name: string; version: string };
    }
    Index

    Properties

    app?: { name: string; version: string }

    The application definition used to attribute events to a specific consumer app.

    Type declaration

    • name: string

      Name of the application.

    • version: string

      Version of the application.

    When not provided, events will not contain app metadata in their context.

    channel: "mobile" | "server" | "web"

    The channel that identifies where events originate from (e.g. web, mobile).

    getLocale?: () => undefined | string

    Function used to resolve the locale for outgoing events.

    Type declaration

      • (): undefined | string
      • Returns undefined | string

        The locale string (e.g. 'en-US'), or undefined if unavailable.

    If not provided, the builder falls back to the default 'en-US'. Locale values supplied directly as arguments to event builder methods take precedence.

    getPageProperties?: () => {
        path: string;
        query: Record<string, string>;
        referrer: string;
        search: string;
        title?: string;
        url: string;
        [key: string]: JSONType;
    }

    Function that returns the current page properties.

    Type declaration

      • (): {
            path: string;
            query: Record<string, string>;
            referrer: string;
            search: string;
            title?: string;
            url: string;
            [key: string]: JSONType;
        }
      • Returns {
            path: string;
            query: Record<string, string>;
            referrer: string;
            search: string;
            title?: string;
            url: string;
            [key: string]: JSONType;
        }

        A Page object containing information about the current page.

        • [key: string]: JSONType
        • path: string

          Path component of the page URL (e.g., /products/123).

        • query: Record<string, string>

          Parsed query parameters for the page.

        • referrer: string

          Referrer URL that led to the current page.

        • search: string

          Raw search string including the leading ? (e.g., "?q=test").

        • Optionaltitle?: string

          Title of the page as seen by the user.

        • url: string

          Full URL of the page.

    Page properties are currently added to the context of all events, as well as the properties of the page event. When specified, all properties of the Page type are required, but may contain empty values.

    Page

    getUserAgent?: () => undefined | string

    Function used to obtain the current user agent string when applicable.

    Type declaration

      • (): undefined | string
      • Returns undefined | string

        A user agent string, or undefined if unavailable.

    library: { name: string; version: string }

    The client library metadata that is attached to all events.

    Type declaration

    • name: string

      Name of the SDK/library (e.g., "@contentful/optimization-web").

    • version: string

      Version of the analytics library.

    This is typically used to record the library name and version.