Class: ReferralBox::ReferralLog

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/referral_box/models/referral_log.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clicked_countObject



25
26
27
# File 'lib/referral_box/models/referral_log.rb', line 25

def self.clicked_count
  clicked.count
end

.conversion_rateObject



33
34
35
36
# File 'lib/referral_box/models/referral_log.rb', line 33

def self.conversion_rate
  return 0 if clicked_count.zero?
  (converted_count.to_f / clicked_count * 100).round(2)
end

.converted_countObject



29
30
31
# File 'lib/referral_box/models/referral_log.rb', line 29

def self.converted_count
  converted.count
end

Instance Method Details

#browserObject



45
46
47
48
49
# File 'lib/referral_box/models/referral_log.rb', line 45

def browser
  return self[:browser] if self[:browser].present?
  return detect_browser_from_user_agent if user_agent.present?
  nil
end

#cityObject



60
61
62
63
64
65
# File 'lib/referral_box/models/referral_log.rb', line 60

def city
  return geo_data["city"] if geo_data&.dig("city").present?
  return nil unless ip_address.present?
  # Implement with your preferred geo service
  nil
end

#conversion_rateObject



20
21
22
23
# File 'lib/referral_box/models/referral_log.rb', line 20

def conversion_rate
  return 0 if clicked_count.zero?
  (converted_count.to_f / clicked_count * 100).round(2)
end

#converted?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/referral_box/models/referral_log.rb', line 16

def converted?
  signed_up_at.present? && referee_id.present?
end

#countryObject

Geo-location methods (if using a geo service)



52
53
54
55
56
57
58
# File 'lib/referral_box/models/referral_log.rb', line 52

def country
  return geo_data["country"] if geo_data&.dig("country").present?
  return nil unless ip_address.present?
  # You can integrate with services like MaxMind GeoIP2 or similar
  # For now, return nil - users can implement their own geo service
  nil
end

#device_typeObject

Device detection methods - use stored data or fallback to user_agent parsing



39
40
41
42
43
# File 'lib/referral_box/models/referral_log.rb', line 39

def device_type
  return self[:device_type] if self[:device_type].present?
  return detect_device_type_from_user_agent if user_agent.present?
  nil
end

#latitudeObject



67
68
69
# File 'lib/referral_box/models/referral_log.rb', line 67

def latitude
  geo_data&.dig("latitude")
end

#longitudeObject



71
72
73
# File 'lib/referral_box/models/referral_log.rb', line 71

def longitude
  geo_data&.dig("longitude")
end