new google analytics code locomotivecms/engine#914

did committed Sep 03, 2015
commit 18455de4d6c5ff3d5ab7e53774d21baf98f4951b
Showing 2 changed files with 10 additions and 13 deletions
locomotive/steam/liquid/tags/google_analytics.rb b/lib/locomotive/steam/liquid/tags/google_analytics.rb +8 -12
@@ @@ -19,18 +19,14 @@ module Locomotive
def ga_snippet(account_id)
%{
<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>}
+ (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', '#{account_id}', 'auto');
+ ga('send', 'pageview');
+ </script>
+ }
end
end
spec/unit/liquid/tags/google_analytics_spec.rb +2 -1
@@ @@ -6,7 +6,8 @@ describe Locomotive::Steam::Liquid::Tags::GoogleAnalytics do
subject { render_template(source) }
- it { is_expected.to include "_gaq.push(['_setAccount', '42']);" }
+ it { is_expected.to include "ga('create', '42', 'auto')" }
+ it { is_expected.to include "ga('send', 'pageview')" }
describe 'raises an error if the syntax is incorrect' do
let(:source) { '{% google_analytics %}' }