From d2c6afc689656143886cf2ef53d101612a42aa28 Mon Sep 17 00:00:00 2001
From: Abby Sassel <3883855+sassela@users.noreply.github.com>
Date: Wed, 31 Jul 2019 08:49:47 +0200
Subject: [PATCH 01/21] Add support for Drift (#139)
* Add support for Drift
* Add usage docs
---
README.md | 9 ++++++++
lib/rack/tracker.rb | 1 +
lib/rack/tracker/drift/drift.rb | 2 ++
lib/rack/tracker/drift/template/drift.erb | 26 ++++++++++++++++++++++
spec/handler/drift_spec.rb | 10 +++++++++
spec/integration/drift_integration_spec.rb | 18 +++++++++++++++
spec/support/metal_controller.rb | 4 ++++
7 files changed, 70 insertions(+)
create mode 100644 lib/rack/tracker/drift/drift.rb
create mode 100644 lib/rack/tracker/drift/template/drift.erb
create mode 100644 spec/handler/drift_spec.rb
create mode 100644 spec/integration/drift_integration_spec.rb
diff --git a/README.md b/README.md
index 515465c..a0fdd89 100644
--- a/README.md
+++ b/README.md
@@ -604,6 +604,15 @@ config.middleware.use(Rack::Tracker) do
end
```
+### Drift
+
+[Drift](https://www.drift.com/)
+
+```
+config.middleware.use(Rack::Tracker) do
+ handler :drift, account_id: 'DRIFT_ID'
+end
+```
### Custom Handlers
diff --git a/lib/rack/tracker.rb b/lib/rack/tracker.rb
index 6cce2fb..2d3dc91 100644
--- a/lib/rack/tracker.rb
+++ b/lib/rack/tracker.rb
@@ -25,6 +25,7 @@
require "rack/tracker/hotjar/hotjar"
require "rack/tracker/bing/bing"
require "rack/tracker/hubspot/hubspot"
+require "rack/tracker/drift/drift"
module Rack
class Tracker
diff --git a/lib/rack/tracker/drift/drift.rb b/lib/rack/tracker/drift/drift.rb
new file mode 100644
index 0000000..fb7fe34
--- /dev/null
+++ b/lib/rack/tracker/drift/drift.rb
@@ -0,0 +1,2 @@
+class Rack::Tracker::Drift < Rack::Tracker::Handler
+end
diff --git a/lib/rack/tracker/drift/template/drift.erb b/lib/rack/tracker/drift/template/drift.erb
new file mode 100644
index 0000000..1b0d12a
--- /dev/null
+++ b/lib/rack/tracker/drift/template/drift.erb
@@ -0,0 +1,26 @@
+
diff --git a/spec/handler/drift_spec.rb b/spec/handler/drift_spec.rb
new file mode 100644
index 0000000..5f96374
--- /dev/null
+++ b/spec/handler/drift_spec.rb
@@ -0,0 +1,10 @@
+RSpec.describe Rack::Tracker::Drift do
+ def env
+ { foo: 'bar' }
+ end
+
+ it 'will be placed in the head' do
+ expect(described_class.position).to eq(:head)
+ expect(described_class.new(env).position).to eq(:head)
+ end
+end
diff --git a/spec/integration/drift_integration_spec.rb b/spec/integration/drift_integration_spec.rb
new file mode 100644
index 0000000..3192d2c
--- /dev/null
+++ b/spec/integration/drift_integration_spec.rb
@@ -0,0 +1,18 @@
+require 'support/capybara_app_helper'
+
+RSpec.describe 'Drift Integration' do
+ before do
+ setup_app(action: :drift) do |tracker|
+ tracker.handler :drift, account_id: 'DRIFT_ID'
+ end
+
+ visit '/'
+ end
+
+ subject { page }
+
+ it 'embeds the script with account_id' do
+ expect(page.find('script')).to have_content('js.driftt.com')
+ expect(page.find('script')).to have_content('DRIFT_ID')
+ end
+end
diff --git a/spec/support/metal_controller.rb b/spec/support/metal_controller.rb
index 13f0a61..644b6b7 100644
--- a/spec/support/metal_controller.rb
+++ b/spec/support/metal_controller.rb
@@ -124,4 +124,8 @@ def hubspot
def bing
render "metal/index"
end
+
+ def drift
+ render "metal/index"
+ end
end
From 21e6d1c27be5f33ce988b209ee29c03ba3742f92 Mon Sep 17 00:00:00 2001
From: Marco Schaden
Date: Wed, 31 Jul 2019 08:56:07 +0200
Subject: [PATCH 02/21] fresh new release with new integration
---
CHANGELOG.md | 4 ++++
lib/rack/tracker/version.rb | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 063ede4..6d63fc4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 1.11.0
+
+ * [ENHANCEMENT] Add support for Drift #139 (thx @sassela)
+
# 1.10.0
* [ENHANCEMENT] Hubspot integration #136 (thx @ChrisCoffey)
diff --git a/lib/rack/tracker/version.rb b/lib/rack/tracker/version.rb
index b8a0953..dc87117 100644
--- a/lib/rack/tracker/version.rb
+++ b/lib/rack/tracker/version.rb
@@ -1,5 +1,5 @@
module Rack
class Tracker
- VERSION = '1.10.0'
+ VERSION = '1.11.0'
end
end
From 997b90fa6884d6ff6e8368144d782c6a3a70a145 Mon Sep 17 00:00:00 2001
From: Abby Sassel <3883855+sassela@users.noreply.github.com>
Date: Thu, 1 Aug 2019 10:36:15 +0100
Subject: [PATCH 03/21] Uncaught ReferenceError Fix: wrap Drift account ID in
quotes (#140)
* Uncaught ReferenceError Fix: wrap Drift account ID in quotes
* Update Drift integration test to verify fix
---
lib/rack/tracker/drift/template/drift.erb | 2 +-
spec/integration/drift_integration_spec.rb | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/rack/tracker/drift/template/drift.erb b/lib/rack/tracker/drift/template/drift.erb
index 1b0d12a..e046404 100644
--- a/lib/rack/tracker/drift/template/drift.erb
+++ b/lib/rack/tracker/drift/template/drift.erb
@@ -22,5 +22,5 @@
}
}();
drift.SNIPPET_VERSION = '0.3.1';
-drift.load(<%= options[:account_id] %>);
+drift.load('<%= options[:account_id] %>');
diff --git a/spec/integration/drift_integration_spec.rb b/spec/integration/drift_integration_spec.rb
index 3192d2c..498538f 100644
--- a/spec/integration/drift_integration_spec.rb
+++ b/spec/integration/drift_integration_spec.rb
@@ -13,6 +13,6 @@
it 'embeds the script with account_id' do
expect(page.find('script')).to have_content('js.driftt.com')
- expect(page.find('script')).to have_content('DRIFT_ID')
+ expect(page.find('script')).to have_content('drift.load(\'DRIFT_ID\')')
end
end
From a9f9eda5e40d4c12ea8bea1e781fb91ec3d41763 Mon Sep 17 00:00:00 2001
From: Marco Schaden
Date: Thu, 1 Aug 2019 19:55:10 +0200
Subject: [PATCH 04/21] bugfix release
---
CHANGELOG.md | 4 ++++
lib/rack/tracker/version.rb | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6d63fc4..885993c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 1.11.1
+
+ * [BUGFIX] Uncaught ReferenceError Fix: wrap Drift account ID in quotes #140 (thx @sassela)
+
# 1.11.0
* [ENHANCEMENT] Add support for Drift #139 (thx @sassela)
diff --git a/lib/rack/tracker/version.rb b/lib/rack/tracker/version.rb
index dc87117..ce6f23f 100644
--- a/lib/rack/tracker/version.rb
+++ b/lib/rack/tracker/version.rb
@@ -1,5 +1,5 @@
module Rack
class Tracker
- VERSION = '1.11.0'
+ VERSION = '1.11.1'
end
end
From 0616d5d088ded1541983688cb16367c6c6e0529c Mon Sep 17 00:00:00 2001
From: Chris Coffey
Date: Sun, 25 Aug 2019 12:39:26 -0400
Subject: [PATCH 05/21] Allow disabling explicit pageview sends for GA (#141)
* Enable disabling explicit pageview sends for GA
* Bump version and update Changelog+Docs
---
CHANGELOG.md | 4 ++++
README.md | 1 +
.../tracker/google_analytics/google_analytics.rb | 5 +++++
.../template/google_analytics.erb | 2 +-
lib/rack/tracker/version.rb | 2 +-
spec/handler/google_analytics_spec.rb | 16 ++++++++++++++++
6 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 885993c..6523463 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 1.11.2
+
+ * [ENHANCEMENT] Allows disabling the Google Analytics pageview send. Defaults to true.
+
# 1.11.1
* [BUGFIX] Uncaught ReferenceError Fix: wrap Drift account ID in quotes #140 (thx @sassela)
diff --git a/README.md b/README.md
index a0fdd89..469998a 100644
--- a/README.md
+++ b/README.md
@@ -140,6 +140,7 @@ end
* `:enhanced_ecommerce` - Enables [Enhanced Ecommerce Tracking](https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce)
* `:optimize` - pass [Google Optimize container ID](https://support.google.com/360suite/optimize/answer/6262084#example-combined-snippet) as value (e.g. `optimize: 'GTM-1234'`).
* `:pageview_url_script` - a String containing a custom js script evaluating to the url that shoudl be given to the pageview event. Default to `window.location.pathname + window.location.search`.
+* `:explicit_pageview` - A boolean that controls whether to send the `pageview` event on pageload. This defaults to true.
#### Events
diff --git a/lib/rack/tracker/google_analytics/google_analytics.rb b/lib/rack/tracker/google_analytics/google_analytics.rb
index a18d1e0..f33663b 100644
--- a/lib/rack/tracker/google_analytics/google_analytics.rb
+++ b/lib/rack/tracker/google_analytics/google_analytics.rb
@@ -2,6 +2,11 @@ class Rack::Tracker::GoogleAnalytics < Rack::Tracker::Handler
self.allowed_tracker_options = [:cookie_domain, :user_id]
+ def initialize(env, options = {})
+ options[:explicit_pageview] = true if !options.has_key?(:explicit_pageview)
+ super(env, options)
+ end
+
class Send < OpenStruct
def initialize(attrs = {})
attrs.reverse_merge!(type: 'event')
diff --git a/lib/rack/tracker/google_analytics/template/google_analytics.erb b/lib/rack/tracker/google_analytics/template/google_analytics.erb
index 000ff7c..673a671 100644
--- a/lib/rack/tracker/google_analytics/template/google_analytics.erb
+++ b/lib/rack/tracker/google_analytics/template/google_analytics.erb
@@ -38,7 +38,7 @@
<% if options[:ecommerce] && ecommerce_events.any? %>
ga('ecommerce:send');
<% end %>
-<% if tracker %>
+<% if tracker && options[:explicit_pageview] %>
ga('send', 'pageview', <%= pageview_url_script %>);
<% end %>
diff --git a/lib/rack/tracker/version.rb b/lib/rack/tracker/version.rb
index ce6f23f..371b0c0 100644
--- a/lib/rack/tracker/version.rb
+++ b/lib/rack/tracker/version.rb
@@ -1,5 +1,5 @@
module Rack
class Tracker
- VERSION = '1.11.1'
+ VERSION = '1.11.2'
end
end
diff --git a/spec/handler/google_analytics_spec.rb b/spec/handler/google_analytics_spec.rb
index 5d46e8d..6951a02 100644
--- a/spec/handler/google_analytics_spec.rb
+++ b/spec/handler/google_analytics_spec.rb
@@ -284,5 +284,21 @@ def env
expect(subject.pageview_url_script).to eql ("{ 'page': location.pathname + location.search + location.hash }")
end
end
+
+ context 'with explicit_pageview disabled' do
+ subject { described_class.new(env, {tracker: 'afake', explicit_pageview: false }).render }
+
+ it 'does not send a pageview event' do
+ expect(subject).not_to include %q{ga('send', 'pageview',}
+ end
+ end
+
+ context 'defaults to sending the pageview event' do
+ subject { described_class.new(env, {tracker: 'afake'}).render }
+
+ it 'does not send a pageview event' do
+ expect(subject).to include "ga('send', 'pageview'"
+ end
+ end
end
end
From 8695ac65036017217722a7a428a5871deb297353 Mon Sep 17 00:00:00 2001
From: Marco Schaden
Date: Sun, 25 Aug 2019 18:40:59 +0200
Subject: [PATCH 06/21] version up
---
CHANGELOG.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6523463..480708d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,6 @@
-# 1.11.2
+# 1.12.0
- * [ENHANCEMENT] Allows disabling the Google Analytics pageview send. Defaults to true.
+ * [ENHANCEMENT] Allows disabling the Google Analytics pageview send. Defaults to true #131 (thx @ChrisCoffey)
# 1.11.1
From f554f692be869ff937a4ea61eb8907e5630915f4 Mon Sep 17 00:00:00 2001
From: Marco Schaden
Date: Sun, 25 Aug 2019 19:23:40 +0200
Subject: [PATCH 07/21] =?UTF-8?q?=F0=9F=99=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CHANGELOG.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 480708d..e444877 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,4 @@
-# 1.12.0
+# 1.11.2
* [ENHANCEMENT] Allows disabling the Google Analytics pageview send. Defaults to true #131 (thx @ChrisCoffey)
From 09b46c67a6fc31109ae81a9c9ae757628727899e Mon Sep 17 00:00:00 2001
From: glaszig
Date: Mon, 30 Sep 2019 09:20:33 +0200
Subject: [PATCH 08/21] test on rails 6.0 (#144)
* test on rails 6.0
* do not test rails 6.0 on ruby < 2.5 on travis
* test on jruby-9.2.7.0, do not test rails 6 on jruby-9.1.10.0
---
.travis.yml | 10 ++++++++++
Gemfile.rails-6.0 | 6 ++++++
2 files changed, 16 insertions(+)
create mode 100644 Gemfile.rails-6.0
diff --git a/.travis.yml b/.travis.yml
index b754765..3c8e02f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,8 +6,18 @@ rvm:
- 2.5.3
- 2.6.1
- jruby-9.1.10.0
+ - jruby-9.2.7.0
gemfile:
- Gemfile
- Gemfile.rails-3.2
- Gemfile.rails-4.2
- Gemfile.rails-5.2
+ - Gemfile.rails-6.0
+matrix:
+ exclude:
+ - rvm: 2.3.8
+ gemfile: Gemfile.rails-6.0
+ - rvm: 2.4.5
+ gemfile: Gemfile.rails-6.0
+ - rvm: jruby-9.1.10.0
+ gemfile: Gemfile.rails-6.0
diff --git a/Gemfile.rails-6.0 b/Gemfile.rails-6.0
new file mode 100644
index 0000000..ee3fb05
--- /dev/null
+++ b/Gemfile.rails-6.0
@@ -0,0 +1,6 @@
+source "https://rubygems.org"
+
+gemspec
+
+gem 'activesupport', '~> 6.0.0'
+gem 'actionpack', '~> 6.0.0'
From c10ea3ecbe4e8bab6af07a0bed9260d6bfa7c1c4 Mon Sep 17 00:00:00 2001
From: Mohan Zhang
Date: Fri, 8 Nov 2019 04:46:01 -0400
Subject: [PATCH 09/21] Add support for Heap (#147)
---
README.md | 12 ++++++++++++
lib/rack/tracker.rb | 1 +
lib/rack/tracker/heap/heap.rb | 2 ++
lib/rack/tracker/heap/template/heap.erb | 4 ++++
lib/rack/tracker/version.rb | 2 +-
spec/handler/heap_spec.rb | 10 ++++++++++
spec/integration/heap_integration_spec.rb | 17 +++++++++++++++++
spec/support/metal_controller.rb | 4 ++++
8 files changed, 51 insertions(+), 1 deletion(-)
create mode 100644 lib/rack/tracker/heap/heap.rb
create mode 100644 lib/rack/tracker/heap/template/heap.erb
create mode 100644 spec/handler/heap_spec.rb
create mode 100644 spec/integration/heap_integration_spec.rb
diff --git a/README.md b/README.md
index 469998a..e1b7927 100644
--- a/README.md
+++ b/README.md
@@ -615,6 +615,18 @@ config.middleware.use(Rack::Tracker) do
end
```
+### Heap
+
+[Heap](https://heap.io/). Heap has Projects (e.g. "Main") which have multiple
+Environments (e.g. "Production" or "Development"). `env_id` is therefore the numerical ID
+that represents the Environment. See Settings -> Projects -> Environments in your dashboard.
+
+```
+config.middleware.use(Rack::Tracker) do
+ handler :heap, env_id: 'HEAP_ID'
+end
+```
+
### Custom Handlers
Tough we give you handlers for a few tracking services right out of the box, you might
diff --git a/lib/rack/tracker.rb b/lib/rack/tracker.rb
index 2d3dc91..ed0a07e 100644
--- a/lib/rack/tracker.rb
+++ b/lib/rack/tracker.rb
@@ -26,6 +26,7 @@
require "rack/tracker/bing/bing"
require "rack/tracker/hubspot/hubspot"
require "rack/tracker/drift/drift"
+require "rack/tracker/heap/heap"
module Rack
class Tracker
diff --git a/lib/rack/tracker/heap/heap.rb b/lib/rack/tracker/heap/heap.rb
new file mode 100644
index 0000000..dac9efb
--- /dev/null
+++ b/lib/rack/tracker/heap/heap.rb
@@ -0,0 +1,2 @@
+class Rack::Tracker::Heap < Rack::Tracker::Handler
+end
diff --git a/lib/rack/tracker/heap/template/heap.erb b/lib/rack/tracker/heap/template/heap.erb
new file mode 100644
index 0000000..b3ac665
--- /dev/null
+++ b/lib/rack/tracker/heap/template/heap.erb
@@ -0,0 +1,4 @@
+
diff --git a/lib/rack/tracker/version.rb b/lib/rack/tracker/version.rb
index 371b0c0..fb24a29 100644
--- a/lib/rack/tracker/version.rb
+++ b/lib/rack/tracker/version.rb
@@ -1,5 +1,5 @@
module Rack
class Tracker
- VERSION = '1.11.2'
+ VERSION = '1.12.0'
end
end
diff --git a/spec/handler/heap_spec.rb b/spec/handler/heap_spec.rb
new file mode 100644
index 0000000..7e48df4
--- /dev/null
+++ b/spec/handler/heap_spec.rb
@@ -0,0 +1,10 @@
+RSpec.describe Rack::Tracker::Heap do
+ def env
+ { foo: 'bar' }
+ end
+
+ it 'will be placed in the head' do
+ expect(described_class.position).to eq(:head)
+ expect(described_class.new(env).position).to eq(:head)
+ end
+end
diff --git a/spec/integration/heap_integration_spec.rb b/spec/integration/heap_integration_spec.rb
new file mode 100644
index 0000000..ff866a1
--- /dev/null
+++ b/spec/integration/heap_integration_spec.rb
@@ -0,0 +1,17 @@
+require 'support/capybara_app_helper'
+
+RSpec.describe "Heap Integration" do
+ before do
+ setup_app(action: :heap) do |tracker|
+ tracker.handler :heap, { env_id: '12341234' }
+ end
+
+ visit '/'
+ end
+
+ subject { page }
+
+ it 'embeds the script with site_id' do
+ expect(page).to have_content('heap.load("12341234");')
+ end
+end
diff --git a/spec/support/metal_controller.rb b/spec/support/metal_controller.rb
index 644b6b7..f22447e 100644
--- a/spec/support/metal_controller.rb
+++ b/spec/support/metal_controller.rb
@@ -128,4 +128,8 @@ def bing
def drift
render "metal/index"
end
+
+ def heap
+ render "metal/index"
+ end
end
From f3d4e65dee9527136c7613940f5cee16fba91f88 Mon Sep 17 00:00:00 2001
From: Marco Schaden
Date: Thu, 14 Nov 2019 10:21:19 +0100
Subject: [PATCH 10/21] add integration spec for callable behaviour
---
.../template/google_analytics.erb | 4 ++--
spec/integration/rails_integration_spec.rb | 23 +++++++++++++------
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/lib/rack/tracker/google_analytics/template/google_analytics.erb b/lib/rack/tracker/google_analytics/template/google_analytics.erb
index 673a671..5aa0159 100644
--- a/lib/rack/tracker/google_analytics/template/google_analytics.erb
+++ b/lib/rack/tracker/google_analytics/template/google_analytics.erb
@@ -1,5 +1,5 @@
-
+<% end %>
diff --git a/spec/integration/rails_integration_spec.rb b/spec/integration/rails_integration_spec.rb
index 368efbe..ec932f0 100644
--- a/spec/integration/rails_integration_spec.rb
+++ b/spec/integration/rails_integration_spec.rb
@@ -1,10 +1,19 @@
require 'support/capybara_app_helper'
RSpec.describe "Rails Integration" do
+ let(:callable_skip_inject) do
+ lambda do |env|
+ # check for anything in the env hash to decide
+ # if you return the `tracker id` or `nil` to skip injection
+ nil
+ end
+ end
+
before do
setup_app(action: :index) do |tracker|
tracker.handler :track_all_the_things, { custom_key: 'SomeKey123' }
tracker.handler :another_handler, { custom_key: 'AnotherKey42' }
+ tracker.handler :google_analytics, { tracker: callable_skip_inject }
end
visit '/'
@@ -17,15 +26,15 @@
Metal Layout
-
-
+
+
welcome to metal#index
-
+