|
1 | 1 | {% if GOOGLEANALYTICS_ID %} |
2 | | -<script> |
3 | | - (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
4 | | - (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
5 | | - m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) |
6 | | - })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); |
| 2 | + {# 0 = Legacy (analytics.js) - Google Analytics #} |
| 3 | + {# 1 = Global site tag (gtag.js) - Google Analytics #} |
| 4 | + {% if GOOGLEANALYTICS_TAG == 1 %} |
| 5 | + <!-- Global site tag (gtag.js) - Google Analytics --> |
| 6 | + <script async src="https://www.googletagmanager.com/gtag/js?id={{ GOOGLEANALYTICS_ID }}"></script> |
| 7 | + <script> |
| 8 | + window.dataLayer = window.dataLayer || []; |
| 9 | + function gtag(){dataLayer.push(arguments);} |
| 10 | + gtag('js', new Date()); |
7 | 11 |
|
8 | | - ga('create', '{{ GOOGLEANALYTICS_ID }}', 'auto'); |
9 | | - {% if S_REGISTERED_USER -%} |
10 | | - ga('set', 'userId', {{ GOOGLEANALYTICS_USER_ID }}); |
11 | | - {% endif -%} |
12 | | - {% if S_ANONYMIZE_IP -%} |
13 | | - ga('set', 'anonymizeIp', true); |
14 | | - {% endif -%} |
15 | | - {% EVENT phpbb_googleanalytics_alter_ga_requirements -%} |
16 | | - ga('send', 'pageview'); |
17 | | -</script> |
| 12 | + gtag('config', '{{ GOOGLEANALYTICS_ID }}', { |
| 13 | + {%- EVENT phpbb_googleanalytics_gtag_options -%} |
| 14 | + {%- if S_REGISTERED_USER %}'user_id': '{{ GOOGLEANALYTICS_USER_ID }}',{% endif -%} |
| 15 | + {%- if S_ANONYMIZE_IP %}'anonymize_ip': true,{% endif -%} |
| 16 | + }); |
| 17 | + </script> |
| 18 | + {% else %} |
| 19 | + <script> |
| 20 | + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
| 21 | + (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
| 22 | + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) |
| 23 | + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); |
| 24 | + |
| 25 | + ga('create', '{{ GOOGLEANALYTICS_ID }}', 'auto'); |
| 26 | + {% if S_REGISTERED_USER %}ga('set', 'userId', {{ GOOGLEANALYTICS_USER_ID }});{% endif %} |
| 27 | + {% if S_ANONYMIZE_IP %}ga('set', 'anonymizeIp', true);{% endif %} |
| 28 | + {% EVENT phpbb_googleanalytics_alter_ga_requirements -%} |
| 29 | + ga('send', 'pageview'); |
| 30 | + </script> |
| 31 | + {% endif %} |
18 | 32 | {% endif %} |
0 commit comments