Delay GA loading

This commit is contained in:
Cotes Chung 2020-12-10 23:57:00 +08:00
parent cdaa79cf80
commit 63f57fbc12
3 changed files with 14 additions and 10 deletions

View file

@ -6,11 +6,13 @@
MIT License
-->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics.id }}"></script>
<script defer src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics.id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ site.google_analytics.id }}');
document.addEventListener("DOMContentLoaded", function(event) {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ site.google_analytics.id }}');
});
</script>

View file

@ -25,4 +25,10 @@
{% if jekyll.environment == 'production' %}
<!-- PWA -->
<script defer src="{{ '/app.js' | relative_url }}"></script>
<!-- GA -->
{% if site.google_analytics.id %}
{% include google-analytics.html %}
{% endif %}
{% endif %}

View file

@ -52,10 +52,6 @@ layout: compress
{% include search-loader.html %}
{% if site.google_analytics.id and jekyll.environment == 'production' %}
{% include google-analytics.html %}
{% endif %}
</body>
</html>