this is utterly useless nowadays.
everything client-side is just bad. blocked by iOS & adblocks, to the point of data discrepancy in conversions and revenue. it's even worse when there's a third-party cookie and the analytics.js files are loaded from another domain.
Please don't use this garbage, get a server-side plugin or your own implementation, either in code (if you can code), or using a plugin+ Google Tag Manager.
if you can't do it on your own, this is a solid way of implementing google analytics:
they have a free plugin + free account that should be enough for any small website.
full instructions how to set everything up.
after that, tag your events without code via gtm / analytics. plenty of guides for that on the internet.
if you're forced to using Monster Insights, at least host your analytics files locally. I think WP-Rocket has this option. same as Perfmatters plugin. and you also have a standalone wordpress plugin that's called CAOS.
But really, switch to server-side events, set your website domain to the root domain (without WWW) , and use a subdomain to feed the analytics events, either by yourself or using stape.io (there is a document to do exactly that, including subdomain setup).