這是我用來從Google表格使用Google Visualization API檢索表格的代碼片段。追蹤Google Visualization API請求中的事件
google.load('visualization', '1', {
packages: ['table']
});
var visualization;
function drawVisualization() {
var query = new google.visualization.Query('http://spreadsheets.google.com/tq?key=XXXXXXXX&hl=it_IT');
query.setQuery('SELECT B, C, D, E, F, G, H where upper(B) like upper("%<?php echo $search; ?>%") or upper(D) like upper("%<?php echo $search; ?>%") or upper(F) like upper("%<?php echo $search; ?>%") order by G DESC label G "Data"');
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();
var formatter = new google.visualization.PatternFormat(
'<a href="{6}" target="_blank" onclick="var that=this;_gaq.push([\'_trackEvent\',\'Event Category\',{2},this.href]);setTimeout(function(){location.href=that.href;},200);return false;">{2}</a>');
// Apply formatter and set the formatted value of the first column.
formatter.format(data, [0, 1, 2, 3, 4, 5, 6], 2);
var view = new google.visualization.DataView(data);
view.setColumns([2, 0, 1, 4, 5]); // Create a view with the first column only.
visualization = new google.visualization.Table(document.getElementById('table'));
visualization.draw(view, {
legend: 'bottom',
allowHtml: true
});
}
google.setOnLoadCallback(drawVisualization);
正如您所看到的,我試圖跟蹤觸發JavaScript事件onclick的下載。
<a href="URL" target="_blank" onclick="var that=this;_gaq.push(['_trackEvent','EVENT_CATEGORY','EVENT_URL',this.href]);setTimeout(function(){location.href=that.href;},200);return false;">LINK_NAME</a>
此代碼的工作,如果在一個「正常」的網頁(即事件在谷歌Analytics(分析)追蹤)使用,但它不能在這裏工作(我相信,因爲它是一個iframe裏面?)。 有沒有可以跟蹤事件的解決方法?
iframe是否啓用GA跟蹤? – nyuen
iframe是Google從Google加載的表格。我無法訪問它 – MultiformeIngegno
然後根本無法跟蹤iframe中的任何內容。您需要在該頁面上添加您的Google Analytics跟蹤代碼才能進行任何跟蹤。 – nyuen