I am trying to extract the Google analytics ID from a html document.
I found the following function:
function get_UA() {
txt = document.getElementById('scripttag').value;
var matches = txt.match(/(UA-[\d-]+)/);
if (matches[1]) {
alert(matches[1]);
}
}
But im getting this error:
TypeError: 'null' is not an object (evaluating 'document.getElementById('scripttag').value')
Any ideas?
Can you access the _gaq variable? If you can, and the page is using asynchronous tracking...
var accountId = _gaq._getAsyncTracker()._getAccount();
In April 2017, this works:
ga.getAll()[0].b.data.values[':trackingId']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With