I´m trying to improve the load time and performance of my website. To summarize this is the average loading time stats that I get without including Google Tag Manager.
However when I just include Google Tag Manager with the code below which is just at the bottom of my page above the closing body tag, I can see a relevant impact in performance like:
<script async defer src="https://www.googletagmanager.com/gtag/js?id=myappid"></script>
<script>
var gaEnv;
switch (window.location.hostname) {
case 'production-domain':
gaEnv = 'production-id'; // production
break;
default:
gaEnv = 'development-id'; // development
}
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
// Config for analytics
gtag('config', gaEnv, { 'send_page_view': false });
// Config for Adwords
gtag('config', 'adwords-id');
</script>
I have read a lot of blog posts about how to improve performance of these scripts y using async and defer attributes, but it´s pretty clear that these is still an important impact in performance (more than 2 secs in load time and 1sec in finish time).
Is there anything that I´m missing or can do?