Sha256: 2e648441148979aea44af770d7967c1c4107da20d1974723fcfc97c1e5b045ac
Contents?: true
Size: 1.27 KB
Versions: 13
Compression:
Stored size: 1.27 KB
Contents
module Locomotive module Steam module Liquid module Tags class GoogleAnalytics < ::Liquid::Tag Syntax = /(#{::Liquid::QuotedFragment}+)/o.freeze attr_reader :account_id def initialize(tag_name, markup, options) super if markup =~ Syntax @account_id = ::Liquid::Expression.parse($1) else raise ::Liquid::SyntaxError.new("Syntax Error in 'google_analytics' - Valid syntax: google_analytics <account_id>") end end def render(context) ga_snippet(context.evaluate(account_id)) end private def ga_snippet(account_id) %{ <!-- Global Site Tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=#{account_id}"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', '#{account_id}'); </script> } end end ::Liquid::Template.register_tag('google_analytics'.freeze, GoogleAnalytics) end end end end
Version data entries
13 entries across 13 versions & 1 rubygems