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.
- checksums.yaml +7 -0
- data/.eslintrc +35 -0
- data/.gitignore +19 -0
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +47 -0
- data/Gemfile +16 -0
- data/README.md +91 -0
- data/Rakefile +60 -0
- data/app/assets/javascripts/workarea/storefront/segment_analytics/dependencies/analytics.js.erb +3 -0
- data/app/assets/javascripts/workarea/storefront/segment_analytics/modules/login_events.js +40 -0
- data/app/assets/javascripts/workarea/storefront/segment_analytics/modules/segment_analytics.js +47 -0
- data/app/assets/javascripts/workarea/storefront/segment_analytics/modules/segment_analytics_adapter.js +235 -0
- data/app/assets/stylesheets/segment_analytics/.keep +0 -0
- data/app/helpers/.keep +0 -0
- data/app/helpers/workarea/storefront/segment_analytics_analytics_helper.rb +40 -0
- data/app/views/.keep +0 -0
- data/app/views/workarea/storefront/users/_current_user_segment_analytics.json.jbuilder +6 -0
- data/bin/rails +20 -0
- data/config/initializers/appends.rb +18 -0
- data/config/initializers/workarea.rb +1 -0
- data/config/routes.rb +2 -0
- data/lib/tasks/segment_analytics_tasks.rake +4 -0
- data/lib/workarea/segment_analytics.rb +23 -0
- data/lib/workarea/segment_analytics/engine.rb +14 -0
- data/lib/workarea/segment_analytics/version.rb +5 -0
- data/script/admin_ci +9 -0
- data/script/ci +11 -0
- data/script/core_ci +9 -0
- data/script/plugins_ci +9 -0
- data/script/storefront_ci +9 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +38 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/bin/yarn +11 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +29 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +54 -0
- data/test/dummy/config/environments/production.rb +91 -0
- data/test/dummy/config/environments/test.rb +44 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +14 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/puma.rb +56 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +32 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/db/seeds.rb +2 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/package.json +5 -0
- data/test/javascripts/fixtures/payloads.js +232 -0
- data/test/javascripts/fixtures/stubs.js +56 -0
- data/test/javascripts/segment_analytics_spec.js +311 -0
- data/test/javascripts/spec_helper.js +12 -0
- data/test/teaspoon_env.rb +6 -0
- data/test/test_helper.rb +10 -0
- data/workarea-segment_analytics.gemspec +19 -0
- 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
|
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,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
|
data/script/admin_ci
ADDED
data/script/ci
ADDED
data/script/core_ci
ADDED
data/script/plugins_ci
ADDED
data/test/dummy/Rakefile
ADDED
|
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
|
+
*/
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= yield %>
|
data/test/dummy/bin/rake
ADDED
|
@@ -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
|
data/test/dummy/bin/yarn
ADDED
|
@@ -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,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
|
+
|