Shared SDK
Shared SDK: The NinetailedApiClient
The Shared SDK exposes Ninetailed data objects, types, and methods applicable across runtimes. The Shared SDK allows you to create an API Client that facilitates constructing and sending Experience API events. It also handles retrying requests and request errors.
Elements of the shared SDK are composed to create the JavaScript SDK, which is then composed into Ninetailed’s React-based SDKs.
For more information about the code, see the shared SDK in our open source repository.
Instantiation
Profile methods
A NinetailedAPIClient maps one function for each Experience API endpoint. upsertProfile is also provided to conveniently switch between create and update functions.
The returned response of each method is the same as that of the Experience API: a data structure indicating the complete representation of the profile(s) and the Ninetailed Experiences and variants that the Experience API has selected for the profile(s).
Request options
All of profile methods accept request options in addition to the supplied events. These are used to control request timeout & retry behavior, performance, localization, and location resolution.
Event building functions
Each of the profile methods above accepts an array of events. Event building helper functions facilitate generating the required payload for page, track, and identify events. These builder methods take care of parsing the supplied ctx.url and populating context properties on events commonly used by Audience rules, including context.page and context.campaign.
Example shared SDK usage
This is a short example of using the buildPageEvent helper to create a well-formatted event of type page and using it to upsert a profile.
Despite the brevity of this example, this is all it takes to get started working with Ninetailed in edge functions and middleware.