Merge pull request #10848 from thaJeztah/conditional_analytics

Move Google Analytics to include, and prepare for making it optional
This commit is contained in:
Usha Mandya 2020-05-20 10:26:08 +01:00 committed by GitHub
commit e18959db80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions

View File

@ -15,6 +15,11 @@ lsi: false
keep_files: ["v17.06", "v18.03", "v18.09"]
exclude: ["_scripts", "tests", "apidocs/layouts", "Gemfile", "hooks", "index.html", "404.html"]
# Google Analytics, etc.
# TODO these should only be set when building for production, or passed as an environment variable when building
google_analytics: GTM-WL2QLG5
# Component versions -- address like site.docker_ce_version
# You can't have - characters in these for non-YAML reasons

View File

@ -0,0 +1,7 @@
{% if include.GOOGLE_ID and include.GOOGLE_ID != '' %}<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','{{ include.GOOGLE_ID }}');</script>
{% else %}<!-- No Google Analytics ID configured, Google Tag Manager is disabled -->{% endif %}

View File

@ -16,13 +16,7 @@
display: block;
}
</style>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-WL2QLG5');</script>
<!-- End Google Tag Manager -->
{% if site.google_analytics != '' %}{% include analytics/google_analytics.html GOOGLE_ID=site.google_analytics %}{% endif %}
{% if site.GH_ENV == "gh_pages" %}
<meta name="robots" content="noindex">{% endif %}
<!-- favicon -->