6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/analytics/rails/action_view/base.rb', line 6
def google_analytics_include_tag(*args)
options = args.
if ::Rails.env.production?
[:variables, :events].each do |name|
if options.has_key? name
options[name].map! do |values|
values.map(&:inspect).join(', ').gsub('"',"'")
end
else
options[name] = []
end
end
variables = options[:variables].map do |values|
"_gaq.push(['_setCustomVar', #{values}]);"
end
events = options[:events].map do |values|
"ga('send', 'event', #{values});"
end
script = " var _gaq = _gaq || [];\n _gaq.push(['_setAccount', '\#{args.first}']);\n \#{variables.join(\"\\n\")}\n _gaq.push(['_trackPageview']);\n (function(){\n var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n })();\n \#{events.join(\"\\n\")}\n SCRIPT\n content_tag :script, script.html_safe, type: 'text/javascript'\n end\nend\n"
|