diff --git a/src/alpine_bits_python/alpine_bits_helpers.py b/src/alpine_bits_python/alpine_bits_helpers.py index 955fa98..27fad1e 100644 --- a/src/alpine_bits_python/alpine_bits_helpers.py +++ b/src/alpine_bits_python/alpine_bits_helpers.py @@ -733,14 +733,15 @@ def _process_single_reservation( room_stay=[room_stay], ) + # Always send md5_unique_id as the primary tracking ID + # This is guaranteed to fit in 64 chars and has low collision risk + res_id_value = reservation.md5_unique_id res_id_source = "website" - klick_id = None + # Determine the source based on available click tracking data (for informational purposes) if reservation.fbclid != "": - klick_id = str(reservation.fbclid) res_id_source = "meta" elif reservation.gclid != "": - klick_id = str(reservation.gclid) res_id_source = "google" # Get utm_medium if available, otherwise use source @@ -757,7 +758,7 @@ def _process_single_reservation( hotel_res_id_data = HotelReservationIdData( res_id_type=RESERVATION_ID_TYPE, - res_id_value=klick_id, + res_id_value=res_id_value, res_id_source=res_id_source, res_id_source_context=res_id_source_context, ) diff --git a/src/alpine_bits_python/conversion_service.py b/src/alpine_bits_python/conversion_service.py index 67add2f..ea6a74c 100644 --- a/src/alpine_bits_python/conversion_service.py +++ b/src/alpine_bits_python/conversion_service.py @@ -814,10 +814,10 @@ class ConversionService: advertising_partner: str | None, session: AsyncSession | None = None, ) -> Reservation | None: - """Match reservation by advertising tracking data (fbclid/gclid/utm_campaign). + """Match reservation by advertising tracking data (fbclid/gclid/md5_unique_id). Args: - advertising_campagne: Truncated tracking ID + advertising_campagne: Tracking ID from PMS (could be truncated click_id or md5_unique_id) hotel_id: Hotel ID for filtering guest_first_name: Guest first name for disambiguation guest_last_name: Guest last name for disambiguation @@ -831,12 +831,14 @@ class ConversionService: """ if session is None: session = self.session - # Find reservations where fbclid or gclid starts with the truncated value + # Find reservations where: + # - fbclid/gclid starts with the advertising_campagne value, OR + # - md5_unique_id matches exactly (for direct ID matching) query = select(Reservation).where( or_( Reservation.fbclid.like(f"{advertising_campagne}%"), Reservation.gclid.like(f"{advertising_campagne}%"), - Reservation.utm_campaign.like(f"{advertising_campagne}%"), + Reservation.md5_unique_id == advertising_campagne, ) )