class Locomotive::Steam::Liquid::Tags::GoogleAnalytics
Constants
- Syntax
Attributes
account_id[R]
Public Class Methods
new(tag_name, markup, options)
click to toggle source
Calls superclass method
# File lib/locomotive/steam/liquid/tags/google_analytics.rb, line 11 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
Public Instance Methods
render(context)
click to toggle source
# File lib/locomotive/steam/liquid/tags/google_analytics.rb, line 21 def render(context) ga_snippet(context.evaluate(account_id)) end
Private Instance Methods
ga_snippet(account_id)
click to toggle source
# File lib/locomotive/steam/liquid/tags/google_analytics.rb, line 27 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