forked from railslove/rack-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle_analytics_integration_spec.rb
More file actions
46 lines (39 loc) · 1.78 KB
/
google_analytics_integration_spec.rb
File metadata and controls
46 lines (39 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require 'support/capybara_app_helper'
RSpec.describe "Google Analytics Integration" do
before do
setup_app(action: :google_analytics) do |tracker|
tracker.handler :google_analytics, { tracker: 'U-XXX-Y' }
end
visit '/'
end
subject { page }
it "embeds the script tag with tracking event from the controller action" do
expect(page.find("head")).to have_content('ga("ecommerce:addItem",{"id":"1234","name":"Fluffy Pink Bunnies","sku":"DD23444","category":"Party Toys","price":"11.99","quantity":"1"})')
expect(page.find("head")).to have_content('ga("ecommerce:addTransaction",{"id":"1234","affiliation":"Acme Clothing","revenue":"11.99","shipping":"5","tax":"1.29"})')
expect(page.find("head")).to have_content('ga("send",{"hitType":"event","eventCategory":"button","eventAction":"click","eventLabel":"nav-buttons","eventValue":"X"})')
end
describe 'adjust tracker position via options' do
before do
setup_app(action: :google_analytics) do |tracker|
tracker.handler :google_analytics, { tracker: 'U-XXX-Y', position: :body }
end
visit '/'
end
it "will be placed in the specified tag" do
expect(page.find("head")).to_not have_content('U-XXX-Y')
expect(page.find("body")).to have_content('ga("ecommerce:addItem",{"id":"1234","name":"Fluffy Pink Bunnies","sku":"DD23444","category":"Party Toys","price":"11.99","quantity":"1"})')
end
end
describe 'values escaping' do
before do
setup_app(action: :google_analytics) do |tracker|
tracker.handler :google_analytics, { tracker: 'U-XXX-Y' }
end
visit '/'
end
it "will not mess up the html" do
expect(page.find('head')).to have_content('U-XXX-Y')
expect(page.find('head')).to have_content %q{Some escaped \\'value}
end
end
end