Rendering Experiences on the edge with Ninetailed's Experience API.
ESR implementations are absolutely supported by Ninetailed and much simpler than this documentation details. This documentation details an approach from a time when the Experience API only returned a profile. Now, the Experience API also returns the list of experiences and variants that the profile should see.
This end-to-end example documentation will be updated 🔜. In the mean time, see:
Experience API selected experiencesWorking with the Shared SDKESR Code Example
The easiest way to get started with Ninetailed is to use our SDKs client-side to select the applicable personalization or experiment variants. However, it is possible to retrieve Ninetailed profiles and select and render the appropriate experience variants in either server or edge contexts. This allows the first page requested by your visitors to show the appropriate content without having to wait for hydration to complete.
You can use Next.js to fetch personalized content from the server and serve a fully updated page via server side rendering.
Methodology
Ninetailed returns an up-to-date representation of a profile whenever an event is sent to the Ninetailed Experience API. By storing a Ninetailed anonymous ID in a cookie, an edge- or server-side function can make requests to update and receive the visitor's profile.
After receiving the profile edge- or server-side, you'd then use Ninetailed's SDK methods to select the appropriate combination of experiences and their variants. You can cache each unique combination so that subsequent visitors can be performantly served the same combination.
Use the loadingComponent prop of the <Experience> component to serve the selected experience and variant. Then, the rehydrated Ninetailed SDKs will take over again on client-side so that new experiences and variants can be rendered immediately in response to the visitor's changing audiences.
Full ESR Example
This example shows how to retrieve a profile, select the correct experiences and variants, and pass that information to the Next.js origin from a Cloudflare Worker edge function (though any edge function provider can be used).
Two utility functions are used to build the page event and send the request to the Ninetailed Experience API. The edge function then extracts the information out of the returned profile to select the appropriate experiences variants and passes them in the URL as a hash, which also serves as the cache key. getStaticProps then reads this hash to provide the correct props to the page. Finally, the <Experience> component uses an ESRLoadingComponent as the value of the loadingComponent prop to render the edge-selected experience and variant.