From 904f0dac78b92e3f31b747b5f3df29292e76f663 Mon Sep 17 00:00:00 2001 From: Vaidehi Joshi Date: Thu, 18 Jun 2020 13:40:14 -0700 Subject: [PATCH] Add ahoy + welcome notification tracking (#8758) [deploy] * Set up ahoy gem, add ahoy-js * Import ahoy.js into base.js.erb * Add trackNotification function to notifications/index.html.erb * Add sanitized_broadcast_id helper * Use sanitized_broadcast_id in broadcast partial * Add specs around tracking welcome notifications * Remove optional fields from Ahoy::Visit migration + table * Fiddle with trait to see if it helps with CI failures * Disable geocode tracking in ahoy * Stub out SiteConfig in notifications page spec --- Gemfile | 1 + Gemfile.lock | 8 +++ app/assets/javascripts/base.js.erb | 1 + app/helpers/broadcasts_helper.rb | 4 ++ app/models/ahoy/event.rb | 8 +++ app/models/ahoy/visit.rb | 6 +++ app/views/notifications/_broadcast.html.erb | 2 +- app/views/notifications/index.html.erb | 14 +++++ config/initializers/ahoy.rb | 8 +++ ...617183058_create_ahoy_visits_and_events.rb | 28 ++++++++++ db/schema.rb | 23 +++++++- package.json | 1 + spec/factories/broadcasts.rb | 4 ++ .../notifications/notifications_page_spec.rb | 50 ++++++++++++++++++ vendor/cache/ahoy_matey-3.0.4.gem | Bin 0 -> 27648 bytes vendor/cache/device_detector-1.0.3.gem | Bin 0 -> 425984 bytes vendor/cache/geocoder-1.6.3.gem | Bin 0 -> 83456 bytes yarn.lock | 12 +++++ 18 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 app/models/ahoy/event.rb create mode 100644 app/models/ahoy/visit.rb create mode 100644 config/initializers/ahoy.rb create mode 100644 db/migrate/20200617183058_create_ahoy_visits_and_events.rb create mode 100644 vendor/cache/ahoy_matey-3.0.4.gem create mode 100644 vendor/cache/device_detector-1.0.3.gem create mode 100644 vendor/cache/geocoder-1.6.3.gem diff --git a/Gemfile b/Gemfile index 0ca14da6a..51a2f9e5f 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,7 @@ gem "acts_as_follower", github: "thepracticaldev/acts_as_follower", branch: "mas gem "addressable", "~> 2.7" # A replacement for the URI implementation that is part of Ruby's standard library gem "administrate", "~> 0.13" # A Rails engine that helps you put together a super-flexible admin dashboard gem "ahoy_email", "~> 1.1" # Email analytics for Rails +gem "ahoy_matey", "~> 3.0" # Tracking analytics for Rails gem "ancestry", "~> 3.0" # Ancestry allows the records of a ActiveRecord model to be organized in a tree structure gem "autoprefixer-rails", "~> 9.7" # Parse CSS and add vendor prefixes to CSS rules using values from the Can I Use website gem "aws-sdk-lambda", "~> 1.42" # Official AWS Ruby gem for AWS Lambda diff --git a/Gemfile.lock b/Gemfile.lock index 863e88029..a0fde2a1d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -99,6 +99,11 @@ GEM addressable (>= 2.3.2) nokogiri safely_block (>= 0.1.1) + ahoy_matey (3.0.4) + activesupport (>= 5) + device_detector + geocoder (>= 1.4.5) + safely_block (>= 0.2.1) amazing_print (1.2.0) ancestry (3.0.7) activerecord (>= 3.2.0) @@ -235,6 +240,7 @@ GEM unicode_plot (>= 0.0.4, < 1.0.0) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) + device_detector (1.0.3) devise (4.7.2) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -369,6 +375,7 @@ GEM formatador (0.2.5) front_matter_parser (0.2.1) gemoji (4.0.0.rc2) + geocoder (1.6.3) get_process_mem (0.2.5) ffi (~> 1.0) gibbon (3.3.4) @@ -876,6 +883,7 @@ DEPENDENCIES addressable (~> 2.7) administrate (~> 0.13) ahoy_email (~> 1.1) + ahoy_matey (~> 3.0) amazing_print (~> 1.2) ancestry (~> 3.0) approvals (~> 0.0) diff --git a/app/assets/javascripts/base.js.erb b/app/assets/javascripts/base.js.erb index ecc6c5d80..576eb9942 100644 --- a/app/assets/javascripts/base.js.erb +++ b/app/assets/javascripts/base.js.erb @@ -4,6 +4,7 @@ //= require initializePage //= require utilities/getImageForLink //= require honeybadger-js/dist/honeybadger.js +//= require ahoy.js/dist/ahoy.js //= require serviceworker-companion var instantClick diff --git a/app/helpers/broadcasts_helper.rb b/app/helpers/broadcasts_helper.rb index 651f453bb..8153cf8bf 100644 --- a/app/helpers/broadcasts_helper.rb +++ b/app/helpers/broadcasts_helper.rb @@ -8,4 +8,8 @@ module BroadcastsHelper "crayons-banner crayons-banner--#{broadcast.banner_style}" end end + + def sanitized_broadcast_id(broadcast_title) + broadcast_title.downcase.delete(":").tr(" ", "_") + end end diff --git a/app/models/ahoy/event.rb b/app/models/ahoy/event.rb new file mode 100644 index 000000000..4c3125b53 --- /dev/null +++ b/app/models/ahoy/event.rb @@ -0,0 +1,8 @@ +class Ahoy::Event < ApplicationRecord + include Ahoy::QueryMethods + + self.table_name = "ahoy_events" + + belongs_to :visit + belongs_to :user, optional: true +end diff --git a/app/models/ahoy/visit.rb b/app/models/ahoy/visit.rb new file mode 100644 index 000000000..66f89e5d5 --- /dev/null +++ b/app/models/ahoy/visit.rb @@ -0,0 +1,6 @@ +class Ahoy::Visit < ApplicationRecord + self.table_name = "ahoy_visits" + + has_many :events, class_name: "Ahoy::Event" + belongs_to :user, optional: true +end diff --git a/app/views/notifications/_broadcast.html.erb b/app/views/notifications/_broadcast.html.erb index eb8994fc6..a41b9a5e1 100644 --- a/app/views/notifications/_broadcast.html.erb +++ b/app/views/notifications/_broadcast.html.erb @@ -6,7 +6,7 @@ link to <%= json_data['s profile"> -
+
<%= json_data["broadcast"]["processed_html"].html_safe %> <% if notification.json_data['broadcast']['type_of'] == "Welcome" %> diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb index c20a3b8ca..2e5773387 100644 --- a/app/views/notifications/index.html.erb +++ b/app/views/notifications/index.html.erb @@ -17,6 +17,20 @@ <% end %> + + <% if user_signed_in? %>