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
Scriptfor one-off app code. - Use a manifest-backed helper in
@c15t/scriptsfor 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:
Consent Conditions
The category field accepts a HasCondition - either a simple string or a logical expression:
Script Callbacks
Every script supports four lifecycle callbacks:
| Callback | When | Use Case |
|---|---|---|
onBeforeLoad | Before the script tag is injected | Set up global variables |
onLoad | Script loaded successfully | Initialize the library |
onError | Script failed to load | Log error, load fallback |
onConsentChange | Consent 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():