Skip to content

Compass Web SDK: Distribution & FAQ

Last updatedView as Markdown

The Compass Web SDK ships on two channels: a hosted <script> bundle (IIFE) for snippet embedding, and an npm package (ESM) for build-pipeline consumers (React / Next). Both are versioned and cacheable, and every published version is immutable.

We recommend one of two integrations. Both let you decide when to adopt a new version:

  • The exact-version script URL with Subresource Integrity (SRI).
  • The npm package with a committed lockfile.

Hosted bundle (<script>)

Each version is served from a CDN on its own exact-version URL. The URL is immutable: it is cached forever and never overwritten, so its bytes never change.

https://arc-rec.app-recommend.aws.arc.pub/arc-rec/v1.2.0/compass-sdk.iife.min.js

Load an exact-version URL with its integrity hash, so the browser rejects a tampered file:

<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"
async
></script>

crossorigin="anonymous" is required: browsers check integrity on a cross-origin script only in CORS mode. To adopt a new version, update both the version in the URL and the integrity value.

The current version and its hash are published in the manifest:

https://arc-rec.app-recommend.aws.arc.pub/arc-rec/manifest.json

manifest.json lists the latest stable version’s artifacts with their bytes, sha256, and integrity (the sha384- SRI string). Its version is the latest stable version, and its embedPath and embedIntegrity are the exact-version URL path and integrity hash for the recommended embed.

Since SDK 1.2.0, two more manifests carry the same fields:

  • arc-rec/manifest-next.json describes the newest version, prereleases included. Read it to test against the newest candidate.
  • arc-rec/v<version>/manifest.json describes one version and never changes. Read it to pin that version, for example https://arc-rec.app-recommend.aws.arc.pub/arc-rec/v1.2.0/manifest.json.

Auto-update URL (optional)

If you want new backwards-compatible versions without changing your page, you can load the major-version alias instead:

<script
src="https://arc-rec.app-recommend.aws.arc.pub/arc-rec/v1/compass-sdk.iife.min.js"
async
></script>

The v1 alias serves a version that Arc XP has promoted within major version 1. Publishing a new version doesn’t move it; Arc XP moves it deliberately, so it can lag behind the latest version. It is served with a short cache TTL.

npm package (ESM)

Package-managed consumers install from the public npm registry:

Terminal window
npm install @arcxp/compass-sdk
import { ArcCompassClient } from "@arcxp/compass-sdk";

Commit your lockfile (package-lock.json, pnpm-lock.yaml, or yarn.lock) so each build installs the version you tested. The package follows semantic versioning, and a major range such as ^1 picks up compatible fixes when you update your lockfile. Stable versions publish to the latest tag. Prereleases publish to the next tag, so npm install @arcxp/compass-sdk never installs a prerelease.

npm-managed consumers can also load the bundle from a public CDN that fronts npm, for example https://cdn.jsdelivr.net/npm/@arcxp/compass-sdk@1.2.0/dist/compass-sdk.iife.min.js. It is a convenient fallback, but the Arc XP-hosted URL is the supported primary.

Self-hosting the bundle

Customers who cannot reference the hosted URL (strict CSP, air-gapped build, policy requiring first-party assets) can self-host: take dist/compass-sdk.iife.min.js from the npm package (or the release manifest) and serve it from your own origin. Serve it with a long Cache-Control on a versioned path and, if loading cross-origin, the appropriate CORS headers. You own updates when you self-host — re-pull on each SDK release.

Content Security Policy

If your site sends a Content Security Policy (CSP), add these sources to it. Replace {org} with your org.

DirectiveSource to addWhy
script-srchttps://arc-rec.app-recommend.aws.arc.pubLoads the hosted bundle. Not needed if you install from npm or self-host the bundle on an origin your policy already allows.
script-srcA nonce or hash for each inline <script>The loader snippet, and the inline script that calls init() and setConsent(), are inline scripts. Give each one your page’s nonce, or add its hash.
connect-srchttps://{org}-config-prod.api.arc-cdn.netEvents post to this host and Experiences read from it. If you set domain or experiencesDomain to a different host, add that host too.
style-src'unsafe-inline'Needed only if you render SDK Experiences. Each Experience adds a <style> element to its shadow root, and the SDK cannot give that element a nonce. Event collection alone needs nothing here.
img-srcThe hosts that serve your content’s imagesExperience cards load each recommended item’s thumbnail_url in an <img>. Not needed for event collection alone.

