Skip to content

Compass Web SDK: Integration Guide

Last updatedView as Markdown

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 toStart here
Put a personalized recommendations carousel or grid on a pageRecommendations Components quickstart
Put a “while you were away” Catch Up Card on a pageCatch Up Card quickstart
Collect reader events, or render recommendations with your own UIThe Quickstart on this page, then the numbered steps
Find out why a component renders nothingNothing 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.

Not sure the SDK is the right fit? Choose your integration path compares the SDK with Collector API and CDP event collection, and with the other ways to render recommendations.

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-web and experiences key 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 XP 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 the site_id your 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"): after the required arc-compass:item-id meta tag resolves, the SDK sends page_view automatically (see 6. Track events).

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 one delivery token and assign it to both the collect-web and experiences collections. The SDK sends it as the X-API-Key header on event posts and on the Experiences’ recommendation reads, so a key in collect-web alone posts events, but every Experience read is refused. Never use a collector key here. To provision and verify the token, see Provision and Manage Compass API Keys.

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 XP 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 XP 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.

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);
});

The SDK has no analytics-only mode, so a reader who consents to only one of the two purposes gets setConsent(false).

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 after 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 in step 5; 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 data-arc-compass-* attributes on the <script> tag that loads the bundle, or in arc-compass:* meta tags (since SDK 1.2.0). For the attributes, the meta tags, and when the SDK initializes from them, see

Configure from markup

in the JavaScript API reference.

Configuration reference

For every init() option, the debug switches, the onError payload, and cookie-domain detection, see

Configuration options

in the JavaScript API reference.

Browser support

The SDK supports Chrome and Edge 111+, Firefox 113+, Safari and iOS Safari 16.2+, and Samsung Internet 22+. For the browser features each part of the SDK uses, see

Browser support

in the JavaScript API reference.

See also