Class: ReferralBox::ReferralLog
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ReferralBox::ReferralLog
- Defined in:
- lib/referral_box/models/referral_log.rb
Class Method Summary collapse
Instance Method Summary collapse
- #browser ⇒ Object
- #city ⇒ Object
- #conversion_rate ⇒ Object
- #converted? ⇒ Boolean
-
#country ⇒ Object
Geo-location methods (if using a geo service).
-
#device_type ⇒ Object
Device detection methods - use stored data or fallback to user_agent parsing.
- #latitude ⇒ Object
- #longitude ⇒ Object
Class Method Details
.clicked_count ⇒ Object
25 26 27 |
# File 'lib/referral_box/models/referral_log.rb', line 25 def self.clicked_count clicked.count end |
.conversion_rate ⇒ Object
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_count ⇒ Object
29 30 31 |
# File 'lib/referral_box/models/referral_log.rb', line 29 def self.converted_count converted.count end |
Instance Method Details
#browser ⇒ Object
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 |
#city ⇒ Object
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_rate ⇒ Object
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
16 17 18 |
# File 'lib/referral_box/models/referral_log.rb', line 16 def converted? signed_up_at.present? && referee_id.present? end |
#country ⇒ Object
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_type ⇒ Object
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 |
#latitude ⇒ Object
67 68 69 |
# File 'lib/referral_box/models/referral_log.rb', line 67 def latitude geo_data&.dig("latitude") end |
#longitude ⇒ Object
71 72 73 |
# File 'lib/referral_box/models/referral_log.rb', line 71 def longitude geo_data&.dig("longitude") end |