CSE JSON API和Google Analytics

时间:2022-11-16 15:15:08

We post our queries directly to the Google CSE JSON Api, as such we do an ajax call that looks something like this:

我们将查询直接发布到Google CSE JSON Api,因此我们执行ajax调用,如下所示:

https://www.googleapis.com/customsearch/v1?q=[query]&cx=[cx]&hq=[filters]&key=[key]

We've setup our CSE with the correct Analytics account and put the old analytics js stuff on our page:

我们已使用正确的Google Analytics帐户设置我们的CSE,并将旧的分析js内容放在我们的页面上:

<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'number']);
_gaq.push(['_trackPageview']);

(function() {
    var ga = document.createElement('script');
    ga.type = 'text/javascript';
    ga.async = true;
    ga.src=('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(ga, s);
})();

and configured the CSE to use the query q. In Google analytics we have site search tracking on and our query parameter is set to q. The CSE stats show a decent amount of distinct queries every day but we get nothing in Google Analytics.

并配置CSE使用查询q。在Google Analytics中,我们有网站搜索跟踪,我们的查询参数设置为q。 CSE统计信息每天都会显示大量不同的查询,但我们在Google Analytics中没有得到任何结果。

When posting directly to the JSON API is there something additional I need to do to get the analytics account hooked up to show queries in the site search reports?

直接发布到JSON API时,我需要做些什么才能将分析帐户连接起来以在站点搜索报告中显示查询?

1 个解决方案

#1


1  

I fixed this by switching to universal analytics and sending GA a fake page with query:

我通过切换到通用分析并向GA发送带有查询的虚假页面来修复此问题:

ga('send', 'pageview', '/search-results.php?q=' + ((query) ? query : Search.searchViewModel.query()) );

ga('send','pageview','/ search-results.php?q ='+((query)?query:Search.searchViewModel.query()));

#1


1  

I fixed this by switching to universal analytics and sending GA a fake page with query:

我通过切换到通用分析并向GA发送带有查询的虚假页面来修复此问题:

ga('send', 'pageview', '/search-results.php?q=' + ((query) ? query : Search.searchViewModel.query()) );

ga('send','pageview','/ search-results.php?q ='+((query)?query:Search.searchViewModel.query()));