Make personalized content editable in Netlify Create.
Netlify Create can integrate with the current generation of headless CMS-native personalization engines.
A significant challenge for editors using these engines is navigating through the CMS content tree to actually edit multiple variants and targeting rules, without actually getting immediate feedback on their work (more about that challenge here).
In other words, the common hardships with a headless CMS are made worse by the extra layers added for personalization. Integrating a personalization tool into Netlify Create is meant to ease this pain.
Here's what such integrations typically provide:
- Quick discovery: any personalized page sections are visually marked as such in the visual editor.
- Previewing variants: the user can switch between the default variant (the one selected by the engine) and any other variant.
- Editing and adding variants is done within the visual editor, without leaving the page.
For personalization to be editable with Netlify Create, the content should be stored in a supported content source. Variants should be stored either in fields within a document, or (more commonly) as separate referenced documents.
Editing Personalized Content
Making personalized content editable with Netlify Create is a three-step process:
- Mare sure you fetch all variants from the content source. If you're using a GraphQL API to access your CMS, make sure that all variants and their IDs are included in the query.
- Wrap any relevant components with a higher-order component rendering a variant selection control for the user.
- Ensure all variants are annotated.
The mechanism for this depends on the web framework (Next.js example). For any component that is personalizable, create a wrapper component (only in non-production environments!).
The responsibilities of this wrapper are:
- If the wrapped component instance is actively personalized, render a badge over the component for quick discovery by content editors.
- For personalized instances, render a drop-down control over the component with the option to show either the default variant (the one selected by the perosnalization engine) or explicitly select any of the existing variants.
- When a user selects a specific variant, the wrapper should: (a) render that variant as its child, rather than the default one, and (b) persist the user selection on the client-side, so that it's not lost when navigating between pages.
This behavior should only exist in your application when it is running in development mode. This is commonly achieved using the
NODE_ENV environment variable. There is also a
STACKBIT_PREVIEW environment that is set in Netlify Create cloud projects.
The last step is to ensure that any variant rendered is properly annotated, whether it's the default variant returned by the personalization engine or a user-selected variant.
As a reminder:
- If storing variants as individual documents in the content source, use
data-sb-object-idon an element that wraps the personalized content.
- If variants are stored as individual fields, use
Handling Gated Content
Netlify Create can also handle content that is behind a gate or paywall, or content that requires user authentication.
The process follows a similar pattern to personalization. As long as there is a way to access content in a supported content source, it can be edited.
There are two approaches commonly taken to let editors access to gated content:
Impersonating a User
In many cases, developers choose to provide the ability to impersonate a specific user or a request. In this mode, the content editor sees exactly what that end-user should see, and edit it. How this is implemented varies significantly based on the needs of the project.
Bypassing the Gate
An alternative approach is to make all gated content available when the site is running in development mode. This tends to speed up the editing process, but comes with risk:
- You must remember (and should test) that gated content is not available in production.
- Page visuals may differ slightly if not edited in the same context in which the content is presented in production.
We have an example project that uses Contentful to store content and Ninetailed for handling user profiles & personalization.
Personalization example built with Next.js, using Contentful to store content and Ninetailed for audience control.
View Example Code
Run the project locally by running the
create-stackbit-app command, then following the README setup instructions.
npx create-stackbit-app@latest --example ninetailed-personalization