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 MIT License
--> -->
<!-- Global site tag (gtag.js) - Google Analytics --> <!-- 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> <script>
window.dataLayer = window.dataLayer || []; document.addEventListener("DOMContentLoaded", function(event) {
function gtag(){dataLayer.push(arguments);} window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ site.google_analytics.id }}'); gtag('js', new Date());
gtag('config', '{{ site.google_analytics.id }}');
});
</script> </script>

View file

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

View file

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