Preview plugin
The Preview plugin allows you to assign your profile to specific audiences, experiences, and variants within preview and development contexts.
Add plugin to the plugins prop of the NinetailedProvider and provide an array of all Ninetailed Experience and Ninetailed Audience entries to the plugin. Ensure that you are supplying both all published and all draft entries of each to the plugin. Additionally, you should ensure that you are not instantiating the plugin in production contexts.
Installation
Add the dependency:
npm
yarn
Then, add the plugin to the instance:
React, Next.js
Gatsby
JavaScript
Conditional instantiation
The Preview Plugin is designed to be used within preview and development contexts.
One way of doing this is through a simple instantiation toggle based on some runtime argument. The code sample below shows conditionally including the plugin only when process.env.NODE_ENV !== 'production', but you are free to use whatever condition best identifies your non-production environments. For example, you might choose to instantiate the plugin based on whether the current visitor has turned on preview or draft mode and use this condition instead or in conjunction.
However, this simple toggle will bundle the preview plugin in production settings. A more robust way would be to dynamically import the preview module only when it is required.
The below Next.js code sample shows returning a <NinetailedProvider> component with the Preview Plugin only when preview data is supplied, leveraging next/dynamic to exclude the depedency from the bundle.
Supply preview content
The Preview Plugin expects a specific format for the provided experiences and audiences. Use the appropriate utility library for your content source to map these to the required format.