Module: Models::SourceAttributable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Customer, Opportunity, Order
- Defined in:
- app/concerns/models/source_attributable.rb
Overview
Concern for models that have source attribution via visits with Google click IDs.
Provides methods to check if source attribution should be protected from manual changes.
Used by: Opportunity, Order, Customer
A source is considered "locked" when the record or its associated visit has a Google
click identifier (gclid, gbraid, or wbraid), indicating paid traffic attribution
that should not be overwritten by manual source selection.
Instance Method Summary collapse
-
#has_google_ads_attribution? ⇒ Boolean
Returns true if this record has Google Ads attribution that should be protected.
-
#source_locked? ⇒ Boolean
Returns true if source should be locked from manual editing in UI.
-
#source_locked_reason ⇒ Object
Human-readable message explaining why source is locked.
-
#visit_with_google_click_id? ⇒ Boolean
Check if the associated visit has a Google click identifier.
Instance Method Details
#has_google_ads_attribution? ⇒ Boolean
Returns true if this record has Google Ads attribution that should be protected.
Override in models that have different visit relationships.
16 17 18 19 20 21 22 |
# File 'app/concerns/models/source_attributable.rb', line 16 def has_google_ads_attribution? return true if respond_to?(:gclid) && gclid.present? return true if respond_to?(:gbraid) && gbraid.present? return true if respond_to?(:wbraid) && wbraid.present? visit_with_google_click_id? end |
#source_locked? ⇒ Boolean
Returns true if source should be locked from manual editing in UI
32 33 34 |
# File 'app/concerns/models/source_attributable.rb', line 32 def source_locked? has_google_ads_attribution? end |
#source_locked_reason ⇒ Object
Human-readable message explaining why source is locked
37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/concerns/models/source_attributable.rb', line 37 def source_locked_reason return nil unless source_locked? if respond_to?(:visit) && visit.present? && (visit.gclid.present? || visit.gbraid.present? || visit.wbraid.present?) "Source is locked: attributed to Google Ads via visit on #{visit.started_at&.to_date}" elsif respond_to?(:gclid) && gclid.present? 'Source is locked: customer has Google Click ID (gclid)' else 'Source is locked: has Google Ads attribution' end end |
#visit_with_google_click_id? ⇒ Boolean
Check if the associated visit has a Google click identifier
25 26 27 28 29 |
# File 'app/concerns/models/source_attributable.rb', line 25 def visit_with_google_click_id? return false unless respond_to?(:visit) && visit.present? visit.gclid.present? || visit.gbraid.present? || visit.wbraid.present? end |