我試圖從html文檔中提取Google分析ID。使用Javascript獲取Google AnalyticsID
我發現了以下功能:
function get_UA() {
txt = document.getElementById('scripttag').value;
var matches = txt.match(/(UA-[\d-]+)/);
if (matches[1]) {
alert(matches[1]);
}
}
但是我得到這個錯誤:
TypeError: 'null' is not an object (evaluating 'document.getElementById('scripttag').value')
任何想法?
+1這正是我一直在尋找的來源:) – VisioN
對於新的萬用谷歌分析(https://support.google.com/analytics/answer/2790010?hl = en)其中'_gaq'已被翻譯爲'ga',您可以使用:'ga.getAll()。shift()。b.data.w [':trackingId']' – sospedra