Skip to content

Commit

Permalink
feat(analytics): add support for Modern Google Analytics gtag
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Goren authored and talha131 committed Jun 13, 2020
1 parent 5823306 commit 7f5d4c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions documentation/content/Analytics SEO SMO/google-analytics.md
Expand Up @@ -23,4 +23,11 @@ Set `GOOGLE_ANALYTICS` variable to it in your configuration.
:::python
GOOGLE_ANALYTICS = u'UA-00000000-1'

If you have a Google Analytics Measurement ID, which has the format `G-XXXXXXXXXX`, you should
set `MODERN_GOOGLE_ANALYTICS`. This will enable the `gtag.js` on your site.
For more information on the difference between the two, see [here](https://developers.google.com/analytics/devguides/collection/gtagjs/migration).

:::python
MODERN_GOOGLE_ANALYTICS = u'G-ABCDE12345'

That's it. Elegant will take care of the rest.
11 changes: 11 additions & 0 deletions templates/_includes/analytics.html
@@ -1,3 +1,14 @@
{% if MODERN_GOOGLE_ANALYTICS %}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ MODERN_GOOGLE_ANALYTICS }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '{{ MODERN_GOOGLE_ANALYTICS }}');
</script>
{% endif %}

{% if GOOGLE_ANALYTICS %}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
Expand Down

0 comments on commit 7f5d4c5

Please sign in to comment.