Skip to content

Commit

Permalink
Upgrade tracker code for Google Analytics 4 (mozilla#3172)
Browse files Browse the repository at this point in the history
Also update corresponding CSP settings
  • Loading branch information
mathjazz authored Apr 9, 2024
1 parent 06d0ed5 commit 7f97f68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
19 changes: 8 additions & 11 deletions pontoon/base/templates/tracker.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{% if settings.GOOGLE_ANALYTICS_KEY %}
<!-- Google Analytics -->
<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','https://www.google-analytics.com/analytics.js','ga');
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ settings.GOOGLE_ANALYTICS_KEY }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

ga('create', '{{ settings.GOOGLE_ANALYTICS_KEY }}', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
gtag('config', '{{ settings.GOOGLE_ANALYTICS_KEY }}');
</script>
{% endif %}

4 changes: 2 additions & 2 deletions pontoon/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,8 @@ def _allowed_hosts():
"'unsafe-eval'",
"'sha256-fDsgbzHC0sNuBdM4W91nXVccgFLwIDkl197QEca/Cl4='",
# Rules related to Google Analytics
"'sha256-G5/M3dBlZdlvno5Cibw42fbeLr2PTEGd1M909Z7vPZE='",
"https://www.google-analytics.com/analytics.js",
"'sha256-MAn2iEyXLmB7sfv/20ImVRdQs8NCZ0A5SShdZsZdv20='",
"https://www.googletagmanager.com/gtag/js",
)
CSP_STYLE_SRC = (
"'self'",
Expand Down

0 comments on commit 7f97f68

Please sign in to comment.