Sha256: 425df3c664d9b010a2b2f29271c650cd5a6d15b259ffc052621cdb87321fa054

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

RSpec.describe Rack::Tracker::GoogleTagManager do

  def env
    {
      misc: 'foobar',
      user_id: '123'
    }
  end

  it 'will be placed in the body by default' do
    expect(described_class.position).to eq(:body)
    expect(described_class.new(env).position).to eq(:body)
    expect(described_class.new(env, position: :head).position).to eq(:head)
  end

  describe "with events" do
    describe "default" do
      def env
        {'tracker' => {
          'google_tag_manager' => [
            { 'class_name' => 'Push', 'page' => 'Cart', 'price' => 50, 'content_ids' => ['sku_1', 'sku_2', 'sku_3'] }
          ]
        }}
      end

      subject { described_class.new(env, container: 'somebody').render }
      it "will show events" do
        expect(subject).to match(%r{"page":"Cart","price":50,"content_ids":\["sku_1","sku_2","sku_3"\]})
      end
    end
  end

  describe "with dynamic tracker" do
    subject { described_class.new(env, { container: lambda { |env| return env[:misc] }}).render }

    it 'will call tracker lambdas to obtain tracking codes' do
      expect(subject).to match(%r{\(window,document,'script','dataLayer','foobar'\)})
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rack-tracker-1.2.0 spec/handler/google_tag_manager_spec.rb
rack-tracker-1.1.0 spec/handler/google_tag_manager_spec.rb