Skill 09 · Contentful Personalization
Subchapter 9.1
references/analytics-and-preview.mdMarkdown4 KBView on GitHub
Analytics and preview are part of setup, not afterthoughts.
For new integrations, use the @contentful/optimization guidance. Apply the Ninetailed sections
only when maintaining a repository that already uses the legacy SDK.
Use @ninetailed/experience.js-plugin-insights when the customer wants:
Do not present @ninetailed/experience.js-plugin-analytics as the default built-in answer for these
setups.
Analytics is built in — there is no separate insights plugin to install. Enable it through the SDK:
trackEntryInteraction (React Web SDK / OptimizationRoot) or autoTrackEntryInteraction
(Web SDK) to capture views, clicks, and hovers on OptimizedEntry elements.OptimizedEntry emits the data-ctfl-* attributes the Web SDK observes; resolved entries are
tracked automatically when interaction tracking is on.trackEvent() from useOptimizationActions(). On the SDK instance itself, call
track().<OptimizationRoot
clientId={process.env.NEXT_PUBLIC_OPTIMIZATION_CLIENT_ID!}
trackEntryInteraction={{ views: true, clicks: true, hovers: false }}
>
{children}
</OptimizationRoot>@contentful/optimization: use the router tracker subpath for the router in use
(NextAppAutoPageTracker, NextPagesAutoPageTracker, React Router, TanStack). A Next.js bound
factory exports the matching tracker; the application still mounts it.@ninetailed/experience.js: Pages Router with NinetailedProvider wires this for navigation; App
Router needs a manual tracker.ctfl-opt-aid for Optimization, ntaid for legacy).@contentful/optimization gates events by consent. Events outside allowedEventTypes (default
['identify', 'page']) are blocked until consent is granted, and surface on
states.blockedEventStream / the onEventBlocked callback. Object consent
({ events, persistence }) lets events emit while keeping profile continuity session-only.Use the preview plugin only when the customer needs editor or QA tooling.
Requirements:
Use @contentful/optimization-web-preview-panel for author preview against an existing Web SDK
instance. When the panel is open, live updates are forced on for all OptimizedEntry components so
authors see variant changes immediately. Set liveUpdates on OptimizationRoot (or per
OptimizedEntry) when entries must react to profile/flag/preview changes outside of preview.
If no client SDK runs after render (either SDK family):
Server-only is usually the wrong recommendation for customers who want a healthy experimentation program.