Pārlūkot izejas kodu

Enable IP anonymization for analytics

Jordi Boggiano 6 gadi atpakaļ
vecāks
revīzija
1b65f2532e

+ 2 - 2
app/config/config_prod.yml

@@ -87,7 +87,7 @@ nelmio_security:
                 - 'unsafe-inline'
                 - 'unsafe-eval'
                 - 'https://cdn.jsdelivr.net/'
-                - 'https://ssl.google-analytics.com/'
+                - 'https://www.google-analytics.com/'
             connect-src:
                 - 'self'
                 - '*.algolia.net'
@@ -99,7 +99,7 @@ nelmio_security:
                 - 'https://raw.github.com/'
                 - 'https://github.com/'
                 - 'https://gitlab.com/'
-                - 'https://ssl.google-analytics.com/'
+                - 'https://www.google-analytics.com/'
                 - 'http://www.google-analytics.com/'
             style-src:
                 - 'self'

+ 8 - 4
src/Packagist/WebBundle/Resources/views/layout.html.twig

@@ -216,10 +216,14 @@
 
         {%- if not app.debug and google_analytics.ga_key %}
         <script>
-            var _gaq=[['_setAccount','{{ google_analytics.ga_key }}'],['_trackPageview']];
-            (function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
-            g.src='https://ssl.google-analytics.com/ga.js';
-            s.parentNode.insertBefore(g,s)}(document,'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('set', 'anonymizeIp', true);
+            ga('create', '{{ google_analytics.ga_key }}', 'auto');
+            ga('send', 'pageview');
         </script>
         {%- endif %}