123456789101112131415161718192021222324252627282930313233343536373839 |
- module Ahoy
- class Event < ActiveRecord::Base
- self.table_name = "ahoy_events"
- belongs_to :visit
- belongs_to :user
- belongs_to :action_page
- scope :actions, -> { where(name: "Action") }
- scope :views, -> { where(name: "View") }
- scope :emails, -> { where("properties ->> 'actionType' = 'email'") }
- scope :congress_messages, -> { where("properties ->> 'actionType' = 'congress_message'") }
- scope :calls, -> { where("properties ->> 'actionType' = 'call'") }
- scope :signatures, -> { where("properties ->> 'actionType' = 'signature'") }
- scope :tweets, -> { where("properties ->> 'actionType' = 'tweet'") }
- scope :on_page, -> (id) { where(action_page_id: id) }
- before_save :user_opt_out
- before_save :anonymize_views
- after_create :record_civicrm
- def user_opt_out
- if user
- user_id = nil unless user.record_activity?
- end
- end
- def record_civicrm
- if name == "Action" && user && action_page_id
- user.add_civicrm_activity! action_page_id
- end
- end
- def anonymize_views
- self.user_id = nil if name == "View"
- end
- end
- end
|