( function () {
	'use strict';

	var config = window.carticyConversionsTracking || {};
	var dataLayerName = config.dataLayerName || 'dataLayer';
	var sentStorageKey = config.dedupStorageKey || 'carticy_conversions_client_sent_v1';
	var SENT_TTL_MS = 48 * 3600000;
	var SYNTHETIC_WINDOW_MS = 15000;
	var loaded = {};
	var googleConfigured = {};
	var queued = [];
	var recentSynthetic = {};
	var initialized = false;
	var existingGtag = typeof window.gtag === 'function';
	var existingFbq = typeof window.fbq === 'function';
	var existingGoogleTagScript = false;
	var existingMetaScript = false;
	var existingGtmScript = false;

	window[ dataLayerName ] = window[ dataLayerName ] || [];

	function gtag() {
		window[ dataLayerName ].push( arguments );
	}

	// Do NOT push a consent default at parse time: on a store with a foreign
	// gtag (another plugin / hardcoded tag) that would inject a late
	// "default: denied" into the merchant's existing setup and degrade THEIR
	// collection. The default-deny is applied just before OUR tag bootstraps
	// (ensureGoogleTag), which is still before our gtag.js processes any
	// command.
	window.gtag = window.gtag || gtag;
	window.gtag.carticyConversionsStub = ! existingGtag;

	function applyGoogleConsentDefault() {
		if ( googleConfigured.consentDefault ) {
			return;
		}
		googleConfigured.consentDefault = true;
		window.gtag( 'consent', 'default', {
			ad_storage: 'denied',
			ad_user_data: 'denied',
			ad_personalization: 'denied',
			analytics_storage: 'denied'
		} );
	}

	function providerConfig( provider ) {
		return ( config.providers && config.providers[ provider ] ) || {};
	}

	function providerModeIncludes( provider, mode ) {
		var providerSettings = providerConfig( provider );
		return true === providerSettings.enabled && ( providerSettings.mode === mode || providerSettings.mode === 'both' );
	}

	function serviceKey( provider ) {
		if ( provider === 'google_ads' ) {
			return 'google-ads';
		}
		return provider;
	}

	function consentAllows( provider, event ) {
		var consent = ( event && event.consent ) || {};
		var services = consent.services || {};
		var key = serviceKey( provider );

		// The CURRENT browser consent intersects the event's consent
		// snapshot, deny-dominant: a server-hydrated purchase carries the
		// order's captured (granted) record, but if the visitor's live
		// consent explicitly denies this provider, loading its tag now would
		// ignore an active refusal. An unset live state does not override
		// the captured order decision.
		if ( browserConsentDenies( provider ) ) {
			return false;
		}

		if ( services[ key ] ) {
			return services[ key ] === 'granted';
		}

		return consent.state === 'granted';
	}

	function browserConsentDenies( provider ) {
		var consent = config.currentConsent || {};
		var services = consent.services || {};
		var key = serviceKey( provider );

		if ( services[ key ] ) {
			return services[ key ] === 'denied';
		}

		return consent.state === 'denied';
	}

	function consentUndecided( provider, event ) {
		var consent = ( event && event.consent ) || {};
		var services = consent.services || {};
		var key = serviceKey( provider );
		var state = services[ key ] || consent.state || 'unset';
		return state !== 'granted' && state !== 'denied';
	}

	function scriptExists( needle ) {
		var scripts;
		var i;
		if ( ! document.querySelectorAll ) {
			return false;
		}
		scripts = document.querySelectorAll( 'script[src]' );
		for ( i = 0; i < scripts.length; i++ ) {
			if ( String( scripts[i].src || '' ).indexOf( needle ) !== -1 ) {
				return true;
			}
		}
		return false;
	}

	function foreignScriptExists( needle, ownId ) {
		var scripts;
		var i;
		if ( ! document.querySelectorAll ) {
			return false;
		}
		scripts = document.querySelectorAll( 'script[src]' );
		for ( i = 0; i < scripts.length; i++ ) {
			if ( String( scripts[i].src || '' ).indexOf( needle ) !== -1 && scripts[i].id !== ownId ) {
				return true;
			}
		}
		return false;
	}

	existingGoogleTagScript = scriptExists( 'googletagmanager.com/gtag/js' );
	existingMetaScript = scriptExists( 'connect.facebook.net' );
	existingGtmScript = foreignScriptExists( 'googletagmanager.com/gtm.js', 'carticy-conversions-gtm' );

	// Scan the dataLayer for foreign gtag config commands so Google Ads
	// conflicts are detected separately from GA4: a site with another
	// plugin's GA4 tag must not silently lose Carticy's Ads conversions.
	function foreignGoogleConfigPresent( prefix, ownIds ) {
		var entries = window[ dataLayerName ] || [];
		var i;
		var entry;
		var id;
		for ( i = 0; i < entries.length; i++ ) {
			entry = entries[ i ];
			if ( ! entry || 'config' !== entry[0] || 'string' !== typeof entry[1] ) {
				continue;
			}
			id = entry[1];
			if ( 0 === id.indexOf( prefix ) && -1 === ownIds.indexOf( id ) ) {
				return true;
			}
		}
		return false;
	}

	function ownGoogleIds() {
		var ids = [];
		var ga4 = providerConfig( 'ga4' );
		var ads = providerConfig( 'google_ads' );
		if ( ga4.measurementId ) {
			ids.push( ga4.measurementId );
		}
		if ( ads.conversionId ) {
			ids.push( ads.conversionId );
		}
		return ids;
	}

	function recordConflict( provider, type ) {
		var conflict = { provider: provider, type: type };
		window.carticyConversionsTrackingConflicts = window.carticyConversionsTrackingConflicts || [];
		if ( ! window.carticyConversionsTrackingConflicts.some( function ( item ) {
			return item.provider === provider && item.type === type;
		} ) ) {
			window.carticyConversionsTrackingConflicts.push( conflict );
			window[ dataLayerName ].push( Object.assign( { event: 'carticy_tracking_conflict' }, conflict ) );
		}
	}

	function foreignDirectTagPresent( provider ) {
		if ( config.allowDuplicateClientDestinations ) {
			return false;
		}
		if ( provider === 'meta' ) {
			return existingFbq || existingMetaScript;
		}
		if ( provider === 'ga4' ) {
			return existingGtag || existingGoogleTagScript;
		}
		if ( provider === 'google_ads' ) {
			// Suppress Ads only on evidence of a foreign Ads conversion setup
			// (an AW- config we did not create); a foreign GA4-only tag must
			// not cost the merchant their Ads conversions.
			return ( existingGtag || existingGoogleTagScript ) && foreignGoogleConfigPresent( 'AW-', ownGoogleIds() );
		}
		return false;
	}

	function shouldSuppressForeignDirect( provider ) {
		if ( ! foreignDirectTagPresent( provider ) ) {
			return false;
		}
		recordConflict( provider, 'foreign_direct_tag' );
		return true;
	}

	function readCookie( name ) {
		var match = document.cookie && document.cookie.match( new RegExp( '(?:^|; )' + name.replace( /([.$?*|{}()[\]\\/+^])/g, '\\$1' ) + '=([^;]*)' ) );
		if ( ! match ) {
			return '';
		}
		try {
			return decodeURIComponent( match[1] );
		} catch ( error ) {
			return match[1];
		}
	}

	// Mirrors the server-side resolver: take the LATEST reading per
	// source+scope first, then apply deny-dominance across sources. Without
	// the latest-per-source step, one stale "denied" entry would latch the
	// shopper to denied even after they explicitly granted.
	function resolveConsentSignals() {
		var signals;
		var latest = {};
		var granted = false;
		var denied = false;
		var services = {};
		var raw = readCookie( 'carticy_conversions_consent_signals' );
		if ( ! raw ) {
			return config.currentConsent || { state: 'unset', services: {} };
		}
		try {
			signals = JSON.parse( raw );
		} catch ( error ) {
			return { state: 'unset', services: {} };
		}
		if ( ! Array.isArray( signals ) ) {
			return { state: 'unset', services: {} };
		}
		signals.forEach( function ( signal ) {
			var key;
			if ( ! signal || signal.is_explicit !== true ) {
				return;
			}
			key = ( signal.source || '' ) + '|' + ( signal.source_version || '' ) + '|'
				+ Object.keys( signal.categories || {} ).sort().join( ',' );
			latest[ key ] = signal; // Array order is push order: last wins.
		} );
		Object.keys( latest ).forEach( function ( key ) {
			var signal = latest[ key ];
			Object.keys( signal.services || {} ).forEach( function ( service ) {
				if ( services[ service ] !== 'denied' ) {
					services[ service ] = signal.services[ service ];
				}
			} );
			if ( signal.state === 'denied' ) {
				denied = true;
			} else if ( signal.state === 'granted' ) {
				granted = true;
			}
		} );
		if ( denied || Object.keys( services ).some( function ( key ) { return services[ key ] === 'denied'; } ) ) {
			return { state: 'denied', services: services };
		}
		return granted ? { state: 'granted', services: services } : { state: 'unset', services: services };
	}

	function currentConsent() {
		config.currentConsent = resolveConsentSignals();
		return config.currentConsent;
	}

	function loadScript( id, src ) {
		var script;
		if ( loaded[ id ] || document.getElementById( id ) ) {
			loaded[ id ] = true;
			return;
		}
		script = document.createElement( 'script' );
		script.id = id;
		script.src = src;
		script.async = true;
		script.defer = true;
		script.setAttribute( 'data-cfasync', 'false' );
		( document.head || document.documentElement ).appendChild( script );
		loaded[ id ] = true;
	}

	function loadGtm() {
		var gtm = config.gtm || {};
		if ( ! gtm.enabled || ! gtm.containerId ) {
			return;
		}
		// Never inject a second container next to a foreign one. dataLayer pushes
		// remain observable by the existing container while the admin UI surfaces
		// the duplicate-container conflict for merchant cleanup.
		if ( existingGtmScript ) {
			recordConflict( 'gtm', 'foreign_container' );
			return;
		}
		window[ dataLayerName ].push( { 'gtm.start': Date.now(), event: 'gtm.js' } );
		loadScript( 'carticy-conversions-gtm', 'https://www.googletagmanager.com/gtm.js?id=' + encodeURIComponent( gtm.containerId ) + ( dataLayerName !== 'dataLayer' ? '&l=' + encodeURIComponent( dataLayerName ) : '' ) );
	}

	function ensureGoogleTag( tagId ) {
		if ( ! tagId ) {
			return;
		}
		applyGoogleConsentDefault();
		loadScript( 'carticy-conversions-google-tag', 'https://www.googletagmanager.com/gtag/js?id=' + encodeURIComponent( tagId ) );
		if ( ! googleConfigured.js ) {
			window.gtag( 'js', new Date() );
			googleConfigured.js = true;
		}
		if ( ! googleConfigured[ tagId ] ) {
			window.gtag( 'config', tagId, { send_page_view: false } );
			googleConfigured[ tagId ] = true;
		}
	}

	function grantGoogleConsentFor( event ) {
		var update = {
			analytics_storage: 'denied',
			ad_storage: 'denied',
			ad_user_data: 'denied',
			ad_personalization: 'denied'
		};
		if ( consentAllows( 'ga4', event ) ) {
			update.analytics_storage = 'granted';
		}
		if ( consentAllows( 'google_ads', event ) ) {
			update.ad_storage = 'granted';
			update.ad_user_data = 'granted';
			update.ad_personalization = 'granted';
		}
		window.gtag( 'consent', 'update', update );
	}

	function ensureGa4( event ) {
		var ga4 = providerConfig( 'ga4' );
		if ( ! ga4.measurementId ) {
			return;
		}
		ensureGoogleTag( ga4.measurementId );
		grantGoogleConsentFor( event );
	}

	function ensureGoogleAds( event ) {
		var ads = providerConfig( 'google_ads' );
		if ( ! ads.conversionId ) {
			return;
		}
		ensureGoogleTag( ads.conversionId );
		grantGoogleConsentFor( event );
	}

	function ensureMeta() {
		var meta = providerConfig( 'meta' );
		if ( ! meta.pixelId || window.fbq && window.fbq.carticyConversionsInit ) {
			return;
		}
		if ( ! window.fbq ) {
			window.fbq = function () {
				window.fbq.callMethod ? window.fbq.callMethod.apply( window.fbq, arguments ) : window.fbq.queue.push( arguments );
			};
			window.fbq.queue = [];
			window.fbq.loaded = true;
			window.fbq.version = '2.0';
			window._fbq = window.fbq;
		}
		loadScript( 'carticy-conversions-meta', 'https://connect.facebook.net/en_US/fbevents.js' );
		window.fbq( 'init', meta.pixelId );
		window.fbq.carticyConversionsInit = true;
	}

	function readSent() {
		try {
			return JSON.parse( window.localStorage.getItem( sentStorageKey ) || '{}' );
		} catch ( error ) {
			return {};
		}
	}

	function wasSent( event, destination ) {
		var sent = readSent();
		return Boolean( sent[ event.event_id + '|' + destination ] );
	}

	function markSent( event, destination ) {
		var sent = readSent();
		var now = Date.now();
		// Prune expired entries so the dedup store cannot grow without bound:
		// reload dedup only needs the platforms' own dedup windows (~48h).
		Object.keys( sent ).forEach( function ( key ) {
			if ( 'number' !== typeof sent[ key ] || now - sent[ key ] > SENT_TTL_MS ) {
				delete sent[ key ];
			}
		} );
		sent[ event.event_id + '|' + destination ] = now;
		try {
			window.localStorage.setItem( sentStorageKey, JSON.stringify( sent ) );
		} catch ( error ) {}
	}

	function providerParams( event ) {
		return {
			value: event.value,
			currency: event.currency,
			transaction_id: event.transaction_id,
			event_id: event.event_id,
			items: event.items || [],
			content_ids: event.content_ids || [],
			content_type: event.content_type || 'product'
		};
	}

	function metaEventName( eventName ) {
		if ( eventName === 'purchase' ) {
			return 'Purchase';
		}
		if ( eventName === 'add_to_cart' ) {
			return 'AddToCart';
		}
		if ( eventName === 'begin_checkout' ) {
			return 'InitiateCheckout';
		}
		return eventName;
	}

	function sendDataLayer( event ) {
		if ( wasSent( event, 'gtm' ) ) {
			return;
		}
		window[ dataLayerName ].push( Object.assign( {}, event ) );
		markSent( event, 'gtm' );
	}

	function sendGa4( event ) {
		if ( ! providerModeIncludes( 'ga4', 'direct' ) || ! consentAllows( 'ga4', event ) || wasSent( event, 'ga4' ) ) {
			return;
		}
		if ( shouldSuppressForeignDirect( 'ga4' ) ) {
			return;
		}
		ensureGa4( event );
		window.gtag( 'event', event.event, providerParams( event ) );
		markSent( event, 'ga4' );
	}

	function sendGoogleAds( event ) {
		var ads = providerConfig( 'google_ads' );
		var params;
		// The configured conversion id/label represent a PURCHASE conversion
		// action; firing it for funnel events (begin_checkout, add_to_cart)
		// would inflate the merchant's Ads conversion counts.
		if ( event.event !== 'purchase' ) {
			return;
		}
		if ( ! providerModeIncludes( 'google_ads', 'direct' ) || ! consentAllows( 'google_ads', event ) || wasSent( event, 'google_ads' ) ) {
			return;
		}
		if ( shouldSuppressForeignDirect( 'google_ads' ) ) {
			return;
		}
		ensureGoogleAds( event );
		params = providerParams( event );
		params.send_to = ads.conversionId + '/' + ads.conversionLabel;
		window.gtag( 'event', 'conversion', params );
		markSent( event, 'google_ads' );
	}

	function sendMeta( event ) {
		var params;
		if ( ! providerModeIncludes( 'meta', 'direct' ) || ! consentAllows( 'meta', event ) || wasSent( event, 'meta' ) ) {
			return;
		}
		if ( shouldSuppressForeignDirect( 'meta' ) ) {
			return;
		}
		ensureMeta();
		params = {
			value: event.value,
			currency: event.currency,
			content_ids: event.content_ids || [],
			content_type: event.content_type || 'product'
		};
		window.fbq( 'track', metaEventName( event.event ), params, event.event_id ? { eventID: event.event_id } : undefined );
		markSent( event, 'meta' );
	}

	function anyGtmProviderAllowed( event ) {
		return [ 'ga4', 'google_ads', 'meta' ].some( function ( provider ) {
			return providerModeIncludes( provider, 'gtm' ) && consentAllows( provider, event );
		} );
	}

	function anyDirectProviderAllowed( event ) {
		return [ 'ga4', 'google_ads', 'meta' ].some( function ( provider ) {
			return providerModeIncludes( provider, 'direct' ) && consentAllows( provider, event );
		} );
	}

	function eventCanDispatch( event ) {
		return Boolean( event && event.consent && ( anyGtmProviderAllowed( event ) || anyDirectProviderAllowed( event ) ) );
	}

	// A provider with an UNDECIDED (unset) consent state may still resolve to
	// granted later in this page view; such an event stays queued so a
	// per-service grant can replay it. Denied providers are settled.
	function eventHasUndecidedProvider( event ) {
		return [ 'ga4', 'google_ads', 'meta' ].some( function ( provider ) {
			if ( ! providerModeIncludes( provider, 'direct' ) && ! providerModeIncludes( provider, 'gtm' ) ) {
				return false;
			}
			return consentUndecided( provider, event );
		} );
	}

	function dispatch( event ) {
		if ( ! event || ! event.event || ! event.event_id ) {
			return;
		}
		if ( anyGtmProviderAllowed( event ) ) {
			loadGtm();
			sendDataLayer( event );
		}
		sendGa4( event );
		sendGoogleAds( event );
		sendMeta( event );
	}

	function processQueue() {
		var pending = queued.slice();
		queued = [];
		pending.forEach( function ( event ) {
			if ( eventCanDispatch( event ) ) {
				dispatch( event );
				// Keep partially-dispatched events queued while any enabled
				// provider is still undecided; wasSent() prevents resends.
				if ( eventHasUndecidedProvider( event ) ) {
					queued.push( event );
				}
			} else if ( eventHasUndecidedProvider( event ) || ! event.consent || event.consent.state !== 'denied' ) {
				queued.push( event );
			}
		} );
	}

	function queueOrDispatch( event ) {
		if ( eventCanDispatch( event ) ) {
			dispatch( event );
			if ( eventHasUndecidedProvider( event ) ) {
				queued.push( event );
			}
			return;
		}
		queued.push( event );
	}

	function syntheticEvent( name, payload ) {
		var now = String( Date.now() );
		return Object.assign( {
			event: name,
			event_id: name + '_' + now,
			transaction_id: name + '_' + now,
			value: 0,
			currency: ( config.context && config.context.currency ) || '',
			items: [],
			content_ids: [],
			content_type: 'product',
			consent: currentConsent()
		}, payload || {} );
	}

	// One physical user action can surface through more than one DOM signal
	// (optimistic click + WooCommerce's added_to_cart); a short window keyed
	// on event name + product collapses them to one tracked event.
	function recentlyEmitted( name, productId ) {
		var key = name + '|' + ( productId || '' );
		var now = Date.now();
		if ( recentSynthetic[ key ] && now - recentSynthetic[ key ] < SYNTHETIC_WINDOW_MS ) {
			return true;
		}
		recentSynthetic[ key ] = now;
		return false;
	}

	function productFromButton( button ) {
		var now = Date.now();
		var productId = button.getAttribute( 'data-product_id' ) || button.getAttribute( 'value' ) || '';
		var sku = button.getAttribute( 'data-product_sku' ) || '';
		var price = parseFloat( button.getAttribute( 'data-carticy-price' ) || '0' );
		var name = button.getAttribute( 'data-carticy-name' ) || '';
		var currency = button.getAttribute( 'data-carticy-currency' ) || ( config.context && config.context.currency ) || '';
		return {
			event: 'add_to_cart',
			event_id: 'add_to_cart_' + productId + '_' + now,
			transaction_id: 'add_to_cart_' + productId + '_' + now,
			value: price || 0,
			currency: currency,
			items: [ { item_id: productId, item_name: name, item_sku: sku, quantity: 1, price: price || 0 } ],
			content_ids: productId ? [ productId ] : []
		};
	}

	function emitAddToCart( payload, productId ) {
		if ( recentlyEmitted( 'add_to_cart', productId ) ) {
			return;
		}
		queueOrDispatch( syntheticEvent( 'add_to_cart', payload ) );
	}

	function singleProductPayload( form ) {
		var input = form.querySelector( 'input[name="add-to-cart"], button[name="add-to-cart"]' );
		var dataNode = form.querySelector( '.carticy-conversions-product-data' );
		var productId = input ? String( input.value || '' ) : '';
		var price = dataNode ? parseFloat( dataNode.getAttribute( 'data-carticy-price' ) || '0' ) : 0;
		var name = dataNode ? dataNode.getAttribute( 'data-carticy-name' ) || '' : '';
		var quantityInput = form.querySelector( 'input.qty, input[name="quantity"]' );
		var quantity = quantityInput ? parseInt( quantityInput.value, 10 ) || 1 : 1;
		var now = Date.now();
		if ( ! productId ) {
			return null;
		}
		return {
			event: 'add_to_cart',
			event_id: 'add_to_cart_' + productId + '_' + now,
			transaction_id: 'add_to_cart_' + productId + '_' + now,
			value: ( price || 0 ) * quantity,
			currency: ( dataNode && dataNode.getAttribute( 'data-carticy-currency' ) ) || ( config.context && config.context.currency ) || '',
			items: [ { item_id: productId, item_name: name, quantity: quantity, price: price || 0 } ],
			content_ids: [ productId ],
			_productId: productId
		};
	}

	function beginCheckoutEvent() {
		var cart = ( config.context && config.context.cart ) || {};
		var hash = cart.hash || 'nohash';
		var eventId = 'begin_checkout_' + hash;
		var items = Array.isArray( cart.items ) ? cart.items.map( function ( item ) {
			return { item_id: String( item.id || '' ), quantity: item.quantity || 1, price: item.price || 0 };
		} ) : [];
		return syntheticEvent( 'begin_checkout', {
			// Cart-hash-keyed id: a checkout-page refresh with the same cart
			// must not re-fire begin_checkout (localStorage dedup catches it).
			event_id: eventId,
			transaction_id: eventId,
			value: cart.value || 0,
			items: items,
			content_ids: items.map( function ( item ) { return item.item_id; } ).filter( Boolean )
		} );
	}

	function bindWooEvents() {
		// Optimistic click capture is the fallback for themes without the
		// added_to_cart event; the recentlyEmitted() window collapses the
		// double signal on standard themes.
		document.addEventListener( 'click', function ( event ) {
			var button = event.target && event.target.closest ? event.target.closest( '.add_to_cart_button[data-product_id]' ) : null;
			if ( button ) {
				emitAddToCart( productFromButton( button ), button.getAttribute( 'data-product_id' ) );
			}
		}, true );

		// Single product page (non-AJAX form submit).
		document.addEventListener( 'submit', function ( event ) {
			var form = event.target;
			var payload;
			if ( ! form || ! form.classList || ! form.classList.contains( 'cart' ) || ! form.querySelector ) {
				return;
			}
			payload = singleProductPayload( form );
			if ( payload ) {
				emitAddToCart( payload, payload._productId );
			}
		}, true );

		document.body && document.body.addEventListener( 'wc-blocks_added_to_cart', function ( event ) {
			emitAddToCart( ( event && event.detail ) || {}, 'wc-blocks' );
		} );

		if ( window.jQuery && window.jQuery.fn && window.jQuery( document.body ).on ) {
			window.jQuery( document.body ).on( 'added_to_cart', function ( jqEvent, fragments, cartHash, button ) {
				var nativeButton = button && button[0] ? button[0] : null;
				var payload = nativeButton ? productFromButton( nativeButton ) : {};
				emitAddToCart( payload, nativeButton ? nativeButton.getAttribute( 'data-product_id' ) : '' );
			} );
		}

		if ( config.context && config.context.isCheckout && ! config.context.isOrderReceived ) {
			queueOrDispatch( beginCheckoutEvent() );
		}
	}

	function updateConsent( consent ) {
		config.currentConsent = Object.assign( {}, config.currentConsent || {}, consent || {} );
		queued = queued.map( function ( event ) {
			event.consent = Object.assign( {}, event.consent || {}, consent || {} );
			return event;
		} );
		processQueue();
	}

	// Same-page consent replay rides the capture script's DOM event, which
	// fires for every bus push regardless of script load order - wrapping the
	// bus function was load-order-fragile (the capture script reassigns it).
	function bindConsentBus() {
		document.addEventListener( 'carticy_conversions_consent_signal', function () {
			updateConsent( currentConsent() );
		} );
	}

	window.carticyConversionsTrackingApi = {
		pushEvent: queueOrDispatch,
		updateConsent: updateConsent,
		getQueueLength: function () {
			return queued.length;
		}
	};

	function init() {
		if ( initialized || ! config.enabled ) {
			return;
		}
		initialized = true;
		bindConsentBus();
		config.currentConsent = currentConsent();
		( config.events || [] ).forEach( queueOrDispatch );
		bindWooEvents();
	}

	if ( document.readyState === 'loading' ) {
		document.addEventListener( 'DOMContentLoaded', init );
	} else {
		init();
	}
}() );
