Sha256: 78f979ff8ed432c0d37b41b27c89053a866ba53bd8fce72d299fe0f0a56d317e

Contents?: true

Size: 831 Bytes

Versions: 6

Compression:

Stored size: 831 Bytes

Contents

class Rack::Tracker::GoogleTagManager < Rack::Tracker::Handler

  class Push < OpenStruct

    def write
      "'#{event[:name]}': '#{event[:value]}'"
    end

    def event
      attributes.stringify_values.compact
    end

    def attributes
      to_h.slice(:name, :value)
    end
  end

  # It is strongly recommended to put the google_tag_manager snippet only in the body tag
  # https://developers.google.com/tag-manager/quickstart
  self.position = :body

  def container
    options[:container].respond_to?(:call) ? options[:container].call(env) : options[:container]
  end

  def render
    Tilt.new( File.join( File.dirname(__FILE__), 'template', 'google_tag_manager.erb') ).render(self)
  end

  def self.track(name, *event)
    { name.to_s => [event.last.merge('class_name' => event.first.to_s.capitalize)] }
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rack-tracker-1.0.2 lib/rack/tracker/google_tag_manager/google_tag_manager.rb
rack-tracker-1.0.1 lib/rack/tracker/google_tag_manager/google_tag_manager.rb
rack-tracker-1.0.0 lib/rack/tracker/google_tag_manager/google_tag_manager.rb
rack-tracker-0.4.2 lib/rack/tracker/google_tag_manager/google_tag_manager.rb
rack-tracker-0.4.1 lib/rack/tracker/google_tag_manager/google_tag_manager.rb
rack-tracker-0.4.0 lib/rack/tracker/google_tag_manager/google_tag_manager.rb