Sha256: a5704fb09fd406a48785ce2deee42c394ef93535d514d2933de17429da25e6b3
Contents?: true
Size: 1.17 KB
Versions: 59
Compression:
Stored size: 1.17 KB
Contents
module Liquid module Locomotive module Tags class GoogleAnalytics < ::Liquid::Tag Syntax = /(#{::Liquid::Expression}+)?/ def initialize(tag_name, markup, tokens, context) if markup =~ Syntax @account_id = $1.gsub('\'', '') else raise ::Liquid::SyntaxError.new("Syntax Error in 'google_analytics' - Valid syntax: google_analytics <account_id>") end super end def render(context) %{ <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', '#{@account_id}']); _gaq.push(['_trackPageview']); (function() \{ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); \})(); </script>} end end ::Liquid::Template.register_tag('google_analytics', GoogleAnalytics) end end end
Version data entries
59 entries across 59 versions & 3 rubygems