Sha256: 19d9097674c9ecca5897ea7de6d6688c538275d112933aa0e18818d64410858e

Contents?: true

Size: 1.66 KB

Versions: 23

Compression:

Stored size: 1.66 KB

Contents

RSpec.describe Rack::Tracker::Facebook do
  describe Rack::Tracker::Facebook::Event do

    subject { described_class.new({id: 'id', foo: 'bar'}) }

    describe '#write' do
      specify { expect(subject.write).to eq(['track', 'id', {foo: 'bar'}].to_json) }
    end
  end

  def env
    {}
  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 custom audience id' do
    subject { described_class.new(env, custom_audience: 'custom_audience_id').render }

    it 'will push the tracking events to the queue' do
      expect(subject).to match(%r{window._fbq.push\(\["addPixelId", "custom_audience_id"\]\)})
      expect(subject).to match(%r{window._fbq.push\(\["track", "PixelInitialized", \{\}\]\)})
    end

    it 'will add the noscript fallback' do
      expect(subject).to match(%r{https://www.facebook.com/tr\?id=custom_audience_id&ev=PixelInitialized})
    end
  end

  describe 'with events' do
    def env
      {
        'tracker' => {
        'facebook' =>
          [
            {
              'id' => '123456789',
              'value' => '23',
              'currency' => 'EUR',
              'class_name' => 'Event'
            }
          ]
        }
      }
    end
    subject { described_class.new(env).render }

    it 'will push the tracking events to the queue' do
      expect(subject).to match(%r{\["track","123456789",\{"value":"23","currency":"EUR"\}\]})
    end

    it 'will add the noscript fallback' do
      expect(subject).to match(%r{https://www.facebook.com/offsite_event.php\?id=123456789&value=23&currency=EUR})
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rack-tracker-1.13.0 spec/handler/facebook_spec.rb
rack-tracker-1.12.1 spec/handler/facebook_spec.rb
rack-tracker-1.12.0 spec/handler/facebook_spec.rb
rack-tracker-1.11.2 spec/handler/facebook_spec.rb
rack-tracker-1.11.1 spec/handler/facebook_spec.rb
rack-tracker-1.11.0 spec/handler/facebook_spec.rb
rack-tracker-1.10.0 spec/handler/facebook_spec.rb
rack-tracker-1.9.0 spec/handler/facebook_spec.rb
rack-tracker-1.8.0 spec/handler/facebook_spec.rb
rack-tracker-1.7.0 spec/handler/facebook_spec.rb
rack-tracker-1.6.0 spec/handler/facebook_spec.rb
rack-tracker-1.5.0 spec/handler/facebook_spec.rb
rack-tracker-1.4.0 spec/handler/facebook_spec.rb
rack-tracker-1.3.1 spec/handler/facebook_spec.rb
rack-tracker-1.3.0 spec/handler/facebook_spec.rb
rack-tracker-1.2.0 spec/handler/facebook_spec.rb
rack-tracker-1.1.0 spec/handler/facebook_spec.rb
rack-tracker-1.0.2 spec/handler/facebook_spec.rb
rack-tracker-1.0.1 spec/handler/facebook_spec.rb
rack-tracker-1.0.0 spec/handler/facebook_spec.rb