From 426abb9313ff0faf72331aea83055997007f601c Mon Sep 17 00:00:00 2001 From: Chalo Fernandez Date: Mon, 9 Dec 2019 17:10:03 -0600 Subject: [PATCH] Avoid showing the JS code when GA tracker is not defined --- .../template/google_analytics.erb | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/rack/tracker/google_analytics/template/google_analytics.erb b/lib/rack/tracker/google_analytics/template/google_analytics.erb index 5aa0159..d6d9d7b 100644 --- a/lib/rack/tracker/google_analytics/template/google_analytics.erb +++ b/lib/rack/tracker/google_analytics/template/google_analytics.erb @@ -8,37 +8,37 @@ ga('create', '<%= tracker %>', <%= tracker_options.to_json %>); } -<% if options[:enhanced_link_attribution] %> - ga('require', 'linkid', 'linkid.js'); -<% end %> -<% if options[:advertising] %> - ga('require', 'displayfeatures'); -<% end %> -<% if options[:enhanced_ecommerce] %> - ga('require', 'ec'); -<% end %> -<% if options[:ecommerce] %> - ga('require', 'ecommerce', 'ecommerce.js'); -<% end %> -<% if options[:optimize] %> - ga('require', '<%= options[:optimize] %>'); -<% end %> -<% if options[:anonymize_ip] %> - ga('set', 'anonymizeIp', true); -<% end %> -<% if options[:adjusted_bounce_rate_timeouts] %> - <% options[:adjusted_bounce_rate_timeouts].each do |timeout| %> - setTimeout(function() { ga('send', 'event', '<%= "#{timeout.to_s}_seconds" %>', 'read'); },<%= timeout*1000 %>); + <% if options[:enhanced_link_attribution] %> + ga('require', 'linkid', 'linkid.js'); + <% end %> + <% if options[:advertising] %> + ga('require', 'displayfeatures'); + <% end %> + <% if options[:enhanced_ecommerce] %> + ga('require', 'ec'); + <% end %> + <% if options[:ecommerce] %> + ga('require', 'ecommerce', 'ecommerce.js'); + <% end %> + <% if options[:optimize] %> + ga('require', '<%= options[:optimize] %>'); + <% end %> + <% if options[:anonymize_ip] %> + ga('set', 'anonymizeIp', true); + <% end %> + <% if options[:adjusted_bounce_rate_timeouts] %> + <% options[:adjusted_bounce_rate_timeouts].each do |timeout| %> + setTimeout(function() { ga('send', 'event', '<%= "#{timeout.to_s}_seconds" %>', 'read'); },<%= timeout*1000 %>); + <% end %> + <% end %> + <% events.each do |var| %> + ga(<%= var.write() %>); + <% end %> + <% if options[:ecommerce] && ecommerce_events.any? %> + ga('ecommerce:send'); + <% end %> + <% if tracker && options[:explicit_pageview] %> + ga('send', 'pageview', <%= pageview_url_script %>); <% end %> -<% end %> -<% end %> -<% events.each do |var| %> - ga(<%= var.write() %>); -<% end %> -<% if options[:ecommerce] && ecommerce_events.any? %> - ga('ecommerce:send'); -<% end %> -<% if tracker && options[:explicit_pageview] %> - ga('send', 'pageview', <%= pageview_url_script %>); <% end %>