fix issue #106
Didier Lafforgue
committed Apr 30, 2018
commit 2e4184f394f79229ba95827515daa0b52030670f
Showing 2
changed files with
10 additions
and 9 deletions
locomotive/steam/liquid/tags/google_analytics.rb b/lib/locomotive/steam/liquid/tags/google_analytics.rb
+8
-7
| @@ | @@ -18,13 +18,14 @@ module Locomotive |
| def ga_snippet(account_id) | |
| %{ | |
| - | <script type="text/javascript"> |
| - | (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'); |
| + | <!-- Global Site Tag (gtag.js) - Google Analytics --> |
| + | <script async src="https://www.googletagmanager.com/gtag/js?id=#{account_id}"></script> |
| + | <script> |
| + | window.dataLayer = window.dataLayer || []; |
| + | function gtag(){dataLayer.push(arguments);} |
| + | gtag('js', new Date()); |
| + | |
| + | gtag('config', '#{account_id}'); |
| </script> | |
| } | |
| end | |
spec/unit/liquid/tags/google_analytics_spec.rb
+2
-2
| @@ | @@ -6,8 +6,8 @@ describe Locomotive::Steam::Liquid::Tags::GoogleAnalytics do |
| subject { render_template(source) } | |
| - | it { is_expected.to include "ga('create', '42', 'auto')" } |
| - | it { is_expected.to include "ga('send', 'pageview')" } |
| + | it { is_expected.to include %{<script async src="https://www.googletagmanager.com/gtag/js?id=42"></script>} } |
| + | it { is_expected.to include "gtag('config', '42');" } |
| describe 'raises an error if the syntax is incorrect' do | |
| let(:source) { '{% google_analytics %}' } | |