1. Sitecore Content SDK

Adapters

Version:

Adapters provide environment-specific implementations for plugins. They handle the differences between browser and server environments, such as cookie management, request/response handling, and data fetching. In the analytics layer, adapters implement the AnalyticsAdapter interface, which extends the generic PluginAdapter from @sitecore-content-sdk/core.

See the following interface for the built-in AnalyticsAdapter as an example:

export interface AnalyticsAdapter extends PluginAdapter {
  getClientId: () => string | null;
  setClientId: () => Promise<void>;
  location: {
    getSearchParams: () => string;
  };
}

Adapters are passed into plugins at initialization time so that each plugin can remain environment‑agnostic while still performing environment‑specific tasks. In the below example of a browser initialization logic, analyticsPlugin will manage client IDs through methods getClientId and setClientId on the analyticsBrowserAdapter instead of directly modifying window or document objects:

import { initContentSdk } from '@sitecore-content-sdk/core';
import { analyticsPlugin, analyticsBrowserAdapter } from '@sitecore-content-sdk/analytics-core';
import { eventsPlugin } from '@sitecore-content-sdk/events';

initContentSdk({
  config: {
    contextId: '<YOUR_CONTEXT_ID>',
    siteName: '<YOUR_SITE_NAME>',
  },
  plugins: [
    analyticsPlugin({
      adapter: analyticsBrowserAdapter(),
      options: { enableCookie: true },
    }),
    eventsPlugin(),
  ],
});
If you have suggestions for improving this article, let us know!