Module: Utopia::Tags::GoogleAnalytics

Defined in:
lib/utopia/tags/google-analytics.rb,
lib/utopia/tags/google-analytics/version.rb

Constant Summary collapse

VERSION =
"1.0.3"

Class Method Summary collapse

Class Method Details

.call(transaction, state) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/utopia/tags/google-analytics.rb', line 26

def self.call(transaction, state)
	id = state[:id]
	
	html = <<-EOF
		<script>
			(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
				(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
				m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
			})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
				
			ga('create', #{JSON.dump(id)}, 'auto');
			ga('send', 'pageview');
		</script>
	EOF
	
	transaction.cdata(html)
end