@bigz-app/booking-widget 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -10280,7 +10280,7 @@ function BookingForm({ config, eventDetails, stripePromise, onSuccess, onError,
10280
10280
  */
10281
10281
  /**
10282
10282
  * Check if Google Consent Mode has granted the necessary permissions for ads tracking
10283
- * This only checks Google's official consent mode - the proper way to handle Google Ads consent
10283
+ * This checks multiple sources of consent state in order of preference
10284
10284
  */
10285
10285
  function checkGoogleConsent() {
10286
10286
  console.log("[Google Ads Tracking] 🔍 Checking Google consent...");
@@ -10289,31 +10289,90 @@ function checkGoogleConsent() {
10289
10289
  return false;
10290
10290
  }
10291
10291
  console.log("[Google Ads Tracking] ✅ Window object available");
10292
- // Check for gtag consent mode
10293
- if (typeof window.gtag === "function") {
10294
- console.log("[Google Ads Tracking] gtag function found");
10295
- try {
10296
- // Try to get consent state from Google's consent mode
10297
- let consentGranted = false;
10298
- window.gtag("get", (consentState) => {
10299
- console.log("[Google Ads Tracking] 📋 Consent state received:", consentState);
10300
- // For Google Ads conversion tracking, we need ad_storage consent
10301
- consentGranted = consentState.ad_storage === "granted";
10302
- console.log("[Google Ads Tracking] 🔐 ad_storage consent:", consentState.ad_storage);
10303
- });
10304
- console.log("[Google Ads Tracking] 🎯 Final consent result:", consentGranted);
10305
- return consentGranted;
10292
+ // Method 1: Check dataLayer for consent_update events (most reliable)
10293
+ if (window.dataLayer && Array.isArray(window.dataLayer)) {
10294
+ console.log("[Google Ads Tracking] 🔍 Checking dataLayer for consent events...");
10295
+ const dataLayer = window.dataLayer;
10296
+ // Debug: Show the entire dataLayer contents
10297
+ console.log("[Google Ads Tracking] 🗂️ Complete dataLayer contents:", JSON.stringify(dataLayer, null, 2));
10298
+ console.log("[Google Ads Tracking] 📊 dataLayer length:", dataLayer.length);
10299
+ // Look for the most recent consent update in dataLayer
10300
+ let latestConsentState = null;
10301
+ const foundEvents = [];
10302
+ // Search backwards through dataLayer for most recent consent state
10303
+ for (let i = dataLayer.length - 1; i >= 0; i--) {
10304
+ const event = dataLayer[i];
10305
+ console.log(`[Google Ads Tracking] 🔍 Checking dataLayer[${i}]:`, event);
10306
+ if (event && typeof event === "object") {
10307
+ // Check for various consent event patterns
10308
+ if (event.event === "consent_update" || event.event === "default_consent") {
10309
+ console.log("[Google Ads Tracking] 📋 Found consent event:", event);
10310
+ foundEvents.push(event);
10311
+ if (event.consent_mode) {
10312
+ latestConsentState = event.consent_mode;
10313
+ break;
10314
+ }
10315
+ }
10316
+ // Also check for direct consent_mode properties
10317
+ if (event.consent_mode) {
10318
+ console.log("[Google Ads Tracking] 📋 Found consent_mode property:", event);
10319
+ foundEvents.push(event);
10320
+ latestConsentState = event.consent_mode;
10321
+ break;
10322
+ }
10323
+ }
10306
10324
  }
10307
- catch (error) {
10308
- console.warn("[Google Ads Tracking] ⚠️ Error checking gtag consent:", error);
10325
+ console.log("[Google Ads Tracking] 📋 All found consent events:", foundEvents);
10326
+ if (latestConsentState) {
10327
+ const adStorageGranted = latestConsentState.ad_storage === "granted";
10328
+ console.log("[Google Ads Tracking] 🔐 ad_storage from dataLayer:", latestConsentState.ad_storage);
10329
+ console.log("[Google Ads Tracking] 🎯 Consent result from dataLayer:", adStorageGranted);
10330
+ return adStorageGranted;
10331
+ }
10332
+ console.log("[Google Ads Tracking] ❌ No consent events found in dataLayer");
10333
+ }
10334
+ console.log("[Google Ads Tracking] ❌ dataLayer not found or not an array");
10335
+ // Method 2: Check for cookie-based consent (fallback for host implementation)
10336
+ console.log("[Google Ads Tracking] 🔍 Checking cookie-based consent...");
10337
+ try {
10338
+ // Debug: Show all cookies
10339
+ console.log("[Google Ads Tracking] 🍪 All cookies:", document.cookie);
10340
+ const allCookies = document.cookie.split(";").map((cookie) => cookie.trim());
10341
+ console.log("[Google Ads Tracking] 🍪 Parsed cookies:", allCookies);
10342
+ // Check for the host page's conversion tracking consent cookie
10343
+ const conversionTrackingCookie = document.cookie
10344
+ .split(";")
10345
+ .find((cookie) => cookie.trim().startsWith("conversionTrackingConsent="));
10346
+ if (conversionTrackingCookie) {
10347
+ const cookieValue = conversionTrackingCookie.split("=")[1];
10348
+ const isGranted = cookieValue === "true";
10349
+ console.log("[Google Ads Tracking] 🍪 Found conversionTrackingConsent cookie:", cookieValue);
10350
+ console.log("[Google Ads Tracking] 🎯 Consent result from cookie:", isGranted);
10351
+ return isGranted;
10352
+ }
10353
+ console.log("[Google Ads Tracking] ❌ conversionTrackingConsent cookie not found");
10354
+ // Also check for other potential cookie names
10355
+ const alternativeCookieNames = ["analyticsConsent", "ads_consent", "ad_storage"];
10356
+ for (const cookieName of alternativeCookieNames) {
10357
+ const alternativeCookie = allCookies.find((cookie) => cookie.startsWith(`${cookieName}=`));
10358
+ if (alternativeCookie) {
10359
+ console.log(`[Google Ads Tracking] 🍪 Found alternative cookie ${cookieName}:`, alternativeCookie);
10360
+ }
10309
10361
  }
10310
10362
  }
10363
+ catch (error) {
10364
+ console.warn("[Google Ads Tracking] ⚠️ Error checking cookies:", error);
10365
+ }
10366
+ // Method 3: Check if gtag exists but no consent state found
10367
+ if (typeof window.gtag === "function") {
10368
+ console.log("[Google Ads Tracking] ⚠️ gtag function exists but no consent state found");
10369
+ console.log("[Google Ads Tracking] 💡 This might indicate consent hasn't been set yet");
10370
+ }
10311
10371
  else {
10312
10372
  console.log("[Google Ads Tracking] ❌ gtag function not found");
10313
10373
  }
10314
- // If gtag is not available, we assume consent has not been properly configured
10315
- // The host page should implement Google Consent Mode if they want tracking
10316
- console.log("[Google Ads Tracking] 🚫 No consent mechanism found, returning false");
10374
+ // If no consent mechanism is found, assume consent is not granted
10375
+ console.log("[Google Ads Tracking] 🚫 No valid consent state found, returning false");
10317
10376
  return false;
10318
10377
  }
10319
10378
  /**