25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/middleman-google-analytics/extension.rb', line 25
def google_analytics_tag
options = ::Middleman::GoogleAnalytics.options
options.debug = development? if options.debug.nil?
ga = options.debug ? 'u/ga_debug' : 'ga'
domain_name = options.domain_name
if tracking_id = options.tracking_id
gaq = []
gaq << ['_setAccount', "#{tracking_id}"]
gaq << ['_setDomainName', "#{domain_name}"] if domain_name
gaq << ['_setAllowLinker', true] if options.allow_linker
gaq << ['_gat._anonymizeIp'] if options.anonymize_ip
gaq << ['_trackPageview']
%Q{<script type="text/javascript">
var _gaq = _gaq || [];
#{gaq.map! { |x| "_gaq.push(#{x});" }.join("\n ")}
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? '//ssl' : '//www') + '.google-analytics.com/#{ga}.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>}
end
end
|