From de2952768478e6390bcec424bb102911e7f4cbff Mon Sep 17 00:00:00 2001 From: Scott Main Date: Mon, 25 Mar 2013 15:48:35 -0700 Subject: [PATCH] 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 Change-Id: I64750e3b96ea585de415969cad8ab46c3bbbcaf4 --- .../droiddoc/templates-sdk/assets/js/docs.js | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/droiddoc/templates-sdk/assets/js/docs.js b/tools/droiddoc/templates-sdk/assets/js/docs.js index 3d34352043..613db32f46 100644 --- a/tools/droiddoc/templates-sdk/assets/js/docs.js +++ b/tools/droiddoc/templates-sdk/assets/js/docs.js @@ -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(''); + $li.append(""); $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('=');