@bigz-app/booking-widget 0.3.2 → 0.3.3

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
@@ -237,7 +237,7 @@ const resolveSemanticColor = (colorValue, fallbackValue) => {
237
237
  const themes = {
238
238
  // --- Light Themes ---
239
239
  "light-fresh": {
240
- highlight: "#00a8a1", // accent-strong
240
+ highlight: "#00b1aa", // accent-strong
241
241
  background: "#f8fdfe", // neutral-strong (background)
242
242
  surface: "#ffffff", // card (pure white)
243
243
  text: "#0e7490", // Turquoise 800
@@ -10275,312 +10275,140 @@ function BookingForm({ config, eventDetails, stripePromise, onSuccess, onError,
10275
10275
  /**
10276
10276
  * Google Ads Conversion Tracking Utility
10277
10277
  *
10278
- * This utility handles Google Ads conversion tracking for the booking widget.
10279
- * It includes consent checking, gtag initialization, and conversion tracking.
10278
+ * Simplified utility that waits 1500ms, checks/initializes gtag, and sends conversion.
10280
10279
  */
10281
10280
  /**
10282
- * Check if Google Consent Mode has granted the necessary permissions for ads tracking
10283
- * This checks multiple sources of consent state in order of preference
10281
+ * Check if gtag is available in current or parent window
10284
10282
  */
10285
- function checkGoogleConsent() {
10286
- console.log("[Google Ads Tracking] 🔍 Checking Google consent...");
10283
+ function isGtagAvailable() {
10287
10284
  if (typeof window === "undefined") {
10288
- console.log("[Google Ads Tracking] Window object not available (SSR context)");
10285
+ console.warn("[Google Ads] window is undefined (SSR context)");
10289
10286
  return false;
10290
10287
  }
10291
- console.log("[Google Ads Tracking] ✅ Window object available");
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
- }
10288
+ // Check current window
10289
+ if (typeof window.gtag === "function") {
10290
+ console.log("[Google Ads] gtag found in current window");
10291
+ return true;
10292
+ }
10293
+ // Check parent window (for iframe/widget scenarios)
10294
+ if (window !== window.parent) {
10295
+ try {
10296
+ if (typeof window.parent?.gtag === "function") {
10297
+ console.log("[Google Ads] gtag found in parent window");
10298
+ return true;
10323
10299
  }
10324
10300
  }
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;
10301
+ catch (e) {
10302
+ console.warn("[Google Ads] Could not access parent window for gtag (cross-origin)");
10331
10303
  }
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
- }
10361
- }
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
- }
10371
- else {
10372
- console.log("[Google Ads Tracking] ❌ gtag function not found");
10373
10304
  }
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");
10305
+ console.log("[Google Ads] gtag not found");
10376
10306
  return false;
10377
10307
  }
10378
10308
  /**
10379
- * Check if gtag is already initialized on the host page
10309
+ * Initialize gtag if not already available
10380
10310
  */
10381
- function isGtagInitialized() {
10382
- console.log("[Google Ads Tracking] 🔍 Checking if gtag is initialized...");
10311
+ function initializeGtag(tagId) {
10383
10312
  if (typeof window === "undefined") {
10384
- console.log("[Google Ads Tracking] Window object not available (SSR context)");
10385
- return false;
10313
+ console.warn("[Google Ads] window is undefined, cannot initialize gtag");
10314
+ return;
10386
10315
  }
10387
- console.log("[Google Ads Tracking] Window object available");
10388
- // Check if gtag function exists
10389
- if (typeof window.gtag === "function") {
10390
- console.log("[Google Ads Tracking] ✅ gtag function exists");
10391
- return true;
10316
+ // Skip if gtag already exists
10317
+ if (isGtagAvailable()) {
10318
+ console.log("[Google Ads] gtag already initialized, skipping init");
10319
+ return;
10392
10320
  }
10393
- console.log("[Google Ads Tracking] gtag function not found, checking for scripts...");
10394
- // Check if Google Analytics or Google Ads scripts are already loaded
10395
- const scripts = document.querySelectorAll('script[src*="googletagmanager.com"]');
10396
- console.log("[Google Ads Tracking] 📜 Found", scripts.length, "Google Tag Manager scripts");
10397
- const isInitialized = scripts.length > 0;
10398
- console.log("[Google Ads Tracking] 🎯 gtag initialization status:", isInitialized);
10399
- return isInitialized;
10400
- }
10401
- /**
10402
- * Initialize Google Tag (gtag) if not already present
10403
- */
10404
- function initializeGtag(tagId) {
10405
- console.log("[Google Ads Tracking] 🚀 Starting gtag initialization with tagId:", tagId);
10406
- return new Promise((resolve, reject) => {
10407
- if (typeof window === "undefined") {
10408
- console.log("[Google Ads Tracking] ❌ Window object not available (SSR context)");
10409
- reject(new Error("Window object not available"));
10410
- return;
10411
- }
10412
- console.log("[Google Ads Tracking] ✅ Window object available");
10413
- // If gtag is already initialized, just resolve
10414
- if (isGtagInitialized()) {
10415
- console.log("[Google Ads Tracking] ⚡ gtag already initialized, skipping setup");
10416
- resolve();
10417
- return;
10418
- }
10419
- console.log("[Google Ads Tracking] 📦 gtag not found, creating new script element...");
10420
- try {
10421
- // Create the gtag script
10422
- const script = document.createElement("script");
10423
- script.async = true;
10424
- script.src = `https://www.googletagmanager.com/gtag/js?id=${tagId}`;
10425
- console.log("[Google Ads Tracking] 🌐 Script src set to:", script.src);
10426
- script.onload = () => {
10427
- console.log("[Google Ads Tracking] 📥 Script loaded successfully, initializing gtag...");
10428
- // Initialize gtag
10429
- window.dataLayer = window.dataLayer || [];
10430
- console.log("[Google Ads Tracking] 📊 dataLayer initialized");
10431
- window.gtag = (...args) => {
10432
- window.dataLayer.push(args);
10433
- };
10434
- console.log("[Google Ads Tracking] 🔧 gtag function created");
10435
- // Configure gtag
10436
- console.log("[Google Ads Tracking] ⚙️ Configuring gtag with privacy settings...");
10437
- window.gtag("js", new Date());
10438
- window.gtag("config", tagId, {
10439
- // Respect consent settings
10440
- anonymize_ip: true,
10441
- allow_google_signals: false,
10442
- allow_ad_personalization_signals: false,
10443
- });
10444
- console.log("[Google Ads Tracking] ✅ gtag initialized successfully with tagId:", tagId);
10445
- resolve();
10446
- };
10447
- script.onerror = (error) => {
10448
- console.error("[Google Ads Tracking] ❌ Failed to load Google Tag script:", error);
10449
- reject(new Error("Failed to load Google Tag script"));
10450
- };
10451
- console.log("[Google Ads Tracking] 📑 Adding script to document head...");
10452
- // Add script to head
10453
- document.head.appendChild(script);
10454
- console.log("[Google Ads Tracking] ✅ Script element appended to head");
10455
- }
10456
- catch (error) {
10457
- console.error("[Google Ads Tracking] ❌ Error during gtag initialization:", error);
10458
- reject(error);
10459
- }
10321
+ // Initialize dataLayer and gtag function
10322
+ console.log("[Google Ads] Initializing dataLayer and gtag function");
10323
+ window.dataLayer = window.dataLayer || [];
10324
+ window.gtag = (...args) => {
10325
+ window.dataLayer.push(args);
10326
+ };
10327
+ // Set current timestamp
10328
+ console.log("[Google Ads] Setting gtag timestamp");
10329
+ window.gtag("js", new Date());
10330
+ // Load gtag script
10331
+ console.log("[Google Ads] Loading gtag script from:", `https://www.googletagmanager.com/gtag/js?id=${tagId}`);
10332
+ const script = document.createElement("script");
10333
+ script.async = true;
10334
+ script.src = `https://www.googletagmanager.com/gtag/js?id=${tagId}`;
10335
+ document.head.appendChild(script);
10336
+ // Configure the tag
10337
+ console.log("[Google Ads] Configuring gtag with tagId:", tagId);
10338
+ window.gtag("config", tagId, {
10339
+ anonymize_ip: true,
10340
+ allow_google_signals: false,
10341
+ allow_ad_personalization_signals: false,
10460
10342
  });
10461
10343
  }
10462
10344
  /**
10463
- * Track a Google Ads conversion
10345
+ * Send conversion event using available gtag
10464
10346
  */
10465
- function trackConversion(config) {
10466
- console.log("[Google Ads Tracking] 🎯 Starting conversion tracking with config:", config);
10347
+ function sendConversion(config) {
10467
10348
  if (typeof window === "undefined") {
10468
- console.warn("[Google Ads Tracking] Window object not available");
10349
+ console.warn("[Google Ads] window is undefined, cannot send conversion");
10469
10350
  return;
10470
10351
  }
10471
- console.log("[Google Ads Tracking] ✅ Window object available");
10472
- if (!config.tagId || !config.conversionId) {
10473
- console.warn("[Google Ads Tracking] Missing tagId or conversionId", {
10474
- tagId: config.tagId,
10475
- conversionId: config.conversionId,
10476
- });
10477
- return;
10352
+ let gtag = window.gtag;
10353
+ // Try parent window gtag if current window doesn't have it
10354
+ if (typeof gtag !== "function" && window !== window.parent) {
10355
+ try {
10356
+ gtag = window.parent?.gtag;
10357
+ if (typeof gtag === "function") {
10358
+ console.log("[Google Ads] Using parent window gtag");
10359
+ }
10360
+ }
10361
+ catch {
10362
+ console.warn("[Google Ads] Could not access parent window for gtag (cross-origin)");
10363
+ }
10478
10364
  }
10479
- console.log("[Google Ads Tracking] ✅ Required config fields present:", {
10480
- tagId: config.tagId,
10481
- conversionId: config.conversionId,
10482
- });
10483
- if (typeof window.gtag !== "function") {
10484
- console.warn("[Google Ads Tracking] ❌ gtag function not available");
10365
+ if (typeof gtag !== "function") {
10366
+ console.warn("[Google Ads] gtag not available, cannot send conversion");
10485
10367
  return;
10486
10368
  }
10487
- console.log("[Google Ads Tracking] ✅ gtag function is available");
10488
- try {
10489
- console.log("[Google Ads Tracking] 🔧 Building conversion data...");
10490
- const conversionData = {
10491
- send_to: `${config.tagId}/${config.conversionId}`,
10492
- };
10493
- console.log("[Google Ads Tracking] 📋 Base conversion data:", conversionData);
10494
- // Add optional parameters
10495
- if (config.conversionValue !== undefined) {
10496
- conversionData.value = config.conversionValue;
10497
- console.log("[Google Ads Tracking] 💰 Added conversion value:", config.conversionValue);
10498
- }
10499
- if (config.conversionCurrency) {
10500
- conversionData.currency = config.conversionCurrency;
10501
- console.log("[Google Ads Tracking] 💱 Added currency:", config.conversionCurrency);
10502
- }
10503
- if (config.transactionId) {
10504
- conversionData.transaction_id = config.transactionId;
10505
- console.log("[Google Ads Tracking] 🔖 Added transaction ID:", config.transactionId);
10506
- }
10507
- console.log("[Google Ads Tracking] 📦 Final conversion data:", conversionData);
10508
- // Track the conversion
10509
- console.log("[Google Ads Tracking] 🚀 Sending conversion event to gtag...");
10510
- window.gtag("event", "conversion", conversionData);
10511
- console.log("[Google Ads Tracking] ✅ Conversion tracked successfully:", conversionData);
10369
+ // Build conversion data
10370
+ const conversionData = {
10371
+ send_to: `${config.tagId}/${config.conversionId}`,
10372
+ };
10373
+ // Add optional parameters
10374
+ if (config.conversionValue !== undefined) {
10375
+ conversionData.value = config.conversionValue;
10512
10376
  }
10513
- catch (error) {
10514
- console.error("[Google Ads Tracking] ❌ Error tracking conversion:", error);
10377
+ if (config.conversionCurrency) {
10378
+ conversionData.currency = config.conversionCurrency;
10515
10379
  }
10380
+ if (config.transactionId) {
10381
+ conversionData.transaction_id = config.transactionId;
10382
+ }
10383
+ console.log("[Google Ads] Dispatching conversion event:", conversionData);
10384
+ // Send conversion event
10385
+ gtag("event", "conversion", conversionData);
10516
10386
  }
10517
10387
  /**
10518
10388
  * Main function to handle Google Ads conversion tracking
10519
- * This function checks consent, initializes gtag if needed, and tracks the conversion
10389
+ * Waits 1500ms, checks/initializes gtag, then sends conversion
10520
10390
  */
10521
- async function handleGoogleAdsConversion(config) {
10522
- console.log("[Google Ads Tracking] 🎬 Starting handleGoogleAdsConversion with config:", config);
10523
- // Validate config
10391
+ function handleGoogleAdsConversion(config) {
10392
+ // Validate required config
10524
10393
  if (!config.tagId || !config.conversionId) {
10525
- console.log("[Google Ads Tracking] No tagId or conversionId provided, skipping conversion tracking", { tagId: config.tagId, conversionId: config.conversionId });
10394
+ console.warn("[Google Ads] Missing tagId or conversionId", config);
10526
10395
  return;
10527
10396
  }
10528
- console.log("[Google Ads Tracking] Config validation passed");
10529
- // Check consent first
10530
- console.log("[Google Ads Tracking] 🔐 Checking consent...");
10531
- if (!checkGoogleConsent()) {
10532
- console.log("[Google Ads Tracking] 🚫 Google consent not granted, skipping conversion tracking");
10533
- return;
10534
- }
10535
- console.log("[Google Ads Tracking] ✅ Consent check passed");
10536
- try {
10537
- // Initialize gtag if not already present
10538
- console.log("[Google Ads Tracking] 🔍 Checking if gtag needs initialization...");
10539
- if (!isGtagInitialized()) {
10540
- console.log("[Google Ads Tracking] 🚀 Initializing gtag...");
10541
- await initializeGtag(config.tagId);
10542
- console.log("[Google Ads Tracking] ✅ gtag initialization completed");
10397
+ console.log("[Google Ads] Waiting 1500ms before tracking conversion...");
10398
+ // Wait 1500ms before proceeding
10399
+ setTimeout(() => {
10400
+ console.log("[Google Ads] Checking if gtag is available...");
10401
+ // Check if gtag is available, initialize if not
10402
+ if (!isGtagAvailable()) {
10403
+ console.log("[Google Ads] gtag not found, initializing...");
10404
+ initializeGtag(config.tagId);
10543
10405
  }
10544
10406
  else {
10545
- console.log("[Google Ads Tracking] gtag already initialized, proceeding...");
10407
+ console.log("[Google Ads] gtag already available.");
10546
10408
  }
10547
- // Small delay to ensure gtag is ready
10548
- console.log("[Google Ads Tracking] ⏱️ Adding 100ms delay to ensure gtag is ready...");
10549
- setTimeout(() => {
10550
- console.log("[Google Ads Tracking] 🎯 Delay completed, tracking conversion...");
10551
- trackConversion(config);
10552
- }, 100);
10553
- }
10554
- catch (error) {
10555
- console.error("[Google Ads Tracking] ❌ Error handling conversion:", error);
10556
- }
10557
- }
10558
- /**
10559
- * Utility function to get conversion value from booking data
10560
- */
10561
- function getConversionValueFromBooking(bookingData) {
10562
- console.log("[Google Ads Tracking] 💰 Extracting conversion value from booking data:", bookingData);
10563
- // Try to get the total amount from various possible structures
10564
- const possiblePaths = [
10565
- { path: "order.total", value: bookingData?.order?.total },
10566
- { path: "booking.total", value: bookingData?.booking?.total },
10567
- { path: "total", value: bookingData?.total },
10568
- { path: "amount", value: bookingData?.amount },
10569
- { path: "payment.amount", value: bookingData?.payment?.amount },
10570
- { path: "stripePaymentIntent.amount", value: bookingData?.stripePaymentIntent?.amount },
10571
- ];
10572
- console.log("[Google Ads Tracking] 🔍 Checking possible value paths:", possiblePaths);
10573
- for (const { path, value } of possiblePaths) {
10574
- console.log(`[Google Ads Tracking] 📋 Checking path '${path}':`, value);
10575
- if (typeof value === "number" && value > 0) {
10576
- // Convert from cents to euros
10577
- const convertedValue = value / 100;
10578
- console.log(`[Google Ads Tracking] ✅ Found valid value at '${path}': ${value} cents = ${convertedValue} euros`);
10579
- return convertedValue;
10580
- }
10581
- }
10582
- console.log("[Google Ads Tracking] ❌ No valid conversion value found in booking data");
10583
- return undefined;
10409
+ console.log("[Google Ads] Sending conversion event...", config);
10410
+ sendConversion(config);
10411
+ }, 1500);
10584
10412
  }
10585
10413
 
10586
10414
  const BookingSuccessModal = ({ isOpen, onClose, config, onError, paymentIntentId, }) => {
@@ -10631,11 +10459,10 @@ const BookingSuccessModal = ({ isOpen, onClose, config, onError, paymentIntentId
10631
10459
  const finalPaymentStatus = data.stripePaymentIntent?.status || data.order.status;
10632
10460
  if (finalPaymentStatus === "succeeded" &&
10633
10461
  config.googleAds?.tagId &&
10634
- config.googleAds?.conversionId) {
10462
+ config.googleAds?.conversionId &&
10463
+ config.googleAds?.consent !== false) {
10635
10464
  // Prepare conversion tracking data
10636
- const conversionValue = config.googleAds.includeValue !== false
10637
- ? getConversionValueFromBooking(data)
10638
- : undefined;
10465
+ const conversionValue = data.order.total;
10639
10466
  const transactionId = data.order.id;
10640
10467
  // Track the conversion
10641
10468
  handleGoogleAdsConversion({
@@ -10644,8 +10471,6 @@ const BookingSuccessModal = ({ isOpen, onClose, config, onError, paymentIntentId
10644
10471
  conversionValue,
10645
10472
  conversionCurrency: config.googleAds.conversionCurrency || "EUR",
10646
10473
  transactionId,
10647
- }).catch((error) => {
10648
- console.warn("[BookingSuccessModal] Google Ads conversion tracking failed:", error);
10649
10474
  });
10650
10475
  }
10651
10476
  }
@@ -10727,7 +10552,7 @@ const BookingSuccessModal = ({ isOpen, onClose, config, onError, paymentIntentId
10727
10552
  fontWeight: "600",
10728
10553
  color: "var(--bw-highlight-color)",
10729
10554
  margin: "0px 10px",
10730
- }, children: "Buchung erfolgreich erstellt!" })] }), jsx("button", { onClick: handlePrint, style: {
10555
+ }, children: "Reservierung erfolgreich!" })] }), jsx("button", { onClick: handlePrint, style: {
10731
10556
  backgroundColor: "transparent",
10732
10557
  border: `1px solid var(--bw-border-color)`,
10733
10558
  color: "var(--bw-text-color)",