forked from railslove/rack-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacebook_pixel_spec.rb
More file actions
73 lines (63 loc) · 2.1 KB
/
facebook_pixel_spec.rb
File metadata and controls
73 lines (63 loc) · 2.1 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
RSpec.describe Rack::Tracker::FacebookPixel do
def env
{ 'PIXEL_ID' => 'DYNAMIC_PIXEL_ID' }
end
it 'will be placed in the body' do
expect(described_class.position).to eq(:body)
expect(described_class.new(env).position).to eq(:body)
end
describe 'with static id' do
subject { described_class.new(env, id: 'PIXEL_ID').render }
it 'will push the tracking events to the queue' do
expect(subject).to match(%r{fbq\('init', 'PIXEL_ID'\)})
end
it 'will add the noscript fallback' do
expect(subject).to match(%r{https://www.facebook.com/tr\?id=PIXEL_ID&ev=PageView&noscript=1})
end
end
describe 'with dynamic id' do
subject { described_class.new(env, id: lambda { |env| env['PIXEL_ID'] }).render }
it 'will push the tracking events to the queue' do
expect(subject).to match(%r{fbq\('init', 'DYNAMIC_PIXEL_ID'\)})
end
it 'will add the noscript fallback' do
expect(subject).to match(%r{https://www.facebook.com/tr\?id=DYNAMIC_PIXEL_ID&ev=PageView&noscript=1})
end
end
describe 'with events' do
def env
{
'tracker' => {
'facebook_pixel' =>
[
{
'type' => 'Purchase',
'class_name' => 'Track',
'options' =>
{
'value' => '23',
'currency' => 'EUR'
}
},{
'type' => 'FrequentShopper',
'class_name' => 'TrackCustom',
'options' =>
{
'purchases' => 8,
'category' => 'Sport'
}
}
]
}
}
end
subject { described_class.new(env).render }
it 'will push the tracking events to the queue' do
expect(subject).to match(%r{"track", "Purchase", \{"value":"23","currency":"EUR"\}})
expect(subject).to match(%r{"trackCustom", "FrequentShopper", \{"purchases":8,"category":"Sport"\}})
end
it 'will add the noscript fallback' do
expect(subject).to match(%r{https://www.facebook.com/tr\?id=&ev=PageView&noscript=1})
end
end
end