react-cookie-manager
Version:
🍪 The ultimate React cookie consent solution. Automatically block trackers, manage consent preferences, and protect user privacy with an elegant UI. Perfect for modern web applications.
47 lines • 2.32 kB
TypeScript
import { CookieCategories } from '../types/types';
/**
* The Google Consent Mode v2 signals this library can manage.
* @see https://developers.google.com/tag-platform/security/guides/consent
*/
export type GoogleConsentSignal = "ad_storage" | "analytics_storage" | "ad_user_data" | "ad_personalization" | "personalization_storage" | "functionality_storage" | "security_storage";
export type GoogleConsentValue = "granted" | "denied";
export interface GoogleConsentModeOptions {
/**
* Override how cookie categories map to Google consent signals. For each
* signal you can point to a category (`"Analytics" | "Social" | "Advertising"`)
* or pin it to a static `"granted"`/`"denied"`. Anything omitted uses the
* default mapping.
*/
mapping?: Partial<Record<GoogleConsentSignal, keyof CookieCategories | GoogleConsentValue>>;
/**
* Override the pre-consent default state for individual signals. By default
* every signal is `denied` except `functionality_storage`/`security_storage`.
*/
defaults?: Partial<Record<GoogleConsentSignal, GoogleConsentValue>>;
/**
* Milliseconds Google should wait for an `update` before sending pings with
* the default state. Passed as `wait_for_update`.
* @default 500
*/
waitForUpdate?: number;
/** Enable `gtag('set', 'url_passthrough', true)`. */
urlPassthrough?: boolean;
/** Enable `gtag('set', 'ads_data_redaction', true)`. */
adsDataRedaction?: boolean;
}
/**
* Maps consent preferences to a Google Consent Mode v2 signal object.
* Pure and SSR-safe — this is the unit-testable core of the integration.
*/
export declare const mapConsentToSignals: (prefs: CookieCategories, options?: GoogleConsentModeOptions) => Record<GoogleConsentSignal, GoogleConsentValue>;
/**
* Emits the pre-consent default consent state via
* `gtag('consent', 'default', {...})`. No-op on the server.
*/
export declare const setGoogleConsentDefault: (options?: GoogleConsentModeOptions) => void;
/**
* Emits an updated consent state via `gtag('consent', 'update', {...})`
* based on the given preferences. No-op on the server.
*/
export declare const updateGoogleConsent: (prefs: CookieCategories, options?: GoogleConsentModeOptions) => void;
//# sourceMappingURL=google-consent-mode.d.ts.map