fix reporting

This commit is contained in:
Seth Call 2026-01-22 21:21:17 -06:00
parent 8c8024c12b
commit bdeecc76c6
6 changed files with 41 additions and 35939 deletions

View File

@ -21,6 +21,12 @@ class CapiTransmitter
# client_user_agent: user.user_agent # Note: User model might not have user_agent stored directly, might need to pass it or rely on what's available
}
if !user.facebook_click_id.present? ||
user.origin_utm_source != APP_CONFIG.facebook_ad_source
return
end
# Enhance user data with hashed PII if available
# Facebook requires SHA256 hashing for PII
# For now, we rely on click_id and browser_id as primary keys if available

View File

@ -336,6 +336,34 @@ module JamRuby
end
end
def report_meta_capi(current_user, plan_code)
# CAPI Hook: Subscribe
begin
monthly_cost = case plan_code
when JamRuby::SubscriptionDefinitions::JAM_SILVER, JamRuby::SubscriptionDefinitions::JAM_SILVER_YEARLY
5.00
when JamRuby::SubscriptionDefinitions::JAM_GOLD, JamRuby::SubscriptionDefinitions::JAM_GOLD_YEARLY
10.00
when JamRuby::SubscriptionDefinitions::JAM_PLATINUM, JamRuby::SubscriptionDefinitions::JAM_PLATINUM_YEARLY
20.00
else
0.00
end
if monthly_cost > 0
ltv = monthly_cost * 12
begin
puts "Sending CAPI Subscribe event #{current_user.email}, #{monthly_cost}, #{ltv}"
CapiTransmitter.send_event('Subscribe', current_user, { value: monthly_cost.to_s, currency: 'USD', predicted_ltv: ltv.to_s })
rescue => e
puts "Error sending CAPI Subscribe event #{current_user.email}, #{e.message}"
end
end
rescue => e
puts "Error sending CAPI Subscribe event #{current_user.email}, #{e.message}"
end
end
def get_highest_plan(subscription)
SubscriptionDefinitions.higher_plan(subscription.plan.plan_code, get_pending_plan_code(subscription))
end
@ -364,6 +392,8 @@ module JamRuby
end
current_user.reset_playtime
current_user.save(validate: false)
report_meta_capi(current_user, plan_code)
rescue => e
puts "Could not create subscription for user #{current_user.email}. #{e}"
return false, subscription, account

View File

@ -168,34 +168,6 @@ class ApiRecurlyController < ApiController
def create_subscription
begin
sale = Sale.purchase_subscription(current_user, params[:recurly_token], params[:plan_code])
# CAPI Hook: Subscribe
begin
plan_code = params[:plan_code]
monthly_cost = case plan_code
when JamRuby::SubscriptionDefinitions::JAM_SILVER, JamRuby::SubscriptionDefinitions::JAM_SILVER_YEARLY
5.00
when JamRuby::SubscriptionDefinitions::JAM_GOLD, JamRuby::SubscriptionDefinitions::JAM_GOLD_YEARLY
10.00
when JamRuby::SubscriptionDefinitions::JAM_PLATINUM, JamRuby::SubscriptionDefinitions::JAM_PLATINUM_YEARLY
20.00
else
0.00
end
if monthly_cost > 0
ltv = monthly_cost * 12
begin
puts "Sending CAPI Subscribe event #{current_user.email}, #{monthly_cost}, #{ltv}"
CapiTransmitter.send_event('Subscribe', current_user, { value: monthly_cost.to_s, currency: 'USD', predicted_ltv: ltv.to_s })
rescue => e
puts "Error sending CAPI Subscribe event #{current_user.email}, #{e.message}"
end
end
rescue => e
puts "Error sending CAPI Subscribe event #{current_user.email}, #{e.message}"
end
subscription = Recurly::Subscription.find(current_user.recurly_subscription_id)
render :json => subscription.to_json
rescue RecurlyClientError => x

View File

@ -174,6 +174,7 @@ if defined?(Bundler)
config.google_public_server_key = "AIzaSyCPTPq5PEcl4XWcm7NZ2IGClZlbsiE8JNo"
# Facebook Conversions API
config.facebook_ad_source = 'meta'
config.facebook_pixel_id = "25663975269956141" # ONLY ONE. NO MULTI ENV
config.facebook_access_token = "EABAGQTtcGk4BQewKCztlfImT86ZAPsRAm3KDrYWsOFZAdLtJCa7bVOzdnZCnHZBFZBRMFVoSZCQdIpX01xXDM0ZCFmYrkPuAHdLsNBU61c7MZCZBLCFd3Q0qrxiJkeYr3F8FH3p98d0tGKljplhJ8vWBIKAiBXaUCCYk6urZB5qZAIEPsppWZCHOep91xZCtMVqtbGJQfFAZDZD" # ONLY ONE. NO MULTI ENV
config.facebook_conversion_api_tls = true

File diff suppressed because it is too large Load Diff

View File

@ -185,6 +185,10 @@ def web_config
'1234567890'
end
def facebook_ad_source
'meta'
end
def facebook_access_token
'dummy_token'
end