Sometimes if we copied a site or if we’re writing a third party library, we may not know whether Google analytics has been loaded.
Google analytics using a function it defines in the global context called “ga”.
How It Works:
typeof ga === 'function'
If this returns true, Google analytics has been loaded, if false, then Google analytics has not been loaded or is currently loading.