首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >跟踪Google Visualization API请求中的事件

跟踪Google Visualization API请求中的事件
EN

Stack Overflow用户
提问于 2016-03-08 01:31:33
回答 1查看 72关注 0票数 0

这是我使用Google Visualization API从Google工作表中检索表的代码片段。

代码语言:javascript
复制
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的下载。

代码语言:javascript
复制
<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中?)。是否有能够跟踪事件的解决方法?

EN

回答 1

Stack Overflow用户

发布于 2016-03-08 02:53:45

如果您可以在iframe中包含GA跟踪代码(如果iframe来自不同的域),并且如果您在iframe中附加跨域跟踪代码,将两个域链接在一起,则可以使用Google Analytics为iframe设置跟踪。从它的声音中,你将无法追踪到它。

还请记住,页面上的iframe没有跟踪iframe将算作反弹,因为您正在加载您的页面,然后google触发,然后google将认为您正在离开,因为您正在加载一个单独的域名。

一种解决方案是尝试在iframe之外构建您自己的按钮,该按钮将触发图表的下载(通过使用图像mimetype再次有效地请求它)。你可以追踪它。它不一定会获得100%的点击,但至少会有一些(即点击按钮的人,而不是iframe)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35850157

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档