Initializing tracking, events, and personalization in the Content SDK
The Content SDK has undergone a major architectural transformation to include functionality from the Sitecore Cloud SDK. This also moves from an older initialization pattern to a modern plugin-based architecture providing better modularity, type safety, and a unified approach to browser and server-side implementations.
Changes to initialization
The earlier initialization chained the required functionality using the dot (.) operator. See examples below for browser and server implementations.
Browser initialization (old)
Server initialization (old)
The new initialization method uses a combination of plugins to determine the functionality and adapters to determine the environment. The initialization function (initContentSdk) accepts a config object (contextId, siteName), and a plugins array, where analytics, events, and personalization are all plugins. Environment differences (browser vs proxy/server) are handled through the chosen adapter. The analyticsPlugin is always present if you use events or personalize.
Browser initialization (new)
Server initialization (new)
Isomorphic functions
The new architecture makes use of isomorphic functions that allows event tracking and other SDK functions to be used identically on both client and server with the same import and function signature. Isomorphic functions provides benefits like using a single import path instead of /browser and /server paths, a consistent API, and type safety across environments.
See the following examples for browser and server environments for the pageView function.
Using the isomorphic version in Content SDK 2.0, you can import it without the /browser or /server in the import path:
Changes to packages and modules
Since the Cloud SDK packages have now been integrated into the Content SDK, the following paths have changed:
|
Old (Cloud SDK) |
New (Content SDK) |
|---|---|
|
|
|
|
|
|
|
|
|
All packages now use a single entry point with environment-specific behavior controlled through adapters. This allows you to use the base import path instead of using /browser or /server.
To use the queue functionality, you must still use the full import path. For example:
Changes to settings
Several settings have been simplified by renaming them and moving them into their specific plugins. See the following table for more information:
|
Old property |
New property |
Description |
|---|---|---|
|
|
|
Simplified name but the same value. |
|
|
|
Optional. Can be provided in the initialization |
|
|
|
Unchanged |
|
|
Moved to plugin options |
Renamed to |
|
|
Moved to plugin options |
Renamed to |
|
|
Moved to plugin options |
Plugin-specific option. For browser: For server: |
Changes to cookies
The following cookies have been renamed:
|
Old name |
New name |
|---|---|
|
|
|
|
|
|
Changes to the window object
window objectContent SDK injects a global scContentSDK variable into the window object when either of the built-in plugins is used with a browser adapter (server and proxy adapters will not add it). window.scContentSDK provides access to the current analytics configuration, the client ID, and library version for diagnostics and debugging purposes, without requiring you to import or directly access any plugin instances.
This replaces the older window.scCloudSDK['analytics-core'] structure from the Cloud SDK, but gives the same stable debugging surface for analytics without coupling your code to the plugins API. The global variable is also resilient to multiple SDK initializations: any new properties introduced by extra plugins will be added to the properties that already exist in the scContentSDK object.
For example, when the SDK is initialized as shown:
The browser adapter (analyticsBrowserAdapter()) in the analytics plugin creates the global variable during the init phase. It contains an analytics_core property with three members:
-
getClientId- a function that returns the current client ID. -
options- an object with the site name, context ID, and edge URL from your SDK configuration. -
version- a string describing the version of theanalytics‑corelibrary used.