Quick Start for Developers (React)
This quick reference guide describes the steps you need to follow to integrate Ninetailed in your website.
In this quick guide you will learn how to integrate Ninetailed in a website using Contentful as headless CMS and React for the frontend in five steps:
- 1.Install Contentful App
- 2.Create a personalized variant
- 3.Install React SDK
- 4.Get visitor profile
- 5.Personalize components
Install our Contentful App from the official marketplace.
- 1.Select the space and environment you want to install the app.
- 2.Authorize the app access.
- 3.Link your Contentful account to Ninetailed.
- 4.Create an organization in Ninetailed.
- 5.Set up the content types for dynamic content personalization.
- 6.Confirm your settings and install the app. 🙃
A variant is a relevant content for a specific audience. To create a variant in Contentful:
- 1.Edit or create an entry of any content type which was set up in the install process.
- 2.Create a new variant for the entry and update the content.
- 3.Create a new audience and publish it.
- 4.Publish the variant and the entry and you're done. 🙌
To show the variants in the frontend you need to install Ninetailed React SDK.
Install
@ninetailed/experience.js-react
module via npm or yarn.yarn add @ninetailed/experience.js-react
This is what the configuration of
@ninetailed/experience.js-react
looks like:import React from 'react';
<NinetailedProvider
// ...
plugins={[
new NinetailedGoogleAnalyticsPlugin({
actionTemplate: 'User has seen personalized component:{{Audience.id}}',
labelTemplate:'{{ baselineOrVariant }}: {{ component.__typename }} - {{ component.id }}',
})
]}
>
//... Your Application Components
</NinetailedProvider>
The next step is to fire a page view to get the profile of the visitor.
This is what a page view looks like:
import React, { useEffect } from 'react';
import { useAnalytics } from '@ninetailed/experience.js-react';
export const Page = () => {
const { page } = useAnalytics();
useEffect(() => {
page();
}, [page]);
// ... your Page component
};
To show the variants in the frontend you need to wrap the components to be personalized.
import React, { useState, useEffect } from 'react';
import { Experience, useAnalytics } from '@ninetailed/experience.js-react';
import Headline from '../Headline.dynamic';
export const Page = () => {
// ...page view effect from Step 4
// fetch the content
const [page, setPage] = useState(null);
useEffect(() => {
// Fetch your content from Contentful as before, just make sure the variants will get fetched.
const { page } = getPageFromContentful();
setPage(page);
}, [setPage]);
return <>
<Experience component={Headline} experiences={page.headline.nt_experience} id={page.headline.sys.id} {...page.headline} />
{/* ...the rest of your page */}
</>
};