Sha256: aacd52a51e360d81a6f19b2c9147e5210e98f04974b9a0daff87676a8771e9fe

Contents?: true

Size: 1.08 KB

Versions: 25

Compression:

Stored size: 1.08 KB

Contents

module Ahoy
  module Helper
    def amp_event(name, properties = {})
      url = Ahoy::Engine.routes.url_helpers.events_url(
        url_options.slice(:host, :port, :protocol).merge(
          name: name,
          properties: properties,
          screen_width: "SCREEN_WIDTH",
          screen_height: "SCREEN_HEIGHT",
          platform: "Web",
          landing_page: "AMPDOC_URL",
          referrer: "DOCUMENT_REFERRER",
          random: "RANDOM"
        )
      )
      url = "#{url}&visit_token=${clientId(ahoy_visit)}&visitor_token=${clientId(ahoy_visitor)}"

      content_tag "amp-analytics" do
        content_tag "script", type: "application/json" do
          json_escape({
            requests: {
              pageview: url
            },
            triggers: {
              trackPageview: {
                on: "visible",
                request: "pageview"
              }
            },
            transport: {
              beacon: true,
              xhrpost: true,
              image: false
            }
          }.to_json).html_safe
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ahoy_matey-5.3.0 lib/ahoy/helper.rb
ahoy_matey-5.2.1 lib/ahoy/helper.rb
ahoy_matey-5.2.0 lib/ahoy/helper.rb
ahoy_matey-5.1.0 lib/ahoy/helper.rb
ahoy_matey-5.0.2 lib/ahoy/helper.rb
ahoy_matey-5.0.1 lib/ahoy/helper.rb
ahoy_matey-5.0.0 lib/ahoy/helper.rb
ahoy_matey-4.2.1 lib/ahoy/helper.rb
ahoy_matey-4.2.0 lib/ahoy/helper.rb
ahoy_matey-4.1.0 lib/ahoy/helper.rb
ahoy_matey-4.0.3 lib/ahoy/helper.rb
ahoy_matey-4.0.2 lib/ahoy/helper.rb
ahoy_matey-4.0.1 lib/ahoy/helper.rb
ahoy_matey-4.0.0 lib/ahoy/helper.rb
ahoy_matey-3.3.0 lib/ahoy/helper.rb
ahoy_matey-3.2.0 lib/ahoy/helper.rb
ahoy_matey-3.1.0 lib/ahoy/helper.rb
ahoy_matey-3.0.5 lib/ahoy/helper.rb
ahoy_matey-3.0.4 lib/ahoy/helper.rb
ahoy_matey-3.0.3 lib/ahoy/helper.rb