@bigz-app/booking-widget 0.3.0 → 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
@@ -237,9 +237,9 @@ const resolveSemanticColor = (colorValue, fallbackValue) => {
237
237
  const themes = {
238
238
  // --- Light Themes ---
239
239
  "light-fresh": {
240
- highlight: "oklch(0.65 0.2 190)", // accent-strong
241
- background: "oklch(0.99 0.005 220)", // neutral-strong (background)
242
- surface: "oklch(1 0 0)", // card (pure white)
240
+ highlight: "#00a8a1", // accent-strong
241
+ background: "#f8fdfe", // neutral-strong (background)
242
+ surface: "#ffffff", // card (pure white)
243
243
  text: "#0e7490", // Turquoise 800
244
244
  border: "#bae6fd", // Blue 200
245
245
  success: "#38bdf8", // Blue 400
@@ -9264,6 +9264,64 @@ function PaymentForm({ config, eventDetails, formData, totalAmount, discountCode
9264
9264
  const [paymentIntentId, setPaymentIntentId] = useState(null);
9265
9265
  const [isCreatingPaymentIntent, setIsCreatingPaymentIntent] = useState(false);
9266
9266
  const [paymentError, setPaymentError] = useState(null);
9267
+ // LocalStorage persistence (scoped by organization + event) for paymentIntentId only
9268
+ const storageKey = typeof window !== "undefined"
9269
+ ? `bw_pi_${config?.organizationId}_${config?.eventInstanceId || eventDetails?.id}`
9270
+ : "";
9271
+ const PAYMENT_INTENT_TTL = 24 * 60 * 60 * 1000; // 24 hours
9272
+ function loadPersistedPaymentIntent() {
9273
+ if (typeof window === "undefined" || !storageKey)
9274
+ return null;
9275
+ try {
9276
+ const raw = window.localStorage.getItem(storageKey);
9277
+ if (!raw)
9278
+ return null;
9279
+ const parsed = JSON.parse(raw);
9280
+ if (!parsed?.id || !parsed?.ts)
9281
+ return null;
9282
+ if (Date.now() - parsed.ts > PAYMENT_INTENT_TTL) {
9283
+ window.localStorage.removeItem(storageKey);
9284
+ return null;
9285
+ }
9286
+ return parsed.id;
9287
+ }
9288
+ catch {
9289
+ return null;
9290
+ }
9291
+ }
9292
+ function persistPaymentIntent(id) {
9293
+ if (typeof window === "undefined" || !storageKey || !id)
9294
+ return;
9295
+ try {
9296
+ const payload = { id, ts: Date.now() };
9297
+ window.localStorage.setItem(storageKey, JSON.stringify(payload));
9298
+ }
9299
+ catch { }
9300
+ }
9301
+ function clearPersistedPaymentIntent() {
9302
+ if (typeof window === "undefined" || !storageKey)
9303
+ return;
9304
+ try {
9305
+ window.localStorage.removeItem(storageKey);
9306
+ }
9307
+ catch { }
9308
+ }
9309
+ // On mount (and when scope changes), restore persisted paymentIntentId
9310
+ useEffect(() => {
9311
+ if (!paymentIntentId) {
9312
+ const restored = loadPersistedPaymentIntent();
9313
+ if (restored) {
9314
+ setPaymentIntentId(restored);
9315
+ }
9316
+ }
9317
+ // eslint-disable-next-line react-hooks/exhaustive-deps
9318
+ }, [storageKey]);
9319
+ // Persist whenever paymentIntentId changes
9320
+ useEffect(() => {
9321
+ if (paymentIntentId) {
9322
+ persistPaymentIntent(paymentIntentId);
9323
+ }
9324
+ }, [paymentIntentId]);
9267
9325
  // Create payment intent when component mounts or when relevant data changes
9268
9326
  useEffect(() => {
9269
9327
  const createPaymentIntent = async () => {
@@ -9393,7 +9451,13 @@ function PaymentForm({ config, eventDetails, formData, totalAmount, discountCode
9393
9451
  clientSecret,
9394
9452
  appearance: stripeAppearance || { theme: "stripe" },
9395
9453
  locale: config.locale || "de",
9396
- }, children: jsx(PaymentFormInner, { config: config, eventDetails: eventDetails, formData: formData, totalAmount: totalAmount, discountCode: discountCode, onSuccess: onSuccess, onError: onError, systemConfig: systemConfig, clientSecret: clientSecret }) }));
9454
+ }, children: jsx(PaymentFormInner, { config: config, eventDetails: eventDetails, formData: formData, totalAmount: totalAmount, discountCode: discountCode, onSuccess: (result) => {
9455
+ // Clear persisted PI data on successful payment
9456
+ clearPersistedPaymentIntent();
9457
+ setPaymentIntentId(null);
9458
+ setClientSecret(null);
9459
+ onSuccess(result);
9460
+ }, onError: onError, systemConfig: systemConfig, clientSecret: clientSecret }) }));
9397
9461
  }
9398
9462
 
9399
9463
  function Sidebar({ isOpen, onClose, title, children, width = "450px" }) {
@@ -10208,6 +10272,317 @@ function BookingForm({ config, eventDetails, stripePromise, onSuccess, onError,
10208
10272
  ` })] }) }));
10209
10273
  }
10210
10274
 
10275
+ /**
10276
+ * Google Ads Conversion Tracking Utility
10277
+ *
10278
+ * This utility handles Google Ads conversion tracking for the booking widget.
10279
+ * It includes consent checking, gtag initialization, and conversion tracking.
10280
+ */
10281
+ /**
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
10284
+ */
10285
+ function checkGoogleConsent() {
10286
+ console.log("[Google Ads Tracking] 🔍 Checking Google consent...");
10287
+ if (typeof window === "undefined") {
10288
+ console.log("[Google Ads Tracking] ❌ Window object not available (SSR context)");
10289
+ return false;
10290
+ }
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
+ }
10323
+ }
10324
+ }
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
+ }
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
+ }
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");
10376
+ return false;
10377
+ }
10378
+ /**
10379
+ * Check if gtag is already initialized on the host page
10380
+ */
10381
+ function isGtagInitialized() {
10382
+ console.log("[Google Ads Tracking] 🔍 Checking if gtag is initialized...");
10383
+ if (typeof window === "undefined") {
10384
+ console.log("[Google Ads Tracking] ❌ Window object not available (SSR context)");
10385
+ return false;
10386
+ }
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;
10392
+ }
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
+ }
10460
+ });
10461
+ }
10462
+ /**
10463
+ * Track a Google Ads conversion
10464
+ */
10465
+ function trackConversion(config) {
10466
+ console.log("[Google Ads Tracking] 🎯 Starting conversion tracking with config:", config);
10467
+ if (typeof window === "undefined") {
10468
+ console.warn("[Google Ads Tracking] ❌ Window object not available");
10469
+ return;
10470
+ }
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;
10478
+ }
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");
10485
+ return;
10486
+ }
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);
10512
+ }
10513
+ catch (error) {
10514
+ console.error("[Google Ads Tracking] ❌ Error tracking conversion:", error);
10515
+ }
10516
+ }
10517
+ /**
10518
+ * Main function to handle Google Ads conversion tracking
10519
+ * This function checks consent, initializes gtag if needed, and tracks the conversion
10520
+ */
10521
+ async function handleGoogleAdsConversion(config) {
10522
+ console.log("[Google Ads Tracking] 🎬 Starting handleGoogleAdsConversion with config:", config);
10523
+ // Validate config
10524
+ 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 });
10526
+ return;
10527
+ }
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");
10543
+ }
10544
+ else {
10545
+ console.log("[Google Ads Tracking] ⚡ gtag already initialized, proceeding...");
10546
+ }
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;
10584
+ }
10585
+
10211
10586
  const BookingSuccessModal = ({ isOpen, onClose, config, onError, paymentIntentId, }) => {
10212
10587
  const [bookingData, setBookingData] = useState(null);
10213
10588
  const [eventDetails, setEventDetails] = useState(null);
@@ -10252,6 +10627,27 @@ const BookingSuccessModal = ({ isOpen, onClose, config, onError, paymentIntentId
10252
10627
  });
10253
10628
  // Set payment status from Stripe data or order status
10254
10629
  setPaymentStatus(data.stripePaymentIntent?.status || data.order.status);
10630
+ // Trigger Google Ads conversion tracking if payment is successful
10631
+ const finalPaymentStatus = data.stripePaymentIntent?.status || data.order.status;
10632
+ if (finalPaymentStatus === "succeeded" &&
10633
+ config.googleAds?.tagId &&
10634
+ config.googleAds?.conversionId) {
10635
+ // Prepare conversion tracking data
10636
+ const conversionValue = config.googleAds.includeValue !== false
10637
+ ? getConversionValueFromBooking(data)
10638
+ : undefined;
10639
+ const transactionId = data.order.id;
10640
+ // Track the conversion
10641
+ handleGoogleAdsConversion({
10642
+ tagId: config.googleAds.tagId,
10643
+ conversionId: config.googleAds.conversionId,
10644
+ conversionValue,
10645
+ conversionCurrency: config.googleAds.conversionCurrency || "EUR",
10646
+ transactionId,
10647
+ }).catch((error) => {
10648
+ console.warn("[BookingSuccessModal] Google Ads conversion tracking failed:", error);
10649
+ });
10650
+ }
10255
10651
  }
10256
10652
  else {
10257
10653
  onError?.(data.error || "Fehler beim Abrufen der Buchungsdaten");
@@ -11848,7 +12244,6 @@ function UniversalBookingWidget({ config: baseConfig }) {
11848
12244
  body: JSON.stringify(requestBody),
11849
12245
  });
11850
12246
  const data = await response.json();
11851
- console.log("Event details response:", { status: response.status, data }); // Debug log
11852
12247
  if (response.ok) {
11853
12248
  setEventDetails(data.eventDetails);
11854
12249
  // Store system configuration for PaymentForm