Skip to content

Commit 2c3971b

Browse files
committed
Migrate from analytics.js to gtag.js
1 parent 7bafc7b commit 2c3971b

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{% 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+
<!-- https://developers.google.com/analytics/devguides/collection/gtagjs/migration -->
3+
<!-- Global site tag (gtag.js) - Google Analytics -->
4+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ GOOGLEANALYTICS_ID }}"></script>
5+
<script>
6+
window.dataLayer = window.dataLayer || [];
7+
function gtag(){dataLayer.push(arguments);}
8+
gtag('js', new Date());
79

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>
10+
gtag('config', '{{ GOOGLEANALYTICS_ID }}', {
11+
{% EVENT phpbb_googleanalytics_gtag_options %}
12+
{% if S_REGISTERED_USER %}'user_id': '{{ GOOGLEANALYTICS_USER_ID }}',{% endif %}
13+
{% if S_ANONYMIZE_IP %}'anonymize_ip': true,{% endif %}
14+
});
15+
</script>
1816
{% endif %}

0 commit comments

Comments
 (0)