diff --git a/.gitignore b/.gitignore index a955cfa..554a6d2 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ test/tmp test/version_tmp tmp .DS_Store +.vscode diff --git a/lib/rack/tracker/facebook_pixel/facebook_pixel.rb b/lib/rack/tracker/facebook_pixel/facebook_pixel.rb index f6015dd..671653a 100644 --- a/lib/rack/tracker/facebook_pixel/facebook_pixel.rb +++ b/lib/rack/tracker/facebook_pixel/facebook_pixel.rb @@ -7,6 +7,10 @@ def write options.present? ? type_to_json << options_to_json : type_to_json end + def with_event_id + ", {\"eventID\":\"#{event_id}\"}" if event_id.present? + end + private def type_to_json diff --git a/lib/rack/tracker/facebook_pixel/template/facebook_pixel.erb b/lib/rack/tracker/facebook_pixel/template/facebook_pixel.erb index 2901c52..fd755d5 100644 --- a/lib/rack/tracker/facebook_pixel/template/facebook_pixel.erb +++ b/lib/rack/tracker/facebook_pixel/template/facebook_pixel.erb @@ -18,7 +18,7 @@ <% if events.any? %> <% end %> diff --git a/lib/rack/tracker/google_global/template/google_global.erb b/lib/rack/tracker/google_global/template/google_global.erb index 9103419..9b74b21 100644 --- a/lib/rack/tracker/google_global/template/google_global.erb +++ b/lib/rack/tracker/google_global/template/google_global.erb @@ -1,5 +1,5 @@ <% if trackers.any? %> - + <% end %> - - diff --git a/lib/rack/tracker/version.rb b/lib/rack/tracker/version.rb index 7d12101..51122c1 100644 --- a/lib/rack/tracker/version.rb +++ b/lib/rack/tracker/version.rb @@ -1,5 +1,5 @@ module Rack class Tracker - VERSION = '1.12.1' + VERSION = '1.12.2' end end diff --git a/spec/handler/facebook_pixel_spec.rb b/spec/handler/facebook_pixel_spec.rb index 9716529..2be26e9 100644 --- a/spec/handler/facebook_pixel_spec.rb +++ b/spec/handler/facebook_pixel_spec.rb @@ -70,4 +70,31 @@ def env expect(subject).to match(%r{https://www.facebook.com/tr\?id=&ev=PageView&noscript=1}) end end + + describe 'with event_id' do + def env + { + 'tracker' => { + 'facebook_pixel' => + [ + { + 'type' => 'Purchase', + 'class_name' => 'Track', + 'options' => + { + 'value' => '23', + 'currency' => 'EUR' + }, + 'event_id' => '42' + } + ] + } + } + end + subject { described_class.new(env).render } + + it 'will push the tracking event with the eventID param' do + expect(subject).to match(%r{"track", "Purchase", \{"value":"23","currency":"EUR"\}, \{"eventID":"42"\}}) + end + end end