workarea-segment_analytics 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintrc +35 -0
  3. data/.gitignore +19 -0
  4. data/.rubocop.yml +8 -0
  5. data/CHANGELOG.md +47 -0
  6. data/Gemfile +16 -0
  7. data/README.md +91 -0
  8. data/Rakefile +60 -0
  9. data/app/assets/javascripts/workarea/storefront/segment_analytics/dependencies/analytics.js.erb +3 -0
  10. data/app/assets/javascripts/workarea/storefront/segment_analytics/modules/login_events.js +40 -0
  11. data/app/assets/javascripts/workarea/storefront/segment_analytics/modules/segment_analytics.js +47 -0
  12. data/app/assets/javascripts/workarea/storefront/segment_analytics/modules/segment_analytics_adapter.js +235 -0
  13. data/app/assets/stylesheets/segment_analytics/.keep +0 -0
  14. data/app/helpers/.keep +0 -0
  15. data/app/helpers/workarea/storefront/segment_analytics_analytics_helper.rb +40 -0
  16. data/app/views/.keep +0 -0
  17. data/app/views/workarea/storefront/users/_current_user_segment_analytics.json.jbuilder +6 -0
  18. data/bin/rails +20 -0
  19. data/config/initializers/appends.rb +18 -0
  20. data/config/initializers/workarea.rb +1 -0
  21. data/config/routes.rb +2 -0
  22. data/lib/tasks/segment_analytics_tasks.rake +4 -0
  23. data/lib/workarea/segment_analytics.rb +23 -0
  24. data/lib/workarea/segment_analytics/engine.rb +14 -0
  25. data/lib/workarea/segment_analytics/version.rb +5 -0
  26. data/script/admin_ci +9 -0
  27. data/script/ci +11 -0
  28. data/script/core_ci +9 -0
  29. data/script/plugins_ci +9 -0
  30. data/script/storefront_ci +9 -0
  31. data/test/dummy/Rakefile +6 -0
  32. data/test/dummy/app/assets/config/manifest.js +4 -0
  33. data/test/dummy/app/assets/images/.keep +0 -0
  34. data/test/dummy/app/assets/javascripts/application.js +13 -0
  35. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  36. data/test/dummy/app/controllers/application_controller.rb +3 -0
  37. data/test/dummy/app/controllers/concerns/.keep +0 -0
  38. data/test/dummy/app/helpers/application_helper.rb +2 -0
  39. data/test/dummy/app/jobs/application_job.rb +2 -0
  40. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  41. data/test/dummy/app/models/concerns/.keep +0 -0
  42. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  43. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  44. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  45. data/test/dummy/bin/bundle +3 -0
  46. data/test/dummy/bin/rails +4 -0
  47. data/test/dummy/bin/rake +4 -0
  48. data/test/dummy/bin/setup +38 -0
  49. data/test/dummy/bin/update +29 -0
  50. data/test/dummy/bin/yarn +11 -0
  51. data/test/dummy/config.ru +5 -0
  52. data/test/dummy/config/application.rb +29 -0
  53. data/test/dummy/config/boot.rb +5 -0
  54. data/test/dummy/config/cable.yml +10 -0
  55. data/test/dummy/config/environment.rb +5 -0
  56. data/test/dummy/config/environments/development.rb +54 -0
  57. data/test/dummy/config/environments/production.rb +91 -0
  58. data/test/dummy/config/environments/test.rb +44 -0
  59. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  60. data/test/dummy/config/initializers/assets.rb +14 -0
  61. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  63. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/test/dummy/config/initializers/inflections.rb +16 -0
  65. data/test/dummy/config/initializers/mime_types.rb +4 -0
  66. data/test/dummy/config/initializers/workarea.rb +5 -0
  67. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/test/dummy/config/locales/en.yml +33 -0
  69. data/test/dummy/config/puma.rb +56 -0
  70. data/test/dummy/config/routes.rb +5 -0
  71. data/test/dummy/config/secrets.yml +32 -0
  72. data/test/dummy/config/spring.rb +6 -0
  73. data/test/dummy/db/seeds.rb +2 -0
  74. data/test/dummy/lib/assets/.keep +0 -0
  75. data/test/dummy/log/.keep +0 -0
  76. data/test/dummy/package.json +5 -0
  77. data/test/javascripts/fixtures/payloads.js +232 -0
  78. data/test/javascripts/fixtures/stubs.js +56 -0
  79. data/test/javascripts/segment_analytics_spec.js +311 -0
  80. data/test/javascripts/spec_helper.js +12 -0
  81. data/test/teaspoon_env.rb +6 -0
  82. data/test/test_helper.rb +10 -0
  83. data/workarea-segment_analytics.gemspec +19 -0
  84. metadata +138 -0
