- Concepts
Lightweight tracking
The Sitecore Content SDK identifies bots and supports lightweight tracking for Angular applications. The SDK identifies requests from web crawlers and other automated agents, tracks them separately from real users, and ensures that bot traffic does not skew analytics or trigger unnecessary processing such as personalization.
Bot detection runs as Express middleware in your application's server entry point and integrates with Sitecore events to record bot page views on the server.
Flow of bot detection
When an incoming request is identified as a bot:
- The SDK sends a single page view event to the Sitecore Events API during middleware execution, recorded on the
botchannel. - The SDK sets the
sc_botcookie on the request and response so that subsequent middleware and server-side rendering can identify the request as bot traffic. - Personalization is skipped, so no visitor variant is resolved and no call is made to Sitecore CDP.
- Your application's own page view is suppressed automatically, so the crawler is counted once rather than twice.
This keeps analytics data clean and reduces unnecessary overhead for bot traffic. Analytics contain a single, server-side page view for the bot request.
Your tracking components need no changes. The pageView function checks whether the current visitor is a bot before sending anything, so the page view your application would normally send is dropped for crawlers while the middleware's dedicated bot event is recorded instead.
For real visitors, the SDK tracks page views normally through the SITECORE_ANALYTICS token, as described in Plugins.
Using createBotTrackingMiddleware
createBotTrackingMiddlewareTo enable bot detection, add createBotTrackingMiddleware to the Express middleware chain in src/server.ts:
The middleware handles the following automatically:
- Detecting bots from the incoming HTTP request.
- Sending a page view event for bots to the Sitecore Events API.
- Setting the
sc_botcookie so that following middleware and the server-side render can react accordingly.
Options
| Option | Description |
|---|---|
contextId, edgeUrl | Sitecore Edge configuration. Spread ...config.api.edge to supply them. contextId is required to send bot events. |
locales | Locales used to extract the language from the request path. |
defaultLanguage | Fallback language when the request path has no locale prefix. Defaults to en. |
defaultSite | Fallback site name when the multisite middleware or site cookie has not resolved one. |
matcher | Path rules controlling which requests the middleware processes. API routes, Sitecore routes, and static files are excluded by default. |
skip | A predicate receiving the request. Return true to skip bot detection for that request. |
To disable bot detection, remove the middleware registration.
Middleware order
Register bot detection after the multisite middleware and before the redirects and personalization middleware:
Multisite runs first because it resolves the site the request belongs to, which the bot page view is recorded against. Bot detection must run before personalization so the personalization middleware can read the sc_bot cookie and decide whether to skip.
Requests that are skipped
Bot detection does no work for a request when any of the following applies:
- The request is an editing or preview session.
- The path does not match the configured
matcher. - Your
skippredicate returnstrue. - The application is running on
localhostor in adevelopmentenvironment, unless theSITECORE_ENABLE_BOT_TRACKINGenvironment variable is set totrue. - The request has no
user-agentheader. - The user agent is not identified as a known crawler.
- The request is a browser prefetch.
For identified bot requests, the middleware awaits SDK initialization and the bot page view event before calling the next middleware, so those requests can incur additional latency. This delay does not affect non-bot requests. If detection or event reporting fails, the middleware logs the error at debug level and the request continues normally; it never blocks or fails the response.
Bot traffic and personalization
createBotTrackingMiddleware also enables the personalization middleware to skip work for crawler requests. The personalization middleware uses this out of the box: personalization is disabled for bot traffic by default and does not trigger variant resolution.
If you need personalization to run for bot requests, opt in explicitly:
In most scenarios, keep the default behavior so that bot traffic stays inexpensive and personalization metrics remain accurate.