Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support mlchaves

    (@mlchaves)

    Hi @tariqinaamgmailcom,

    We saw your support ticket on this subject. Thanks for that. And, we replied.

    A brief summary: That script tag isn’t hardcoded perse. Just like almost anything in WordPress, you can change it. But, you need to understand and accept the consequences.

    MonsterInsights doesn’t add the defer attribute because it isn’t recommended (refer to Google dev docs). Otherwise, you’d increase your chances of missing stats and causing errors if the gtag library isn’t loaded asap. Defer kinda defeats the purpose.

    Check out the reply to your support ticket and please follow-up there if needed 😉

    Cheers!

    Plugin Support mlchaves

    (@mlchaves)

    Marking as resolved.

    sathoro

    (@sathoro)

    Hey @mlchaves, I came across this thread because I noticed the gtag script is in the head and doesn’t have the async or defer attributes. This means the website will be blocked from being rendered until the script is fully executed. This can of course cause significant delay since it will generally require a DNS request, SSL handshake, JS execution etc etc. Of course most the time it is quick but if there is any slowdown well it will make the whole site seem slow.

    You mentioned the docs say defer is not recommended, but I noticed that on this page https://developers.google.com/analytics/devguides/collection/gtagjs the code example actually uses the async attribute. This seems to me that Google in fact does recommend using async, but I have not done significant research on this. I did check a couple of Google-owned properties and they all used the async property on their own gtag scripts.

    So I’m wondering if there is an option or workaround for adding the async attribute to the script? Thanks!

    Btw, I do understand that this will can cause some page views to not get counted but I would prefer that over the page from being blocked from rendering. Also since some people use ad blockers you can’t really rely on GA being 100% accurate anyways so some missed hits isn’t critical.

    Plugin Support mlchaves

    (@mlchaves)

    Hi @sathoro,

    That’s a great question. Thanks for asking.

    Please look at the second file in the gist below. The file name is remove_type_attr_add_async.php

    https://gist.github.com/chavesm/1c9eb33ad489ccaecc606401f9bbd1b3

    Carefully read the comments in the code. Yell if you have any questions 🙂

    Have an awesome weekend!

    Mark

    • This reply was modified 2 months ago by mlchaves.
    sathoro

    (@sathoro)

    Thanks @mlchaves! That is very helpful

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.