Script Loader

The script loader manages third-party scripts based on consent state. Scripts are defined in the provider's scripts option and are automatically loaded when their required consent category is granted, and unloaded when consent is revoked.

c15t has a collection of premade scripts available in @c15t/scripts. Check the integrations overview first before manually building a script.

Info

We recommend using the pre-built integrations when possible.

Info

If you need a vendor we do not ship yet, see the custom integration guide. It covers both one-off Script objects and reusable manifest-backed integrations.

Info

For app-specific scripts, use a plain Script object. For reusable integrations, prefer a manifest-backed helper so startup phases, consent signaling, and future server-side loading support stay structured.

Basic Usage

Pass an array of Script objects to the provider:

Choose the Right Approach

  • Use a plain Script for one-off app code.
  • Use a manifest-backed helper in @c15t/scripts for reusable integrations, contributions, or anything that needs structured startup behavior.

If you are building something reusable, start with the custom integration guide before using raw callbacks.

Reusable Integrations

For app-specific use, raw Script objects are usually enough.

For reusable integrations, c15t uses a manifest-backed model in @c15t/scripts. That keeps startup phases, consent signaling, and vendor-specific boot logic structured instead of hidden inside large callback bodies.

If you are building an integration for multiple apps or contributing upstream, use the custom integration guide.

Script Types

Standard Scripts

Load an external JavaScript file via a <script> tag. Use src to specify the URL.

Inline Scripts

Execute inline JavaScript code. Use textContent instead of src:

Callback-Only Scripts

Don't inject any <script> tag - just execute callbacks based on consent changes. Useful for controlling libraries that are already loaded:

The category field accepts a HasCondition - either a simple string or a logical expression:

Script Callbacks

Every script supports four lifecycle callbacks:

CallbackWhenUse Case
onBeforeLoadBefore the script tag is injectedSet up global variables
onLoadScript loaded successfullyInitialize the library
onErrorScript failed to loadLog error, load fallback
onConsentChangeConsent state changed (script already loaded)Toggle tracking on/off

Advanced Options

Always Load

Scripts that manage their own consent internally (like GTM in consent mode):

Persist After Revocation

Keep the script loaded even after consent is revoked (the page won't reload for this script):

Script Placement

Control where in the DOM the script is injected:

Ad Blocker Evasion

Script element IDs are anonymized by default to avoid ad blocker pattern matching:

Dynamic Script Management

Add, remove, or check scripts at runtime via useConsentManager():

API Reference

Loading…