Contentful Personalization & Analytics
    Preparing search index...

    Client for interacting with the Experience API.

    This client is responsible for reading and mutating Ninetailed profiles using the Experience API.

    const client = new ExperienceApiClient({
    clientId: 'org-id',
    environment: 'main',
    })

    const profile = await client.getProfile('profile-id')

    Extends ApiClientBase.

    Hierarchy

    • ApiClientBase
      • ExperienceApiClient
    Index

    Constructors

    Properties

    baseUrl: string

    Base URL used for Experience API requests.

    clientId: string

    Client identifier used for authentication or tracking.

    environment: string

    Contentful environment associated with this client.

    Protected fetch method used by the client to perform HTTP requests.

    name: string

    Name of the API client, used in log messages and as the apiName for fetch.

    Methods

    • Logs errors that occur during API requests with standardized messages.

      Parameters

      • error: unknown

        The error thrown by the underlying operation.

      • options: { requestName: string }

        Additional metadata about the request.

        • requestName: string

          Human-readable name of the request operation.

      Returns void

      Abort errors are logged at warn level and other errors at error level. The log message includes the client name for better debugging context.

    • Sends multiple events to the Ninetailed Experience API to upsert many profiles.

      Parameters

      Returns Promise<
          | {
              audiences: string[];
              id: string;
              location: {
                  city?: string;
                  continent?: string;
                  coordinates?: { latitude: number; longitude: number };
                  country?: string;
                  countryCode?: string;
                  postalCode?: string;
                  region?: string;
                  regionCode?: string;
                  timezone?: string;
              };
              random: number;
              session: {
                  activeSessionLength: number;
                  averageSessionLength: number;
                  count: number;
                  id: string;
                  isReturningVisitor: boolean;
                  landingPage: {
                      path: string;
                      query: Record<string, string>;
                      referrer: string;
                      search: string;
                      title?: string;
                      url: string;
                      [key: string]: JSONType;
                  };
              };
              stableId: string;
              traits: Record<string, JSONType>;
          }[]
          | undefined,
      >

      The list of profiles affected by the batch operation.

      Batch requests must contain at least one event. Every event must contain an anonymous ID. Profiles will be created or updated according to the anonymous ID.

      This method is intended to be used from server environments.

      const profiles = await client.upsertManyProfiles({
      events: [
      { anonymousId: 'anon-1', type: 'identify', ... },
      { anonymousId: 'anon-2', type: 'identify', ... },
      ],
      })