docbrown/app/models/page_view.rb
Ben Halpern 1dc1723709
Add field test gem to establish a/b testing (#6283) [deploy]
* Initial field test spec work

* Clean up specs

* Fix codeclimage

* Cleanups

* Update names

* Rename and remove need to pass logged in status

* Leadup to prod: two experiments

* Move test logic to controller and add tests

Co-authored-by: Josh Puetz <josh@grorichpuetz.com>
2020-03-03 10:21:29 -05:00

35 lines
762 B
Ruby

class PageView < ApplicationRecord
belongs_to :user, optional: true
belongs_to :article
before_create :extract_domain_and_path
after_create_commit :record_field_test_event
private
def extract_domain_and_path
return unless referrer
parsed_url = Addressable::URI.parse(referrer)
self.domain = parsed_url.domain
self.path = parsed_url.path
end
def article_searchable_tags
article.cached_tag_list
end
def article_searchable_text
article.body_text[0..350]
end
def article_tags
article.decorate.cached_tag_list_array
end
def record_field_test_event
return unless user_id
Users::RecordFieldTestEventWorker.perform_async(user_id, :user_home_feed, "user_views_article_four_days_in_week")
end
end