C15T Logo

Script Loader

Load scripts based on consent. Used to load scripts that are not necessary for the user's consent, such as analytics scripts.

Canary Feature

This feature is available in canary releases and may have breaking changes. Use with caution in production. Report issues on GitHub

Info

When using the Script Loader, the tracking blocker will be disabled automatically (If enabled). This is because the tracking blocker is deprecated and may cause conflicts with the script loader. The current approach of the tracking blocker will only be available in v1.x of c15t, and will be removed in v2.0.

Overview

c15t provides the ability to load and unload scripts based on consent. This is useful for loading scripts that are not necessary for the user's consent, such as analytics scripts.

One common flaw of CMPs is they'll maintain a list of scripts that are blocked and then unblocked based on consent. This is a problem because it's not always accurate and can lead to scripts being missed or incorrectly blocked.

Our approach gives you, the developer, full control over the scripts that are loaded and unloaded, as no one knows your site better than you do.

Prebuilt Scripts

A lot of scripts you may need to implement may be common, such as Google Tag Manager (GTM), PostHog, Meta Pixel, etc. To save you time, we have provided a set of prebuilt scripts for you to use.

These scripts are available in the @c15t/scripts package.

All Prebuilt Scripts

ScriptGuide
Google Tag ManagerGuide
Meta PixelGuide
PostHogGuide
TikTok PixelGuide
LinkedIn InsightsGuide
Microsoft UETGuide
X PixelGuide

Always Load Scripts

Some tracking scripts, like Google Tag Manager or PostHog, manage their own consent state internally. For these scripts, you'll want them to load immediately and never be unloaded, regardless of the consent state in c15t.

The alwaysLoad property allows you to bypass consent checks and ensure these scripts are always present on the page.

When to Use Always Load

Use alwaysLoad: true for:

  • Tag Management Systems (e.g., Google Tag Manager) that handle consent internally
  • Analytics Platforms (e.g., PostHog) with built-in consent management & cookieless behavior
  • Scripts that must initialize early and configure themselves based on consent

Info

When using alwaysLoad, you are responsible for ensuring the script respects user consent through its own consent management API. The script will load regardless of the user's consent choices in c15t.

Behavior

Scripts with alwaysLoad: true have the following characteristics:

  • Load immediately when the consent manager initializes, bypassing consent checks
  • Never unload when consent is revoked or changed
  • Persist through clearAllScripts calls
  • Still trigger callbacks like onBeforeLoad, onLoad, and onConsentChange

Script

Property
Types