3.7K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

ga.js CSE JSON API

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭
We post our queries directly to the Google CSE JSON Api, as such we do an ajax call that looks something like this:
 
 
We've setup our CSE with the correct Analytics account and put the old analytics js stuff on our page:
 
<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);
    })();
</script>

 

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 that a decent ammount of distinct queries every day but we get nothing in Google Analytics.When posting directly to the JSON API is there something additional I need to do to get the analytics account hooked up?

 
Also, I'm cross posting here because there have been no answers on the CSE side of the house (https://productforums.google.com/forum/#!topic/customsearch/8guUpdqXhfY;context-place=forum/customse... , and the CSE support from Google is starting to point fingers at the analytics side. 
 
1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Joan J
June 2016

Re: ga.js CSE JSON API

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
I fixed this by switching to universal analytics and sending GA a fake page with query.

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

View solution in original post

Re: ga.js CSE JSON API

Top Contributor
# 2
Top Contributor
Hi, it may sound obvious but make sure you replace 'number' with your actual Google Analytics property ID
VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

Re: ga.js CSE JSON API

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
i wish it were that easy! this problem has been vexing me for a week now, and there have even been no answers from google's CSE team.
Marked as Best Answer.
Solution
Accepted by topic author Joan J
June 2016

Re: ga.js CSE JSON API

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
I fixed this by switching to universal analytics and sending GA a fake page with query.

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