/sitecore-content-sdk:content-sdk-analytics-eventsfrom Sitecore Content SDK - Core
Sends Content SDK analytics events including pageView, event, form, and identity calls to SitecoreAI. Use when adding or debugging tracking calls in a Sitecore head app.
Ships in Sitecore Content SDK - Core. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The Content SDK sends visitor events to SitecoreAI by calling POST {edgeUrl}/v1/events/v1.2/events?siteId=<site> with the x-sitecore-contextid header. One core singleton (initContentSdk) holds two plugins. analyticsPlugin owns the visitor id: it calls create.json and stores the result in the sc_cid cookie. eventsPlugin owns the five send functions. Every event function reads that singleton at call time, and that one fact explains most of the limits below.
src/Bootstrap.tsx, src/components/content-sdk/CdpPageView.tsx or any call into @sitecore-content-sdk/events.content-sdk-tracking-consent. That skill owns the banner wiring, the gates, withdrawal and the cookie categories. This skill assumes the gate exists and never bypasses it._variantId_ rewrites). Use content-sdk-personalization.sitecoreai-personalization.The SDK has no consent API. A call you add here is consent-safe only if it can run when the visitor has consented and cannot run when they have not. In practice, every helper in this skill goes through the gate that content-sdk-tracking-consent defines. That covers Bootstrap's init, CdpPageView, your custom helpers, <Form> and PersonalizeProxy.skip. Do not add a second, local consent check, and do not call initContentSdk from anywhere except the place that skill defines.
| Piece | Where (App Router) | What it does |
|---|---|---|
Bootstrap (client) | src/app/[site]/layout.tsx, first child before {children} | initContentSdk({config:{contextId: clientContextId, edgeUrl, siteName}, plugins:[analyticsPlugin({options:{enableCookie:true, cookieDomain: hostname without www.}, adapter: analyticsBrowserAdapter()}), eventsPlugin()]}). Skips NODE_ENV=development and draftMode |
CdpPageView (client) | rendered by Layout through Scripts | pageView({channel, currency, page, pageVariantId, language}) once per route, only when mode.isNormal |
BotTrackingProxy | src/proxy.ts, second, after preview | Bot UA → sc_bot=1 cookie plus a server botPageView in waitUntil |
analyticsPlugin before eventsPlugin.config.api.edge.clientContextId, which defaults to NEXT_PUBLIC_SITECORE_EDGE_CONTEXT_ID and is inlined into the public bundle. The server uses config.api.edge.contextId (SITECORE_EDGE_CONTEXT_ID). defineConfig has no analytics or events keys; everything is set through plugin options.window.scContentSDK.analytics_core.options.contextId and compare it with the context you expect.[IE-002] SDK not initialized, and the scaffold's .catch(console.debug) swallows it. Bootstrap's effect depends only on [siteName, isPreviewMode], so it does not re-run on soft navigation. The cache-components template wraps Bootstrap in <Suspense>; whether the ordering still holds there is [probe-gated: P6, cache-components leg not yet run].src/pages/_app.tsx, and the proxy chain has no LocaleProxy. Otherwise the same rules apply.| Event | API (@sitecore-content-sdk/events) | Wire type | Send from | Use it for |
|---|---|---|---|---|
| Page view | pageView(data?: PageViewData) | VIEW (the dashboard shows it as "pageView") | Client, through the scaffold's CdpPageView only | Every normal page render. pageVariantId ties the view to a personalization or A/B variant |
| Custom | event(data: EventData) | your type string | Client by default | Interactions and conversions |
| Form | form(formId, 'VIEWED' | 'SUBMITTED', componentInstanceId) | FORM | Client, automatic through the SDK <Form> component | Sitecore Forms. Never hand-wire it |
| Identity | identity(data: IdentityData) | IDENTITY | Client today. Server-side is [probe-gated: P14] | Login or a known-visitor form submit. It is the input to identity resolution, which is off until an org identity rule exists |
| Bot view | botPageView({page, language, userAgent}) | VIEW, channel:'bot' | Server, inside BotTrackingProxy only | Crawler traffic. Never call it yourself |
Field limits are enforced client-side, and a violation throws (the promise rejects) rather than being swallowed:
extensionData: at most 50 attributes after flattening (IV-006). It applies to pageView, event and identity.identity: identifiers: [{id, provider}] is required (MV-003). dob is date-only YYYY-MM-DD (IV-003) from events 2.1.2 on. identifier.expiryDate must be a full ISO date-time (IV-005). email is validated (IV-004). The beta.atoms builds predate 2.1.2 and reject a date-only dob.pageView reads the referrer only on the first view per page load (static isFirstPageView). includeUTMParameters defaults to true.currency from the site's real currency. The scaffold hard-codes 'USD'.Minimal calls, with full typed signatures in references/api-surface.md:
await event({ type: 'ACME_NEWSLETTER_SIGNUP', channel: 'WEB', page: route.name, language, extensionData: { list: 'weekly' } });
await identity({ identifiers: [{ id: crmId, provider: 'acme-crm' }], email, dob: '1990-04-15', channel: 'WEB' });
// pageView and form: leave them to CdpPageView and <Form>
Put one helper in src/lib/tracking.ts and make every component call it. Never call event() directly from a component.
'use client';
import { event, type EventData } from '@sitecore-content-sdk/events';
import { getClientId } from '@sitecore-content-sdk/analytics-core';
const SITE_PREFIX = 'ACME'; // one per site; see § 5
export async function track(action: string, extensionData?: EventData['extensionData'], page?: string) {
try {
getClientId(); // throws IE-002 when Bootstrap did not init: dev, editing/preview, no consent
} catch {
return null;
}
if (document.cookie.split('; ').some((c) => c.startsWith('sc_bot='))) return null; // event() does not skip bots
return event({
type: `${SITE_PREFIX}_${action}`,
channel: 'WEB',
page,
language: document.documentElement.lang || undefined,
extensionData,
}).catch((e) => { console.debug('[track]', e); return null; }); // validation errors reject
}
Why each guard exists:
event() rejects. The getClientId() probe turns "no init" (dev, draftMode, no consent) into a silent no-op, so the helper inherits the suppression that Bootstrap and the consent gate already apply.pageView skips bots, but event() and identity() do not. A bot has no sc_cid, so the event goes out with browser_id: "" and is rejected (404 or 400 observed), swallowed as null. sc_bot is set server-side and is readable from JS.useSitecore().page.mode.isNormal before calling, as CdpPageView does.sendEvent uses fetch with no keepalive, so an event fired on a click that navigates to another site is lost: measured 2026-10-05 on a production build (real Chrome UA), the POST stayed pending when the cross-origin navigation replaced the page. A same-origin hard navigation (a plain <a> to the same site) is safe: the event and the next page's VIEW both returned 201. For outbound links either accept the undercount and document it, delay-then-navigate (await trackEvent with a ~300 ms timeout, then location.assign), or queue via @sitecore-content-sdk/events/browser and flush on the visitor's next page (only if they return). A redirecting form submit is unmeasured [probe-gated: P16]../browser queue. addToEventQueue / processEventQueue from @sitecore-content-sdk/events/browser batch events in sessionStorage across navigations. They still await init, so they are not a way to buffer events before init.src/byoc/index.tsx passes the whole events module to BYOC components (FEAAS.setContextProperties({ eventsSDK: Events })). A BYOC component's eventsSDK.event(...) uses the same singleton and the same rules. Route it through the same naming convention, and make the BYOC author aware of the consent gate.Decision rule: send from the client by default. Use a server event only when the action exists only on the server (a webhook or a server-validated conversion), and only if all of the following hold:
analyticsProxyAdapter(req, carrier) a new NextResponse(null) as the carrier, then copy carrier.cookies.getAll() onto the response you return. return NextResponse.next() from a Route Handler is HTTP 500 ("not supported"). Without the cookie copy, a fresh visitor's sc_cid is lost. RSC cannot set cookies at all. The full code is in references/server-events.md.page, language and referrer explicitly. Server-side they default to an empty string or null.create.json for bots, so the event goes out with browser_id: "", gets a 400, and event() resolves null without throwing.initContentSdk overwrites a process-global singleton, and event() reads it at call time. In a measured run, 50 parallel requests with 0–200 ms jitter sent 49 of 50 events under another visitor's browser_id, and edge-platform answered 201 to all 50. Without jitter it was 24 of 50. Set-Cookie stayed correct per request, so nothing in the response reveals the mis-attribution. Until Sitecore fixes the singleton, a per-request initContentSdk on the server is safe only when calls are serialized per process. The escape hatch is a direct POST with the request's own sc_cid and no SDK state (references/server-events.md). The same singleton runs inside PersonalizeProxy and BotTrackingProxy; whether the proxy path cross-contaminates is [probe-gated: P22].Pages Router: analyticsServerAdapter(req, res) takes Node IncomingMessage / OutgoingMessage and has the same singleton problem. Its API-route behaviour has not been probed. Treat it as [probe-gated: not yet in the probe plan].
The ingress accepts any type string with 201. That includes typos, lowercase strings and the legacy reserved SC_ prefix. The Performance → Events dashboard lists custom events by their exact type, next to pageView. Naming discipline is therefore the only control.
<SITE>_<OBJECT>_<ACTION>, upper snake case, for example ACME_NEWSLETTER_SIGNUP or ACME_PDP_ADD_TO_CART. The SDK's own JSDoc suggests site:ACTION. Pick one form per estate and never mix them.VIEW, IDENTITY, FORM, the legacy CDP names ADD, SEARCH, TRACKING, INTERACTION, anything starting SC_ (SC_SEARCH_WIDGET_VIEW / _CLICK belong to Sitecore Search), and the display label pageView. Ingress does not reject them. How the dashboard and Profiles treat them downstream is [probe-gated: P10].type: 'search' with core: { componentId, componentInstanceId, interactionType, keyword, nullResults } feeds the search dashboard (content-sdk-search). It is distinct from standalone Search's SC_SEARCH_WIDGET_* and from the reserved uppercase legacy SEARCH. Case sensitivity [probe-gated: P7].type stable. The dashboard groups by the string, so a rename starts a new row. Put variable data in extensionData, never in type.<SITE>_PROBE_* type or extensionData.probe_tag, so they can be filtered out of live dashboards.| Context | Bootstrap init | CdpPageView | Custom helper (§ 3) | <Form> | BotTrackingProxy |
|---|---|---|---|---|---|
next dev | off | off | no-op (IE-002) | fires, unhandled IE-002 [probe-gated: P16] | off |
| Pages editing / preview (draftMode) | off | off (!mode.isNormal) | no-op | off in editing | skips preview |
Bot UA (isbot) | inits, but no sc_cid | skipped ("visitor is a bot") | no-op (sc_bot) | skipped | sets sc_bot, sends botPageView |
Headless browser (Playwright default, HeadlessChrome, curl) | treated as a bot | skipped | no-op | skipped | sc_bot (not on localhost) |
localhost production build | on | on | on | on | skipped, unless SITECORE_ENABLE_BOT_TRACKING=true |
| No consent | off (via the consent skill) | off | no-op | see the consent skill | unaffected (sets only sc_bot) |
The editing host is a production build. Whether it leaks events on direct, non-preview hits is [probe-gated: P21].
Errors are swallowed, and there is no timeout. sendEvent catches every transport failure and resolves null, so a console with no output proves nothing.
next build && next start, or the deployment). Dev and preview send nothing.…Chrome/141.0.0.0 Safari/537.36. A default headless UA is a bot, and every "0 events" assertion run with one passes even when tracking is broken.GET …/browser/create.json returns 201 and sc_cid is set. Only then trust a count.POST …/v1/events/v1.2/events returns 201 {"status":"OK","ref":…}, and the request body type is your name.No sitecore context (wrong or missing context id) or Invalid browser id/ref specified (missing or unknown sc_cid). siteId is not validated: a bogus site also gets 201, so it is not a negative control. Use a bogus context id instead.DEBUG=content-sdk:events (or the fetch tap in references/testing.md); the events log includes the response status.type, with event and session counts, next to pageView. Ingestion latency, and whether IDENTITY and FORM show up there and in Profiles, are [probe-gated: P10].siteId is not validated). Sitecore's site analytics need one identifier per site language, and a site created by serialization push or a newly added language has none (sitecoreai-sites § Pitfalls). Whether events sent without one are kept, dropped, or attributed later is [probe-gated].Recipes, Playwright code and controls: references/testing.md. Wire shapes and the 404/400 table: references/wire-format.md.
content-sdk-tracking-consent. Never add an ungated initContentSdk or a direct event() call.NextResponse.next(), and are never concurrent until T15 is fixed.CdpPageView, form events to <Form> and bot views to BotTrackingProxy. Do not double-send them.ext attributes, identifiers present, date-only dob.sc_cid or send any event without going through the consent gate.identity() would carry restricted data (health, payment, government ids). SitecoreAI forbids it, and deletion needs a support case.references/api-surface.md: exports, typed signatures, .d.ts paths, error codes.references/wire-format.md: create.json, the events request and response, the 404/400 classes, the cookies tracking sets.references/server-events.md: the carrier-pattern Route Handler, the direct-POST escape hatch, the T15 evidence.references/testing.md: Playwright UA pinning, network assertions, controls, the concurrency check.content-sdk-tracking-consent, content-sdk-personalization, content-sdk-app-router-multisite-management (proxy chain order).What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub chris1415/sitecore-skills-pocs --plugin sitecore-content-sdk23 skills in this plugin
/content-sdk-atomic-design-assessmentAssesses a Content SDK head app for Atomic Design: scan src/components, rate each low-code candidate / partial / keep-code, derive the atom set, plan a side-by-side migration. Use when asked which components could become atoms. Not writing atoms./content-sdk-collection-data-modelPicks the data model for a component that shows many items: owned rows, derived view, curated list or shared library, and how each is delivered. Use when migrating a tree-walking list or a list is not editable in Pages. Not row templates./content-sdk-Other plugins' skills for the same job