Consolidated analytics, events, and tracking in Content SDK v2.0
Best practices for transitioning to consolidated analytics
Start typing to search...
If you've worked with Sitecore XM Cloud's analytics and tracking before Content SDK v2.0, you've dealt with the Cloud SDK. It had a separate initialization path, its own lifecycle, and a pattern that always felt slightly disconnected from the rest of your front-end. With Content SDK v2.0, Sitecore has consolidated that functionality into three focused packages and a single initialization function. The result is a cleaner, more modular approach that fits naturally into how we already build Next.js applications.
With that in mind, let's have a look at what changed, why it matters, and how to migrate.
Previously, analytics and event tracking in XM Cloud relied on the Cloud SDK which was nothing more than a standalone package with its own initialization:
//TODO: Confirm exact old CloudSDK init pattern from your project
import { CloudSDK } from '@sitecore-cloudsdk/core';
import '@sitecore-cloudsdk/events';
import '@sitecore-cloudsdk/personalize';
// Initialization typically happened in _app.tsx or a layout component
await CloudSDK({
siteName: process.env.SITECORE_SITE_NAME,
sitecoreEdgeContextId: process.env.SITECORE_EDGE_CONTEXT_ID,
// ... additional config
}).initialize();This worked, but had some challenges:
Content SDK v2.0 replaces Cloud SDK with a plugin-based architecture. Everything runs through a single initContentSdk function, and you opt into capabilities by registering plugins:
//TODO: Confirm exact import paths and plugin registration API
import { initContentSdk } from '@sitecore-content-sdk/core';
import { analyticsPlugin } from '@sitecore-content-sdk/analytics-core';
import { eventsPlugin } from '@sitecore-content-sdk/events';
await initContentSdk({
siteName: process.env.SITECORE_SITE_NAME,
sitecoreEdgeContextId: process.env.SITECORE_EDGE_CONTEXT_ID,
plugins: [
analyticsPlugin(),
eventsPlugin(),
// personalize plugin covered in Part 7
],
});@sitecore-content-sdk/analytics-core — The foundational analytics layer. Handles core tracking infrastructure including page views, session management, and the data pipeline to Sitecore's analytics backend. This is the package you'll always include if you need any analytics at all.@sitecore-content-sdk/events — Custom event tracking. If you're firing events beyond basic page views including button clicks, form submissions, video plays, custom engagement goals. It's this package that provides that API. Registers via eventsPlugin.@sitecore-content-sdk/personalize — Handles personalization variant resolution and audience evaluation on the front-end. We'll cover this in depth in Part 7 of this series, but know that it follows the same plugin pattern.Migrating from Cloud SDK to Content SDK 2.0+ for managing the Sitecore CDP and Personalize improves things on a number of levels including:
npm install @sitecore-content-sdk/analytics-core @sitecore-content-sdk/events
# If using personalization:
npm install @sitecore-content-sdk/personalizenpm uninstall @sitecore-cloudsdk/core @sitecore-cloudsdk/events @sitecore-cloudsdk/personalizeFind where you previously called CloudSDK().initialize() which typically resides in _app.tsx, a layout component, or a dedicated initialization file. Replace it with initContentSdk and the appropriate plugins.
// Before
import { CloudSDK } from '@sitecore-cloudsdk/core';
import '@sitecore-cloudsdk/events';
await CloudSDK({
siteName: process.env.SITECORE_SITE_NAME,
sitecoreEdgeContextId: process.env.SITECORE_EDGE_CONTEXT_ID,
}).initialize();
// After
import { initContentSdk } from '@sitecore-content-sdk/core';
import { analyticsPlugin } from '@sitecore-content-sdk/analytics-core';
import { eventsPlugin } from '@sitecore-content-sdk/events';
await initContentSdk({
siteName: process.env.SITECORE_SITE_NAME,
sitecoreEdgeContextId: process.env.SITECORE_EDGE_CONTEXT_ID,
plugins: [
analyticsPlugin(),
eventsPlugin(),
],
});If you had custom event tracking code you'll want to update each to utilize the new endpoints. This might be things like custom calls to personalize endpoints for dealing with certain events.
Add the new custom Edge hostname variable if you're using custom domains:
SITECORE_EDGE_PLATFORM_HOSTNAME=media.abccompany.comThis is a direct improvement related to what I covered in my Custom Domains article. Previously, configuring custom Edge hostnames required manual URL transformation in your front-end code. The new SITECORE_EDGE_PLATFORM_HOSTNAME environment variable provides native SDK support for this. Migrating to this though in other environments may require additional work as you potentially have created custom rewrite urls for dealing with all that.
This deserves its own callout. In my earlier article on custom domains, we built a getTransformedMediaUrl function to rewrite edge.sitecorecloud.io URLs to a custom domain for SEO and indexing purposes. We also discussed why first-party domains matter for analytics tracking.
Content SDK v2.0 now supports custom Edge hostnames natively:
SITECORE_EDGE_PLATFORM_HOSTNAME=media.abccompany.comWhat this means in practice:
A smaller but notable addition: Content SDK v2.0 supports custom query parameters in editing render handlers. This is useful when:
This might not impact you terribly much unless you're really utilizing everything within Sitecore CDP and Personalize.
If any of your components imported from @sitecore-cloudsdk/*directly (rather than relying on the global initialization), those imports will break. Audit your codebase:
# Find all CloudSDK references
grep -r "@sitecore-cloudsdk" src/Creating yourself an audit checklist is a handy way to verify your own work. You might have an existing one already that you want to expand upon as you perhaps do this multiple times for multiple clients.
initContentSdk@sitecore-cloudsdk/* imports updated to new packagesSITECORE_EDGE_PLATFORM_HOSTNAME if using custom domains)package.jsonDon't skip this. Analytics bugs are silent. You don't really notice unless you go looking.
The consolidation of Cloud SDK into Content SDK is one of those changes that's easy to underestimate. On paper it largely just involves swapping imports. In practice, it means one initialization path, one versioning story, and a plugin model that lets you include only what you need.
If you've been maintaining a Sitecore XM Cloud project with analytics, this migration is straightforward but worth doing carefully, especially the analytics verification step. Honestly, this is what gets most people because they don't actually verify events are happening and triggering.