Sha256: 79c892e425b140985f0149f51a6a13b464d040e5f8187ad1d335fa47a210c383

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'support/capybara_app_helper'

RSpec.describe "Google Tag Manager Integration" do
  before do
    setup_app(action: :google_tag_manager) do |tracker|
      tracker.handler :google_tag_manager, { container: 'GTM-ABCDEF' }
    end
  end

  subject { page }

  it "embeds the script tag with tracking event from the controller action" do
    visit '/'
    expect(page.find("head")).to have_content 'GTM-ABCDEF'
    expect(page.find("head")).to have_content "dataLayer.push({\"click\":\"X\",\"price\":10}, {\"transactionProducts\":[{\"sku\":\"DD44\",\"name\":\"T-shirt\"},{\"sku\":\"DD66\",\"name\":\"Jeans\"}]});"
    expect(page.find("body")).to have_xpath '//body/noscript/iframe[@src="https://www.googletagmanager.com/ns.html?id=GTM-ABCDEF"]'
  end

  it "does not inject a dataLayer if no events are set " do
    visit '/?no_events=true'
    expect(page.find("head")).to have_content 'GTM-ABCDEF'
    expect(page.find("head")).to_not have_content "dataLayer.push("
    expect(page.find("body")).to have_xpath '//body/noscript/iframe[@src="https://www.googletagmanager.com/ns.html?id=GTM-ABCDEF"]'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-tracker-1.3.1 spec/integration/google_tag_manager_integration_spec.rb