Compass Web SDK: Integration Guide
Audience: Front-end and site developers integrating a publisher site with the Compass Web SDK.
The Compass Web SDK — published as @arcxp/compass-sdk and exposed in the
browser as the global ArcCompass — is Arc XP’s first-party, client-side library
for collecting reader interaction events (page views, video progress, clicks,
and more) and posting them to the event collector. These events train the
recommendation models.
It ships as a single bundled JavaScript file for <script> inclusion, and also
as an npm ESM module for build-pipeline consumers (React / Next). The target is
a roughly one-hour integration: paste a snippet, call init() once, resolve
consent, and add an Experience tag or call track() for each event.
Choose your path
| You want to | Start here |
|---|---|
| Put a personalized recommendations carousel or grid on a page | Recommendations Components quickstart |
| Put a “while you were away” Catch Up Card on a page | Catch Up Card quickstart |
| Collect reader events, or render recommendations with your own UI | The Quickstart on this page, then the numbered steps |
| Find out why a component renders nothing | Nothing renders? |
The SDK-rendered Experiences are the fastest way to get Compass onto a page: each one is the setup on this page plus a single tag.
Before you start
Some are account or deployment prerequisites, and each one, if missed, leaves events refused or Experiences empty. Check them before you write any code. The Prerequisites & Enablement page covers each one in full.
- Compass is provisioned, and you have a delivery token. Arc XP has
confirmed your organization is provisioned, and you have a delivery token in
the
collect-webandexperienceskey collections. See A delivery credential. - Your origins are allowed. The Compass endpoints accept browser
requests only from origins Arc XP has registered for your organization.
Send Arc XP Client Support every exact
scheme://host[:port]you load the SDK from, including staging and test origins. A page on any other origin fails with a CORS error. See What Arc needs from you. - Your Content Security Policy allows the SDK. If your site sends a CSP, add the sources in Content Security Policy.
- You know your
site_id. It must be thesite_idyour content was ingested under. For Arc XP CMS customers, that is the Arc XP website ID. See Find your site_id. - Your readers’ browsers are supported. See Browser support.
If a component still renders nothing after setup, work through Nothing renders?.
Quickstart
Paste this into an index.html, replace {org}, <arc-delivery-token>, and
<your-site-id>, and serve it from http://localhost (for example,
npx serve .). It initializes the SDK, resolves consent, collects events, and
renders a recommendations carousel. Every placeholder is explained in the
numbered steps that follow.
<!doctype html><html lang="en"><head> <meta charset="utf-8" /> <title>Compass quickstart</title>
<!-- Required to render any Experience: the Site to read recommendations for. --> <meta name="arc-compass:site-id" content="<your-site-id>" /> <!-- On an article, uncomment and set this to the ID the content was ingested under: it drives the automatic page_view. Leave it out on a homepage or section front. Experiences render without it. --> <!-- <meta name="arc-compass:item-id" content="<content-item-id>" /> -->
<style> :root { --arc-compass-font-family: Georgia, serif; --arc-compass-font-family-secondary: "Helvetica Neue", Arial, sans-serif; --arc-compass-accent: #b00020; } </style>
<script> (function (w, d) { w.ArcCompass = w.ArcCompass || { q: [] }; ["init", "setConsent", "setUserId", "track", "trackExposure", "refreshExperiences", "flush"].forEach(function (m) { w.ArcCompass[m] = w.ArcCompass[m] || function () { w.ArcCompass.q.push([m, [].slice.call(arguments)]); }; }); // getUserId returns a value, so it can't ride the queue: until the bundle // attaches there is no identifier yet, so the stub returns null. w.ArcCompass.getUserId = w.ArcCompass.getUserId || function () { return null; }; // observeRecommendations returns a handle: queue the call and return a // deferred handle that wires to the real detector once the bundle loads. w.ArcCompass.observeRecommendations = w.ArcCompass.observeRecommendations || function (options) { var record = { disconnected: false, real: null }; w.ArcCompass.q.push(["observeRecommendations", [options, record]]); return { disconnect: function () { record.disconnected = true; if (record.real) record.real.disconnect(); } }; }; var s = d.createElement("script"); s.async = true; s.src = "https://arc-rec.app-recommend.aws.arc.pub/arc-rec/v1.2.0/compass-sdk.iife.min.js"; s.integrity = "sha384-VvYEr4g99L9WMmYHPcTMN3vZyiIlN4jT+c/GtVx5CBfQimkjKeTbE/Njl6hWfdGZ"; s.crossOrigin = "anonymous"; d.head.appendChild(s); })(window, document);
window.ArcCompass.init({ // Your org's Arc edge origin, with no path. The SDK derives the event // collector and Experiences endpoints from it. origin: "https://{org}-config-prod.api.arc-cdn.net", apiKey: "<arc-delivery-token>", // Logs why an Experience renders nothing. Remove it before you ship. debug: true, });
// PLACEHOLDER: replace this function with your consent manager's (CMP's) // callback before you ship. It grants consent only on localhost, so a copy // that reaches production grants nothing. function onConsentDecision(callback) { callback(location.hostname === "localhost" || location.hostname === "127.0.0.1"); } // The SDK stores nothing between pages: call setConsent on every page load. // Until you do, no event is sent and Experiences render nothing. onConsentDecision(function (granted) { window.ArcCompass.setConsent(granted); }); </script></head><body> <!-- No space is reserved: the tag takes no room until content arrives, and stays collapsed if there is nothing to show. --> <arc-compass-recommendations-carousel surface-id="quickstart" heading="Recommended for you" ></arc-compass-recommendations-carousel></body></html>page_view is captured automatically, so the quickstart does not call
track("page_view"). For events only, delete the carousel tag. To use the
Catch Up Card instead, swap the tag for <arc-compass-catchup-card>. If nothing
appears, see Nothing renders?.
The rest of this guide walks through each step.
The snippet does not call track("page_view"): once the required arc-compass:item-id meta tag resolves, the SDK sends page_view automatically (see 6. Track events). An earlier version of this quickstart called it after init(), which counted each tagged article twice. If you copied that version, remove the call.
To configure the SDK with HTML attributes instead of an init() call (since SDK
1.2.0), see Configure from markup.
1. Provision a delivery token
Provision a delivery token through the Arc XP Delivery API — see Provisioning tokens through the Delivery API.
The SDK sends this token as the X-API-Key header on every request.
Assign the key to both the collect-web and experiences
collections: the SDK sends it on event posts and on the Experiences’
recommendation reads. A key in collect-web alone posts events, but every
Experience read is refused. Neither collection can reach the content catalog,
so the key is safe to embed in page JavaScript.
2. Add the snippet
Place this block in <head>, before any code that calls ArcCompass.*:
<script> (function (w, d) { w.ArcCompass = w.ArcCompass || { q: [] }; ["init", "setConsent", "setUserId", "track", "trackExposure", "refreshExperiences", "flush"].forEach(function (m) { w.ArcCompass[m] = w.ArcCompass[m] || function () { w.ArcCompass.q.push([m, [].slice.call(arguments)]); }; }); // getUserId returns a value, so it can't ride the queue: until the bundle // attaches there is no identifier yet, so the stub returns null. w.ArcCompass.getUserId = w.ArcCompass.getUserId || function () { return null; }; // observeRecommendations returns a handle: queue the call and return a // deferred handle that wires to the real detector once the bundle loads. w.ArcCompass.observeRecommendations = w.ArcCompass.observeRecommendations || function (options) { var record = { disconnected: false, real: null }; w.ArcCompass.q.push(["observeRecommendations", [options, record]]); return { disconnect: function () { record.disconnected = true; if (record.real) record.real.disconnect(); } }; }; var s = d.createElement("script"); s.async = true; s.src = "https://arc-rec.app-recommend.aws.arc.pub/arc-rec/v1.2.0/compass-sdk.iife.min.js"; s.integrity = "sha384-VvYEr4g99L9WMmYHPcTMN3vZyiIlN4jT+c/GtVx5CBfQimkjKeTbE/Njl6hWfdGZ"; s.crossOrigin = "anonymous"; d.head.appendChild(s); })(window, document);</script>The snippet defines a tiny stub on window.ArcCompass so calls made before the
bundle loads queue up and replay in order.
The snippet loads an exact-version URL (…/arc-rec/v1.2.0/…) with Subresource
Integrity (SRI), so the browser runs only the bytes you tested. To adopt a new
version, update both the version in the URL and the integrity value. The
current version and its hash are in the manifest, as described in Distribution,
which also covers the npm (ESM) install, the optional auto-update URL, and the
self-host fallback.
3. Initialize the SDK
ArcCompass.init({ origin: "https://{org}-config-prod.api.arc-cdn.net", apiKey: "<arc-delivery-token>",});origin is your org’s Arc edge origin: the shared
{org}-config-prod.api.arc-cdn.net hostname, with no path. The SDK derives
every endpoint from it. Events post to
https://{org}-config-prod.api.arc-cdn.net/collect-web/v1/events/batch, and the
SDK-rendered Experiences read from
https://{org}-config-prod.api.arc-cdn.net/experiences/…. Arc provides your
org’s edge origin during onboarding.
init() throws if origin carries a path, such as /collect-web/v1, or is not
an absolute http(s) URL. The error message names the value it received.
4. Resolve consent
Translate whatever your consent manager (CMP) returns into the SDK’s single
yes/no gate. Pass true only when the reader has consented to both analytics
and personalization; if your CMP reports the two purposes separately, combine
them first:
// Wire this to your CMP's decision callback (the exact API differs per CMP).yourCmp.onDecision(function (analytics, personalization) { ArcCompass.setConsent(analytics && personalization);});Call setConsent on every page load. The SDK stores nothing between pages,
so until you call it, no event is sent and SDK-rendered Experiences render
nothing. Events that fired before this call are flushed after consent resolves
to granted. See Consent & Identity
for the full state machine.
5. Add the content and site meta tags
Add these tags to each page’s <head> so the SDK can attribute events to the
right content and Site:
<!-- The content item this page represents; it must match the ID the content was ingested under. Required for automatic page_view on a content page. Leave it out on a homepage or section front. --><meta name="arc-compass:item-id" content="ARTICLE-ABC123" />
<!-- The Site this page belongs to. Optional for event attribution on a single-site tenant; REQUIRED on every tenant if you use the SDK-rendered recommendation or Catch Up Experiences, whose render request needs it. --><meta name="arc-compass:site-id" content="the-daily" />The Experiences do not send item-id: a page without it still renders them, as
long as site-id resolves.
item-id must be present for automatic page_view capture to fire. In a
single-page app, set it whenever your route knows the ID — before or after
navigating, or once an awaited content load resolves. The SDK fires when the tag
changes, so there is no ordering to honour and no extra SDK call per route.
The SDK reads the site-id tag each time it needs a Site, so in a single-page
app you can rewrite it on every route. If your pages always belong to the same
Site, pass siteId to init() instead (since SDK 1.2.0). It takes priority over
the meta tag, and the SDK then never reads the tag:
ArcCompass.init({ origin: "https://{org}-config-prod.api.arc-cdn.net", apiKey: "<arc-delivery-token>", siteId: "the-daily",});You can override either value for a single event with
track(type, { itemId, siteId }).
See Events & Reliability for the full resolution order.
6. Track events
ArcCompass.track("video_progress", { itemId: "VIDEO123", eventValue: 0.75 });page_view is captured automatically for the item the page loads with, and again
whenever the page becomes about a different item. You do not need to call
track("page_view") yourself on a server-rendered page or an SPA route, unless
you disable auto capture (autoPageView: false). item_id and the optional site_id come from the
meta tags you set above; pass itemId or siteId to track() to override them
for a single event. See Events & Reliability.
7. (Optional) Set a known user ID after login
ArcCompass.setUserId("user-abc-123");// Pass null on logout to revert to the persistent anonymous ID.ArcCompass.setUserId(null);A stable, host-managed ID is what makes personalization work across devices. See Consent & Identity.
Configure from markup
Instead of calling init(), you can put the SDK configuration in HTML. The
bundle reads it when it loads and initializes itself, so you don’t write any
JavaScript to set up the SDK.
Add the configuration as data-arc-compass-* attributes on the <script> tag
that loads the bundle:
<head> <meta name="arc-compass:item-id" content="ARTICLE-ABC123" /> <meta name="arc-compass:site-id" content="the-daily" /> <script src="https://arc-rec.app-recommend.aws.arc.pub/arc-rec/v1.2.0/compass-sdk.iife.min.js" integrity="sha384-VvYEr4g99L9WMmYHPcTMN3vZyiIlN4jT+c/GtVx5CBfQimkjKeTbE/Njl6hWfdGZ" crossorigin="anonymous" data-arc-compass-origin="https://{org}-config-prod.api.arc-cdn.net" data-arc-compass-api-key="<arc-delivery-token>" ></script> <script> // Pass true after your CMP reports consent. ArcCompass.setConsent(true); </script></head><body> <!-- … --> <arc-compass-recommendations-list surface-id="article-footer"></arc-compass-recommendations-list></body>Load the bundle with a plain <script> tag, without async or defer, so
ArcCompass exists when the code that follows it runs. To load the bundle
asynchronously, use the loader snippet and put the
configuration in meta tags instead (see Meta tags).
Consent is not part of the markup configuration. You still call
ArcCompass.setConsent() from your consent code, as described in
Resolve consent. Until you do, the SDK sends no events and
SDK-rendered Experiences render nothing.
Attributes
Each attribute sets the init() option of the same name. See the
configuration reference for what each option does.
| Attribute | init() option | Value |
|---|---|---|
data-arc-compass-origin | origin | Required, unless data-arc-compass-domain is set. |
data-arc-compass-api-key | apiKey | Required. |
data-arc-compass-site-id | siteId | Optional. The Site every event and Experience uses. |
data-arc-compass-domain | domain | Optional override. |
data-arc-compass-experiences-domain | experiencesDomain | Optional override. |
data-arc-compass-cookie-domain | cookieDomain | Optional. |
data-arc-compass-attribution-root | attributionRoot | Optional. A CSS selector, or false to turn off the scan. |
data-arc-compass-auto-page-view | autoPageView | Optional. On unless set to false or 0. |
data-arc-compass-debug | debug | Optional. On when present, unless set to false or 0. |
The batching, queue, and onError options have no attribute. To set them, call
init() instead.
Meta tags
If you can’t add attributes to the <script> tag, for example because a tag
manager or the loader snippet inserts it, use meta tags with the same names:
<meta name="arc-compass:origin" content="https://{org}-config-prod.api.arc-cdn.net" /><meta name="arc-compass:api-key" content="<arc-delivery-token>" />If an attribute and a meta tag set the same option, the attribute is used.
The Site is the exception. <meta name="arc-compass:site-id"> keeps the meaning
described in Add the content and site meta tags:
the SDK reads it each time it needs a Site, so it can change from route to
route. It does not count as configuration. To fix the Site for every page, use
the data-arc-compass-site-id attribute.
When the SDK initializes
The SDK initializes from markup when the page finishes parsing
(DOMContentLoaded), and only if the page sets an origin, a domain, or an API
key. A page that declares none of them, for example one with only a
data-arc-compass-debug attribute, does not initialize from markup.
- An
init()call made before then takes precedence, whether you call it directly or the loader snippet queues it. The SDK ignores the markup configuration entirely; it does not merge the two. - Calls such as
setConsent(),setUserId(), andtrack()made before the SDK initializes are held and applied in order right after it initializes, from either source. - The SDK initializes only one time, so an
init()call made after it has initialized from markup has no effect: none of its options apply, includingonError. The SDK logs aconsole.errorinstead of throwing. If you need an option that markup can’t express, callinit()beforeDOMContentLoaded, or remove the markup configuration. - If the markup configuration is invalid, for example because the API key is
missing, the SDK logs a
console.errorand does not initialize. A laterinit()call still works.
Configuration reference
ArcCompass.init(options) accepts the following options. Only apiKey and one
of origin or domain are required.
| Option | Type | Default | Description |
|---|---|---|---|
origin | string | — (required unless domain is set) | Your org’s Arc edge origin with no path, for example https://{org}-config-prod.api.arc-cdn.net. The SDK derives the event collector endpoint (/collect-web/v1/events/batch) and the Experiences endpoints (/experiences/…) from it. init() throws if it carries a path, query, or fragment, or is not an http(s) URL. Since SDK 1.2.0. |
apiKey | string | — (required) | Arc-provisioned delivery token. Sent as X-API-Key on every request — event posts and the SDK-rendered Experiences’ recommendation reads alike. |
domain | string | origin + /collect-web/v1 | Override for the events collector base path, for example https://{org}-config-prod.api.arc-cdn.net/collect-web/v1. The SDK appends /events/batch. Set it only when your event collector is not at the path origin implies. On SDK versions earlier than 1.2.0, this option is required in place of origin. |
experiencesDomain | string | origin | Override for the origin the SDK-rendered Experiences read from, the Arc edge root the /experiences/… recommendation and Catch Up routes hang off. Defaults to origin, or, when only domain is set, to domain with a trailing /collect-web/v<n> removed. Set it only when the Experiences service is on a different host from your event collector. |
siteId | string | the arc-compass:site-id meta tag | The Site every event and Experience read uses. Takes priority over <meta name="arc-compass:site-id">, which the SDK then never reads; a siteId passed to track() still overrides it for that event. Leave it unset on a host whose Site varies by route, and set the meta tag on each route instead. See Add the content and site meta tags. Since SDK 1.2.0. |
cookieDomain | string | detected registrable domain | Cookie Domain attribute for the anonymous-ID and session cookies. Defaults to the broadest scope the browser accepts for the current host, found by probing rather than by counting labels, so ccTLDs and platform hosts share identity across subdomains without configuration. Set it explicitly to override. See Cookie domain. |
batch.maxEvents | number | 20 | Flush when the buffer reaches this many events. |
batch.flushIntervalMs | number | 2000 | Flush this many milliseconds after the last flush. |
queue.maxBuffered | number | 500 | Hard cap on in-memory queued events. Oldest are dropped on overflow with a console.warn. |
autoPageView | boolean | true | Fire page_view automatically each time the <meta name="arc-compass:item-id"> tag resolves to a new item (covering the initial load and every SPA route change), reading the optional site_id from <meta name="arc-compass:site-id"> at the same moment. Set false to call track('page_view', { itemId }) yourself. |
attributionRoot | Element | string | false | document.body | Root under which the SDK scans for host-rendered recommendations carrying the data-arc-compass-* binding — also the click-delegation container, so tagged elements (and elements passed to trackExposure) must live inside it. Accepts an element or a CSS selector (resolved once the DOM is ready). Narrow it to the container that holds recommendations to avoid a page-wide MutationObserver; pass false to disable the scan entirely. A structurally-broken root (invalid selector, or a non-Element value) disables the binding with a console.warn; a valid selector whose container has not mounted yet is deferred and attaches on the next trackExposure. See Recommendation Attribution. |
debug | boolean | false | Log lifecycle and transport diagnostics, including the event and Experiences endpoints the SDK resolved from your configuration, the cookie scope it detected, and why an SDK-rendered Experience showed nothing. You can also turn it on without editing init(); see Diagnostics and Nothing renders?. |
onError | (e: ArcCompassErrorInfo) => void | — | Called when the SDK abandons a batch (a terminal 4xx/429, or a 5xx/network failure that exhausts retries), and when the browser accepts no cookie scope so identity drops to per-origin (reason: "degraded", no events lost). Use it to forward otherwise-silent loss to your observability. Never runs inside a track() call, so it cannot interrupt the page; anything it throws is swallowed. See Error visibility. |
Diagnostics
The debug option logs lifecycle, transport, and Experience-render diagnostics
to the console. When you can’t edit the init() call, for example because it
sits in a tag manager or a template you don’t own, you can turn debug on from
the page (since SDK 1.2.0):
- Add
?arcCompassDebugto the page URL. - Add a
data-arc-compass-debugattribute to the<script>tag that loads the SDK.
Either one turns debug on even when init() passes debug: false. A value of
0 or false leaves it off.
Separately from debug, the SDK logs one console.warn when an
<arc-compass-*> Experience tag on the page can’t render (since SDK 1.2.0). The
SDK checks a few seconds after the page loads, and the warning names the cause:
init()never ran, threw, or couldn’t load the Experience.setConsent()hasn’t been called, so the Experience is still waiting for consent.
The warning is always on, and logs at most one time per page. It stays silent
when the SDK is initialized and consent is set, including setConsent(false),
because a Reader who declines consent is not an integration error.
Error visibility
The SDK is fire-and-forget: track() never throws, and a batch that the
collector rejects (or that never gets through) is dropped rather than surfaced
to the page. To make those drops observable, wire onError to your tooling — it
fires for terminal transport failures and for one client-side degradation, both
off the user’s interaction path:
ArcCompass.init({ origin: "https://{org}-config-prod.api.arc-cdn.net", apiKey: "<browser token>", onError: (e) => { // e: { message, reason: "rejected" | "exhausted" | "degraded", status?, droppedEvents, eventTypes, cause? } Sentry.captureException(e.cause ?? new Error(e.message), { extra: e }); // or: datadogRum.addError(e.cause ?? new Error(e.message), e); },});reason: "rejected" is a 4xx/429 the collector refused (fix the payload or
key — retrying won’t help); reason: "exhausted" means repeated 5xx/network
failures used up the retry budget. status is absent for network/CORS errors
(no response). reason: "degraded" loses no events at all (droppedEvents is
0): it fires at most once per page when the browser accepted no cookie scope,
which costs you cross-subdomain identity — see
Cookie domain. Per-event issues (an unresolved item_id, a
coerced event_value) are logged only under debug, not through onError.
Cookie domain
When cookieDomain is omitted, the SDK writes its identity cookies at the
broadest scope the browser accepts for the current host, which is that host’s
registrable domain. It finds the scope by offering each candidate to the
browser and keeping the first one that sticks, rather than by counting labels,
so multi-segment public suffixes (.co.uk, .com.au) and platform hosts
(CloudFront, Vercel, Netlify, GitHub Pages) resolve correctly without
configuration. Probe cookies are deleted as soon as they are read back, and
none is written before consent.
Set cookieDomain explicitly to override the detected scope. If the browser
accepts no scope at all, identity still works but is per-origin rather than
shared across subdomains, and onError fires once with reason: "degraded"
(see Error visibility).
Browser support
The SDK supports Chrome and Edge 111+, Firefox 113+, Safari and iOS Safari
16.2+, and Samsung Internet 22+. That floor is set by the rendered
Experiences; event collection on its own runs on older browsers too, with the
caveats in the table. The floor ships as the browserslist field in the
package’s package.json.
| Feature | Used for | Chrome / Edge | Firefox | Safari | Without it |
|---|---|---|---|---|---|
fetch with keepalive: true | Sending events, including the flush when the reader leaves the page | 66 | 133 | 13 | Events still send, but the final flush on page exit can be lost |
visibilitychange, pagehide | Detecting when the reader leaves, to flush queued events | 33 | 18 | 7 | Events still in the queue when the reader leaves may not be sent |
localStorage, sessionStorage, cookies | Anonymous and session IDs | All | All | All | If storage is blocked, IDs do not persist across page views |
crypto.randomUUID | Generating IDs | 92 | 95 | 15.4 | Falls back to crypto.getRandomValues; no effect |
| Custom elements, shadow DOM | Every Experience is an <arc-compass-*> element with a shadow root | 67 | 63 | 10.1 | Experiences do not render |
IntersectionObserver | Exposure attribution; Catch Up Card view telemetry | 58 | 55 | 12.1 | Exposure events are not sent; click attribution still works |
::part() | Restyling Experience internals from your CSS | 73 | 72 | 13.1 | Your ::part() rules do not apply |
color-mix(), including in oklab | The Catch Up Card’s neutral colours: muted text, hairlines, subtle fills | 111 | 113 | 16.2 | The card renders without its fills and hairlines, and muted text shows at full strength |
The recommendations Components do not use color-mix(), so they render in
older browsers as well, but only the floor above is supported. In Firefox
before 133, the event flush on page exit is best-effort. For more on theming
features, see Compass Web SDK: Theming Reference.
The SDK is browser-only. The IIFE bundle is safe to include in a
server-rendered page — it no-ops on import when window is undefined.
See also
- Compass API Developer Guide — how this path fits the whole integration, and when to use a forwarder instead.
- Compass Web SDK: Consent & Identity
- Compass Web SDK: Events & Reliability
- Compass Web SDK: Distribution & FAQ
- Compass Onboarding Checklist