Class: OutletPurchaseConversionWorker
- Inherits:
-
Object
- Object
- OutletPurchaseConversionWorker
- Includes:
- Sidekiq::Worker
- Defined in:
- app/workers/outlet_purchase_conversion_worker.rb
Overview
Reports an outlet purchase to the ad platforms once the rep has claimed it.
If a Google click produced a real WarmlyYours sale, that is a conversion
whatever channel it closed in — suppressing it starves bid optimisation on
clicks we already paid for. The click identifier lives on the opportunity
(Opportunity#find_gclid reads visit / customer / customer-visit), so it is
available even though no order exists on our side.
Fires on the rep's claim, not the manager's verification:
GoogleConversionReporter::CONVERSION_WINDOW_DAYS is 90 and matched invoices
run to 200 days P90 from the opportunity, so gating on an unhurried review
would see most uploads rejected as stale. Manager verification gates
commission, not this.
Instance Method Summary collapse
Instance Method Details
#perform(purchase_id) ⇒ void
This method returns an undefined value.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/workers/outlet_purchase_conversion_worker.rb', line 26 def perform(purchase_id) purchase = CustomerOutletPurchase.find_by(id: purchase_id) return unless purchase&.attributed? opportunity = purchase.opportunity return log_skip(purchase, 'no click identifier on the opportunity') if click_identifier(opportunity).blank? result = Invoicing::GoogleConversionReporter.new.send_new_opportunity_conversion( # A TimeWithZone, not a String: the reporter compares this against the # click baseline, and comparing a String would raise. opportunity, conversion_date_time: purchase.invoice_date&.in_time_zone ) Rails.logger.info( "[OutletPurchaseConversionWorker] #{opportunity.reference_number} via #{purchase.outlet_name}: #{result.inspect}" ) end |