Sha256: a93df7c56e79954aa8bd383479f7a50d2a515169f8bebc6b7b3db588f6667a71

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

<% if container %>
  <script>
    dataLayer = [];

    <% if options[:turbolinks] %>
      document.addEventListener('turbolinks:load', function(event) {
        var url = event.data.url;
        dataLayer.push({'event':'pageView','virtualUrl': url});
      });
      document.addEventListener('turbo:load', function(event) {
        var url = event.detail.url;
        dataLayer.push({'event':'pageView','virtualUrl': url});
      });
    <% end %>
  </script>

  <% if events.any? %>
    <script>
      <%# Generates unique script tags to ensure that turbo/turbolinks include %>
      <%# them in the document even if the same event happens more than once %>
      // Unique Script ID: <%= SecureRandom.base64(8) %>
      dataLayer.push(<%= events.map(&:write).join(', ') %>);
    </script>
  <% end %>

  <script>
  (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
  'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  })(window,document,'script','dataLayer','<%= container %>');</script>
<% end %>


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-tracker-1.13.0 lib/rack/tracker/google_tag_manager/template/google_tag_manager_head.erb