AGamePlayer
AGamePlayer

Reputation: 7734

How to get a page's Google Analytics tracking ID via a Chrome Extension?

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

Answers (1)

intentionally-left-nil
intentionally-left-nil

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

Related Questions