Transcend Docs

Scripts for airgap.js

Have Transcend build custom JavaScript into your airgap.js bundle so that every site that loads the bundle runs the same logic.

A script is custom JavaScript that Transcend builds into your airgap.js bundle. It runs at the top of the bundle, before airgap.js starts, on every page that loads the bundle.

Transcend installs scripts for you. You cannot add or edit a script in the Admin Dashboard. To request one, contact your Transcend representative.

When to use a script

You need toExample
Run the same consent logic on every siteOne rule for all brands, with no extra script tag on each site
Run code before airgap.js startsSet a load option or register a request override for all sites
Send consent to your own systemsPost each consent change to your own API
Apply your own rule when two consent records disagreeCompare the browser record with the account record after login

If only one site needs the logic, a script tag placed before the airgap.js script tag does the same job. See Airgap Pre-init Configuration.

How a script reaches your sites

  1. Tell your Transcend representative what the script must do. You can send your own JavaScript or TypeScript as a starting point.
  2. Transcend releases the script as a numbered version. Each version has a changelog entry.
  3. Transcend attaches that version to your bundle. If the script takes configuration, Transcend sets its values at this step.
  4. Publish the bundle. In the Admin Dashboard, select Review Changes & Publish..., pick the bundle type, and then select Deploy Changes. For bundles that use scripts, the review step has a Scripts tab. It lists the catalog, name, version, and Config of each script.
  5. Every site that loads that bundle now runs the script. You do not change any script tag.

To test first, deploy to the Test bundle. See Testing with Test Bundle.

A later change to the script follows the same steps. Transcend releases a new version, attaches it to your bundle, and you publish again.

Names, versions, and configuration

PartWhat it means
CatalogA script is either general, which any organization can use, or specific to your organization.
NameEach script has a name. A bundle can carry more than one script.
VersionA bundle is pinned to one version of each script. A new release does not change your bundle until it is attached.
ConfigA script can define configuration. Transcend checks the values against the script schema when it attaches it.

What a script can do

A script runs in the page, in the same file as airgap.js. Transcend wraps each script in its own function so its variables do not leak to the page.

WhenWhat the script can do
Before airgap.js startsSet load options, register request overrides and cookie overrides, and queue a callback for when airgap.js is ready.
After airgap.js is readyCall the airgap.js API: airgap.getConsent(), airgap.setConsent(), airgap.sync(), and airgap.addEventListener().

A script can listen for consent-change, consent-resolution, and sync like any other code on the page.

airgap.setConsent() needs proof that the change is allowed. See Consent authorization. A script can use a user interaction event or the load event of the airgap.js script tag.

Example patterns Transcend can build

You do not author the released script yourself. These sketches show the kinds of logic Transcend can embed for you.

PatternBehavior
Consent webhookOn each consent-change event, POST the consent record to your API
Login-time consent reconciliationOn the airgap.js load event, fetch the account record, merge it with the browser record, then call setConsent()

Classify any domains your script calls in your data flows so airgap.js allows those requests. See Unknown Request Policy.

Limits

  • An error can stop airgap.js. The script and airgap.js are one bundle. An error that Transcend does not catch at the top level stops the rest of the bundle.
  • The code is public. Anyone can read the script in the bundle. Do not put secrets in a script or in its configuration.
  • The script adds to the bundle size. Every visitor downloads it with airgap.js.
  • Each change needs a release. Transcend releases the new version, and you publish the bundle.

On this page