File without changes
data/app/helpers/.keep ADDED
File without changes
@@ -0,0 +1,40 @@
1
+ module Workarea
2
+ module Storefront
3
+ module SegmentAnalyticsAnalyticsHelper
4
+ def checkout_started_analytics_data(order)
5
+ {
6
+ event: 'checkoutStarted',
7
+ domEvent: 'click',
8
+ payload: order_analytics_data(order)
9
+ }
10
+ end
11
+
12
+ # Overrides helper method from Workarea::Storefront::AnalyticsHelper
13
+ def checkout_order_placed_analytics_data(order)
14
+ result = super
15
+ result[:payload].merge!(email: order.email, name: order_name(order))
16
+ result
17
+ end
18
+
19
+ # Share analytics helper method
20
+ # to be used in conjunction with workarea-share
21
+ def share_analytics_data(type, url, message)
22
+ {
23
+ event: 'share',
24
+ domEvent: 'click',
25
+ payload: {
26
+ message: message,
27
+ type: type,
28
+ url: url
29
+ }
30
+ }
31
+ end
32
+
33
+ private
34
+
35
+ def order_name(order)
36
+ "#{order.billing_address.first_name} #{order.billing_address.last_name}"
37
+ end
38
+ end
39
+ end
40
+ end
data/app/views/.keep ADDED
File without changes
@@ -0,0 +1,6 @@
1
+ json.user_id current_user.try(:_id)
2
+ json.checkout_id current_order.id
3
+ if logged_in?
4
+ json.user_name current_user.try(:name)
5
+ json.user_email current_user.try(:email)
6
+ end
data/bin/rails ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/segment_analytics/engine', __FILE__)
7
+ APP_PATH = File.expand_path('../../test/dummy/config/application', __FILE__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
11
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
12
+
13
+ require "action_controller/railtie"
14
+ require "action_view/railtie"
15
+ require "action_mailer/railtie"
16
+ require "rails/test_unit/railtie"
17
+ require "sprockets/railtie"
18
+ require 'teaspoon-mocha'
19
+
20
+ require 'rails/engine/commands'
@@ -0,0 +1,18 @@
1
+ module Workarea
2
+ Plugin.append_javascripts(
3
+ 'storefront.head',
4
+ 'workarea/storefront/segment_analytics/dependencies/analytics'
5
+ )
6
+
7
+ Plugin.append_javascripts(
8
+ 'storefront.modules',
9
+ 'workarea/storefront/segment_analytics/modules/segment_analytics',
10
+ 'workarea/storefront/segment_analytics/modules/login_events',
11
+ 'workarea/storefront/segment_analytics/modules/segment_analytics_adapter'
12
+ )
13
+
14
+ Plugin.append_partials(
15
+ 'storefront.current_user',
16
+ 'workarea/storefront/users/current_user_segment_analytics'
17
+ )
18
+ end
@@ -0,0 +1 @@
1
+ Workarea::SegmentAnalytics.configure_secrets
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :segment do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,23 @@
1
+ require 'workarea'
2
+ require 'workarea/storefront'
3
+ require 'workarea/admin'
4
+
5
+ require 'workarea/segment_analytics/engine'
6
+ require 'workarea/segment_analytics/version'
7
+
8
+ module Workarea
9
+ module SegmentAnalytics
10
+ include ActiveSupport::Configurable
11
+ config_accessor :write_key
12
+
13
+ def self.configure_secrets
14
+ if Rails.application.secrets.segment_analytics.present?
15
+ secrets = Rails.application.secrets.segment_analytics.deep_symbolize_keys
16
+
17
+ self.write_key = secrets[:write_key]
18
+ else
19
+ self.write_key = ''
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module Workarea
2
+ module SegmentAnalytics
3
+ class Engine < ::Rails::Engine
4
+ include Workarea::Plugin
5
+ isolate_namespace Workarea::SegmentAnalytics
6
+
7
+ config.to_prepare do
8
+ Workarea::Storefront::ApplicationController.helper(
9
+ Workarea::Storefront::SegmentAnalyticsAnalyticsHelper
10
+ )
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module Workarea
2
+ module SegmentAnalytics
3
+ VERSION = "1.0.2"
4
+ end
5
+ end
data/script/admin_ci ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem install bundler
4
+ bundle update
5
+
6
+ CI_GEM_PATH="$(bundle show workarea-ci)"
7
+ . ${CI_GEM_PATH}/exe/workarea-set-ci-env
8
+
9
+ bin/rails app:workarea:test:admin
data/script/ci ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem install bundler
4
+ bundle update
5
+
6
+ CI_GEM_PATH="$(bundle show workarea-ci)"
7
+ . ${CI_GEM_PATH}/exe/workarea-set-ci-env
8
+
9
+ bundle exec workarea-lint
10
+ bundle exec workarea-audit
11
+ bin/rails test test/**/*_test.rb
data/script/core_ci ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem install bundler
4
+ bundle update
5
+
6
+ CI_GEM_PATH="$(bundle show workarea-ci)"
7
+ . ${CI_GEM_PATH}/exe/workarea-set-ci-env
8
+
9
+ bin/rails app:workarea:test:core
data/script/plugins_ci ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem install bundler
4
+ bundle update
5
+
6
+ CI_GEM_PATH="$(bundle show workarea-ci)"
7
+ . ${CI_GEM_PATH}/exe/workarea-set-ci-env
8
+
9
+ bin/rails app:workarea:test:plugins
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ gem install bundler
4
+ bundle update
5
+
6
+ CI_GEM_PATH="$(bundle show workarea-ci)"
7
+ . ${CI_GEM_PATH}/exe/workarea-set-ci-env
8
+
9
+ bin/rails app:workarea:test:storefront
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,4 @@
1
+
2
+ //= link_tree ../images
3
+ //= link_directory ../javascripts .js
4
+ //= link_directory ../stylesheets .css
File without changes
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery with: :exception
3
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+
7
+ <%= stylesheet_link_tag 'application', media: 'all' %>
8
+ <%= javascript_include_tag 'application' %>
9
+ </head>
10
+
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a starting point to setup your application.
15
+ # Add necessary setup steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ # Install JavaScript dependencies if using Yarn
22
+ # system('bin/yarn')
23
+
24
+
25
+ # puts "\n== Copying sample files =="
26
+ # unless File.exist?('config/database.yml')
27
+ # cp 'config/database.yml.sample', 'config/database.yml'
28
+ # end
29
+
30
+ puts "\n== Preparing database =="
31
+ system! 'bin/rails db:setup'
32
+
33
+ puts "\n== Removing old logs and tempfiles =="
34
+ system! 'bin/rails log:clear tmp:clear'
35
+
36
+ puts "\n== Restarting application server =="
37
+ system! 'bin/rails restart'
38
+ end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ include FileUtils
5
+
6
+ # path to your application root.
7
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
8
+
9
+ def system!(*args)
10
+ system(*args) || abort("\n== Command #{args} failed ==")
11
+ end
12
+
13
+ chdir APP_ROOT do
14
+ # This script is a way to update your development environment automatically.
15
+ # Add necessary update steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system! 'gem install bundler --conservative'
19
+ system('bundle check') || system!('bundle install')
20
+
21
+ puts "\n== Updating database =="
22
+ system! 'bin/rails db:migrate'
23
+
24
+ puts "\n== Removing old logs and tempfiles =="
25
+ system! 'bin/rails log:clear tmp:clear'
26
+
27
+ puts "\n== Restarting application server =="
28
+ system! 'bin/rails restart'
29
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ VENDOR_PATH = File.expand_path('..', __dir__)
3
+ Dir.chdir(VENDOR_PATH) do
4
+ begin
5
+ exec "yarnpkg #{ARGV.join(" ")}"
6
+ rescue Errno::ENOENT
7
+ $stderr.puts "Yarn executable was not detected in the system."
8
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
9
+ exit 1
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative 'config/environment'
4
+
5
+ run Rails.application
@@ -0,0 +1,29 @@
1
+ require_relative 'boot'
2
+
3
+ require "action_controller/railtie"
4
+ require "action_view/railtie"
5
+ require "action_mailer/railtie"
6
+ require "rails/test_unit/railtie"
7
+ require "sprockets/railtie"
8
+ require "teaspoon-mocha"
9
+
10
+
11
+ # Workarea must be required before other gems to ensure control over Rails.env
12
+ # for running tests
13
+ require "workarea/core"
14
+ require "workarea/admin"
15
+ require "workarea/storefront"
16
+ Bundler.require(*Rails.groups)
17
+ require "workarea/segment_analytics"
18
+
19
+ module Dummy
20
+ class Application < Rails::Application
21
+ # Initialize configuration defaults for originally generated Rails version.
22
+ # config.load_defaults 5.1
23
+
24
+ # Settings in config/environments/* take precedence over those specified here.
25
+ # Application configuration should go into files in config/initializers
26
+ # -- all .rb files in that directory are automatically loaded.
27
+ end
28
+ end
29
+