Class: ReservationTracking
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ReservationTracking
- Defined in:
- app/models/reservation_tracking.rb
Overview
ReservationTracking
Stores **tracking, attribution, and analytics fields** for a reservation. These fields are not part of the core business logic and are intentionally stored separately to avoid bloating the Reservation or ReservationProperty models.
Example attributes:
-
user_country
-
UTM parameters (utm_source, utm_medium, utm_campaign, utm_term, utm_content)
-
future marketing identifiers (gclid, fbclid, ad_id, referral_code)
Each Reservation has at most *one* tracking record.
TODO: migrate UTM fields from ReservationProperty to ReservationTracking.
Instance Method Summary collapse
-
#user_country ⇒ String?
Returns the user's country name for analytics tracking.
-
#user_country=(country_alpha3) ⇒ Object
Sets the user_country for analytics tracking.
Methods inherited from ApplicationRecord
Instance Method Details
#user_country ⇒ String?
Returns the user's country name for analytics tracking. The value corresponds to the official ISO-3166 country name stored in the Country table.
ref: en.wikipedia.org/wiki/List_of_ISO_3166_country_codes
or nil if no country is associated.
78 79 80 |
# File 'app/models/reservation_tracking.rb', line 78 def user_country country&.name end |
#user_country=(country_alpha3) ⇒ Object
Sets the user_country for analytics tracking.
This method looks up the country by alpha3 code in the database. If found, it links the country; otherwise, country_id will be set to nil. No error is raised for non-existent countries, as this is used purely for tracking user origin.
NOTE: The validation of whether the country alpha3 code is in the database happens in the service layer via Country.valid_country_code? before this setter is called.
68 69 70 |
# File 'app/models/reservation_tracking.rb', line 68 def user_country=(country_alpha3) self.country = Country.find_by(alpha3: country_alpha3) if country_alpha3.present? end |