Skip to content

Commit ba7b007

Browse files
authored
Merge pull request #73 from ByteInternet/google_tag_manager
2 parents 597b32c + 03a334d commit ba7b007

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

docs/_templates/layout.html

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@
6464
<!--[if lt IE 9]>
6565
<script src="{{ pathto('_static/js/html5shiv.min.js', 1) }}"></script>
6666
<![endif]-->
67+
68+
{%- if theme_analytics_id %}
69+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
70+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
71+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
72+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
73+
})(window,document,'script','dataLayer','{{ theme_analytics_id }}');</script>
74+
{%- endif %}
75+
6776
{%- if not embedded %}
6877
{# XXX Sphinx 1.8.0 made this an external js-file, quick fix until we refactor the template to inherert more blocks directly from sphinx #}
6978
{%- if sphinx_version_info >= (1, 8) -%}
@@ -248,22 +257,9 @@ <h4>Need support?</h4>
248257
});
249258
</script>
250259

251-
{#- Do not conflict with RTD insertion of analytics script #}
252-
{%- if not READTHEDOCS %}
253-
{%- if theme_analytics_id %}
254-
<!-- Theme Analytics -->
255-
<script async src="https://www.googletagmanager.com/gtag/js?id={{ theme_analytics_id }}"></script>
256-
<script>
257-
window.dataLayer = window.dataLayer || [];
258-
function gtag(){dataLayer.push(arguments);}
259-
gtag('js', new Date());
260-
261-
gtag('config', '{{ theme_analytics_id }}', {
262-
'anonymize_ip': {{ 'true' if theme_analytics_anonymize_ip|tobool else 'false' }},
263-
});
264-
</script>
265-
266-
{%- endif %}
260+
{%- if theme_analytics_id %}
261+
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PDL826"
262+
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
267263
{%- endif %}
268264

269265
{%- block footer %} {% endblock %}

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"navigation_depth": 4,
6363
"collapse_navigation": False,
6464
"titles_only": False,
65+
"analytics_id": "GTM-PDL826",
6566
}
6667
html_context = {
6768
"display_github": True, # Integrate GitHub

0 commit comments

Comments
 (0)