I am trying to use the Google Analytics API via Angular. I load the analytics script first
<script src="https://apis.google.com/js/client.js"></script>
I then console.log
the global gapi
variables that the api script creates. This returns the object as I'd expect, with an auth
property. However gapi.auth
appears undefined
.
When I make the function wait two seconds though it does run as expected. This illustrates what happens:
However all the properties are there even in the first object:
Why does the later one have a preview and the earlier one doesn't? I'd imagine that this is related to why I can only access their properties after 2 seconds.
UPDATE:
I have added this checker at the top of my script to wait for gapi.auth
to load... but it never finishes:
while (gapi.auth === undefined) {
console.log("Still undefined");
}
console.log(loaded now");