am 2325250e: am 9ae6d37a: am de295276: add javascript action events to search suggestions and search results. Allows us to track and compare the success of suggested results and results from Google

* commit '2325250e639f3c443a8ccd006f0d591eb8f1c5d3':
  add javascript action events to search suggestions and search results. Allows us to track and compare the success of suggested results and results from Google
This commit is contained in:
Scott Main 2013-03-25 16:15:12 -07:00 committed by Android Git Automerger
commit 709fcf04a0

View file

@ -1511,6 +1511,12 @@ var gGoogleMatches = new Array();
var ROW_COUNT_GOOGLE = 15; // max number of results in list
var gGoogleListLength = 0;
function onSuggestionClick(link) {
// When user clicks a suggested document, track it
_gaq.push(['_trackEvent', 'Suggestion Click', 'clicked: ' + $(link).text(),
'from: ' + $("#search_autocomplete").val()]);
}
function set_item_selected($li, selected)
{
if (selected) {
@ -1540,7 +1546,7 @@ function new_suggestion() {
$(this).addClass('jd-selected');
gSelectedIndex = $('#search_filtered li').index(this);
});
$li.append('<a></a>');
$li.append("<a onclick='onSuggestionClick(this)'></a>");
$li.attr('class','show-item');
return $li;
}
@ -1894,6 +1900,11 @@ function loadSearchResults() {
location.hash = 'q=' + query;
});
// once search results load, set up click listeners
searchControl.setSearchCompleteCallback(this, function(control, searcher, query) {
addResultClickListeners();
});
// draw the search results box
searchControl.draw(document.getElementById("leftSearchControl"), drawOptions);
@ -1972,6 +1983,17 @@ function addTabListeners() {
setTimeout(function(){$(tabHeaders[0]).click()},200);
}
// add analytics tracking events to each result link
function addResultClickListeners() {
$("#searchResults a.gs-title").each(function(index, link) {
// When user clicks enter for Google search results, track it
$(link).click(function() {
_gaq.push(['_trackEvent', 'Google Click', 'clicked: ' + $(this).text(),
'from: ' + $("#search_autocomplete").val()]);
});
});
}
function getQuery(hash) {
var queryParts = hash.split('=');