c15t
Version:
<div align="center"> <img src="https://c15t.com/logo-icon.png" alt="c15t Logo" width="64" height="64" /> <h1>c15t</h1> <p>Transform privacy consent from a compliance checkbox into a fully observable system</p>
93 lines • 2.99 kB
TypeScript
import type { ConsentState } from '../types';
/**
* GTM-specific consent configuration matching Google's consent mode API
*/
interface GTMConsentConfiguration {
ad_storage: 'granted' | 'denied';
ad_personalization: 'granted' | 'denied';
ad_user_data: 'granted' | 'denied';
analytics_storage: 'granted' | 'denied';
personalization_storage: 'granted' | 'denied';
functionality_storage: 'granted' | 'denied';
security_storage: 'granted' | 'denied';
}
interface Options {
/**
* Your Google Tag Manager container ID. Begins with 'GTM-'.
*/
id: string;
/**
* Custom URL for your GTM script. Include the 'id' parameter.
*
* @default `https://www.googletagmanager.com/gtm.js?id=${id}`
*
* @example
* ```ts
* https://www.c15t.dev/gtm.js?id=GTM-XXXXXXX
* ```
*/
customScriptUrl?: string;
/**
* The consent state to use for the GTM consent configuration.
*/
consentState?: ConsentState;
}
export type GTMConfiguration = Omit<Options, 'consentState'>;
/**
* Extended Window interface to include GTM-specific properties
*/
declare global {
interface Window {
dataLayer: unknown[];
gtag: (...args: unknown[]) => void;
}
}
/**
* Converts ConsentState to GTM consent configuration
*
* @param consentState - The application's consent state
* @returns GTM-compatible consent configuration
*
* @see {@link CONSENT_STATE_TO_GTM_MAPPING} for the mapping logic
*/
export declare function mapConsentStateToGTM(consentState: ConsentState): GTMConsentConfiguration;
/**
* Initializes the Google Tag Manager dataLayer and consent configuration
*
* @param configuration - GTM setup configuration options
*
* @throws {Error} When GTM container ID is empty or invalid
*
* @internal This function should be called before loading the GTM script
*/
export declare function initializeGTMDataLayer(gtm: Options): void;
/**
* Creates and injects the Google Tag Manager script into the document head
*
* @param gtmContainerId - The GTM container ID (e.g., 'GTM-XXXXXXX')
*
* @throws {Error} When script injection fails
*
* @see {@link initializeGTMDataLayer} - Should be called before this function
*/
export declare function createGTMScript(gtm: Options): void;
/**
* Complete Google Tag Manager setup including dataLayer initialization and script injection
*
* @param configuration - Complete GTM configuration options
*
* @throws {Error} When GTM container ID is empty or invalid
* @throws {Error} When script injection fails
*
* @see {@link initializeGTMDataLayer} - For dataLayer setup only
* @see {@link createGTMScript} - For script injection only
*/
export declare function setupGTM(gtm: Options): void;
/**
* Updates the Google Tag Manager consent configuration
*
* @param consentState - The consent state to update
*/
export declare function updateGTMConsent(consentState: ConsentState): void;
export {};
//# sourceMappingURL=gtm.d.ts.map