For example, a site that renders Experiences and serves images from images.example.com sends this header (shown on several lines for reading; send it as one line):

Content-Security-Policy:
script-src 'self' 'nonce-<per-request-nonce>' https://arc-rec.app-recommend.aws.arc.pub;
connect-src 'self' https://{org}-config-prod.api.arc-cdn.net;
style-src 'self' 'unsafe-inline';
img-src 'self' https://images.example.com

If your script-src uses 'strict-dynamic', the browser ignores host sources and trusts the bundle because the nonced loader snippet inserts it. Keep the nonce on the loader snippet in that case.

A blocked bundle shows a CSP error in the console and leaves every <arc-compass-*> tag empty. A request blocked by connect-src shows a CSP error and fails the same way a network error does.

Versioning and deprecation policy

  • Semantic versioning. Breaking changes bump the major version. An exact-version URL (/arc-rec/v<version>/) or a locked npm version gives you the version you chose; the major-version alias (/arc-rec/v<major>/) and an npm major range follow compatible updates.
  • Deprecation window. A superseded major is supported for at least 90 days before its alias URL is sunset. Exact-version URLs are immutable and remain reachable even after an alias is retired.
  • Changelog. Every release is recorded in the SDK’s CHANGELOG.md, published with the @arcxp/compass-sdk npm package.

Caching

PathCache-ControlNotes
arc-rec/v<version>/…public, max-age=31536000, immutableCache forever; never rewritten
arc-rec/v<major>/…public, max-age=300, must-revalidateMoves only when promoted
arc-rec/manifest.json, arc-rec/manifest-next.jsonpublic, max-age=300, must-revalidateUpdated when a release moves the channel

On each release the CDN invalidates only the channel manifests the release moves (/arc-rec/manifest.json, /arc-rec/manifest-next.json, or both); immutable version directories are never invalidated. When the alias is promoted, the CDN invalidates /arc-rec/v<major>/*.

FAQ

Why is event_value not type-checked against eventType?

The Collector accepts an optional event_value on every event type, except that deepest_scroll requires one and article_save rejects one. The SDK applies those rules at run time instead of in its types: it strips the value from an article_save, drops a deepest_scroll that has no value, and clamps out-of-range values into 0.0–1.0, with a warning on each. Tight typing would have to change every time a new event type is added. See Supported Event Types.

Why don’t you parse TCF / GPP strings?

Vendor-specific consent strings are large and evolving. Forcing the SDK to parse them couples it to a TCF/GPP version and balloons the bundle. The single consent gate (setConsent(true | false)) is small enough that hosts can map any CMP onto it in a few lines.

Why no automatic retry across page loads?

Retry-with-backoff in the browser is mostly useless: the user navigates away long before the third attempt fires. Persistent retry across page loads (via localStorage / IndexedDB) raises consent and correctness problems — replayed events would carry stale identity / consent context. The SDK does retry transient failures within a page (see Events & Reliability).

Why is the item_id for search events synthetic?

The collector requires an item_id on every event, and a search has no natural item. Pass a synthetic ID such as { itemId: "search:" + query }.

No. They sit in the in-memory queue until the queue cap is reached, at which point oldest-first eviction kicks in. The SDK never assumes consent — setConsent must be called explicitly.

How do I see what the SDK is doing?

Pass debug: true to ArcCompass.init() for lifecycle and transport diagnostics on the console. Since SDK 1.2.0, you can also add ?arcCompassDebug to the page URL, or a data-arc-compass-debug attribute to the SDK’s <script> tag, without editing init() (see Diagnostics). For terminal batch drops in production, wire the onError callback (see Error visibility).

What about server-side rendering?

The SDK is browser-only. The IIFE bundle is safe to include in an SSR page — it no-ops on import when window is undefined.

See also