Class: VendorsService::GoogleReserve::ConversionTrackingService

Inherits:
BaseOperationService show all
Includes:
ElasticAPM::SpanHelpers
Defined in:
app/services/vendors_service/google_reserve/conversion_tracking_service.rb

Constant Summary collapse

ROUTE =
'conversion-tracking'.freeze
ATTRIBUTION_WINDOW_DAYS =
30
MERCHANT_CHANGED_VALUE =

Hardcoded since users cannot change merchants

'2'.freeze

Instance Attribute Summary collapse

Attributes inherited from BaseOperationService

#outcome

Instance Method Summary collapse

Methods inherited from BaseOperationService

#success?

Constructor Details

#initialize(reservation_id) ⇒ ConversionTrackingService

Returns a new instance of ConversionTrackingService.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/vendors_service/google_reserve/conversion_tracking_service.rb', line 13

def initialize(reservation_id)
  super()
  @reservation_id = reservation_id
  @reservation = Reservation.find_by(id: reservation_id)
  @rwg_token = extract_rwg_token

  if @reservation
    BUSINESS_LOGGER.set_business_context({
                                           reservation_id: reservation.id,
                                           vendor_name: ApiVendorV1::Constants::GOOGLE_RESERVE_VENDOR_NAME,
                                         })
  end
end

Instance Attribute Details

#reservationObject (readonly)

Returns the value of attribute reservation.



11
12
13
# File 'app/services/vendors_service/google_reserve/conversion_tracking_service.rb', line 11

def reservation
  @reservation
end

#reservation_idObject (readonly)

Returns the value of attribute reservation_id.



11
12
13
# File 'app/services/vendors_service/google_reserve/conversion_tracking_service.rb', line 11

def reservation_id
  @reservation_id
end

#rwg_tokenObject (readonly)

Returns the value of attribute rwg_token.



11
12
13
# File 'app/services/vendors_service/google_reserve/conversion_tracking_service.rb', line 11

def rwg_token
  @rwg_token
end

Instance Method Details

#send_conversion_eventBoolean

Main method to send conversion event to Google

Returns:

  • (Boolean)

    true if conversion tracking was sent successfully, false otherwise



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/vendors_service/google_reserve/conversion_tracking_service.rb', line 31

def send_conversion_event
  return false if reservation.blank?
  return false unless valid_for_conversion_tracking?

  payload = build_conversion_payload
  response = send_conversion_request(payload)

  if response&.status == 200
    log_conversion_success(response)
    true
  else
    log_conversion_error(response, payload)
    false
  end
rescue StandardError => e
  log_conversion_error(e, payload)
  false
end