Reputation: 7734
I used to use window.ga.getAll()[1].b.data.values[':trackingId'];
a few months ago and it works well. But recently it's not working and says getAll is not a function
.
What should I do instead?
update:
Upvotes: 1
Views: 123
Reputation: 8304
getAll
is not immediately available when google analytics loads:
https://developers.google.com/analytics/devguides/collection/analyticsjs/ga-object-methods-reference
Don't — use ga object methods outside a readyCallback as the methods may not be available yet.
Instead, try this:
window.ga(() => window.ga.getAll()[1].b.data.values[':trackingId']);
which will run your function as part of a readyCallback.
Upvotes: 1