JavaScript SDK: The Ninetailed Instance
Leverage custom instantiation options, methods, and properties for precise control over accessing profile data, rendering experiences, and tracking functions.
The Javascript SDK facilitates sending core Ninetailed events and tracking Ninetailed Experience views. These functions are managed by a created Ninetailed
class instance. Internally, the instance uses a NinetailedApiClient
instantiated by the Shared SDK.
A Ninetailed
instance is created and provided when using the <NinetailedProvider>
of React-based Ninetailed SDKs.
Because a Ninetailed class instance contains methods for tracking Experience views, it is mostly intended to be used client-side. For implementations where you want to render Experiences on the server, check out the Shared SDK's underlying NinetailedApiClient
.
Want to browse the code? Check out the Ninetailed instance in our open source SDK.
Dependencies and Instantiation
Ninetailed instances are created using a constructor from Ninetailed JavaScript SDK.
Instantiation Options
NinetailedApiClientInstanceOrOptions
NinetailedApiClientInstanceOrOptions
Provide a created NinetailedApiClient instance (created using the Shared SDK @ninetailed/experience.js-shared), or supply parameters to create one.
|
| The organization ID/API key of a Ninetailed account. |
|
| The environment key of a Ninetailed account. Typically either |
|
| A |
Options
Options
Specify optional configurations for the constructor.
Parameter | Type Signature | Description |
---|---|---|
|
| Supply a function to define a custom context object for events. Useful for working with React in non-web contexts. |
|
| The amount of time in milliseconds an Experience must remain in the viewport to fire any connected plugin tracking calls. Defaults to |
|
| Optionally specify a supported locale code.This will be used to localize location information. |
|
| A logging function to be called on instance errors |
|
| Supply a callback function to assign the ID of a profile. This may be used to ensure that Ninetailed profiles use specific external IDs, e.g., those from a CDP, an ecommerce provider, or analytics instance. |
|
| A logging function to be called on instance warn-level console messages |
|
| Supply an array of Ninetailed plugins. Plugins are used for a variety of purposes, including sending experience impression events, filtering events based on user consent, and previewing experiences. |
|
| The amount of time in milliseconds to wait for a response from the Experience API before falling back to baseline content. Defaults to |
|
| Specify a custom storage implementation. Ninetailed web SDKs default to using localStorage. Useful to store a Ninetailed profile anonymous ID client-side in non-web contexts. |
|
| Specify the base URL of the Experience API to use when not supplying a |
|
| Whether the Ninetailed instance should compute what experience and variants to assign for the current profile using the SDK ( Use |
Instance Methods and Properties
Property/Method | Type Signature | Description |
---|---|---|
| Essential methods of Ninetailed that submit events to the Experience API. See the dedicated documentation on these events. | |
|
| Guarantee multiple events are sent as single batch. Useful in conjunction with |
|
| Method to turn debug mode on or off. Debug mode logs information about profiles' assignment to experiences and its variants. |
|
| A class instance for building Ninetailed event method payloads based on the current context. The Occasionally, you may need access to |
|
| Register a DOM element to be tracked by any plugins attached to the Ninetailed instance. Your plugin tracking events will fire when any part of the element has been visible within the user's viewport for at least the amount of time specified by the |
|
| Register a DOM element to be tracked by any plugins attached to the Ninetailed instance. Your plugin tracking events will fire when any part of the element has been visible within the user's viewport for at least the amount of time specified by the |
|
| Configure a callback function that is executed each time the profile changes. The callback function has access to the changed profile. Additionally, the callback function you supply will be immediately invoked when first calling onProfileChange using the current profile state. |
|
| [Exposed in Next.js and Gatsby SDKs only] Supply a function to be called on each route change. When unspecified, the default is to call the |
|
| Provide a baseline entry, its mapped experience entries, and a callback to execute. The callback has access to the currently selected variant for the supplied baseline/experience combination and will execute any time experience selections change. This method also responds to variants selected within a connected Preview widget. We suggest using this for the most declarative non-React implementations. |
|
| Read the plugins attached to the Ninetailed instance and/or invoke any methods attached to them. |
| { error: Error | null, from: "api" | "hydrated", profile: Profile | null, status: "error" | "loading" | "success", } | Metadata about loading state of a profile and, once loaded, the current profile state. |
|
| Discard the current profile state. |
|
| Immediately send any connected plugin tracking calls for a supplied element. Called by For custom implementations, we recommended using |
|
| Unregister an element for tracking. This is the clean up compliment to |
Last updated