这是我使用Google Visualization API从Google工作表中检索表的代码片段。
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>如果在“普通”页面中使用此代码(即在Google Analytics中跟踪事件),则此代码可以工作,但它在这里不能工作(我假设是因为它在iframe中?)。是否有能够跟踪事件的解决方法?
发布于 2016-03-08 02:53:45
如果您可以在iframe中包含GA跟踪代码(如果iframe来自不同的域),并且如果您在iframe中附加跨域跟踪代码,将两个域链接在一起,则可以使用Google Analytics为iframe设置跟踪。从它的声音中,你将无法追踪到它。
还请记住,页面上的iframe没有跟踪iframe将算作反弹,因为您正在加载您的页面,然后google触发,然后google将认为您正在离开,因为您正在加载一个单独的域名。
一种解决方案是尝试在iframe之外构建您自己的按钮,该按钮将触发图表的下载(通过使用图像mimetype再次有效地请求它)。你可以追踪它。它不一定会获得100%的点击,但至少会有一些(即点击按钮的人,而不是iframe)。
https://stackoverflow.com/questions/35850157
复制相似问题