From 7edc2cb6da5e8a9ca77b2c0340d18400fa32ce52 Mon Sep 17 00:00:00 2001 From: Jeffrey Warren Date: Mon, 20 May 2019 13:27:53 -0400 Subject: [PATCH 1/2] Add google analytics callbacks to typeahead search (if GA installed) --- app/assets/javascripts/restful_typeahead.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/restful_typeahead.js b/app/assets/javascripts/restful_typeahead.js index fe168b40b9..3ee4b61f44 100644 --- a/app/assets/javascripts/restful_typeahead.js +++ b/app/assets/javascripts/restful_typeahead.js @@ -15,7 +15,12 @@ $(function() { source: debounce(function (query, process) { var encoded_query = encodeURIComponent(query); var qryType = $(el).attr('qryType'); - return $.getJSON('/api/srch/' + qryType + '?query=' + encoded_query, function (data) { + var queryUrl = 'api/srch/' + qryType + '?query=' + encoded_query; + if (window.hasOwnProperty('ga')) { + tracker = ga.getAll()[0]; + tracker.send("pageview", queryUrl); + } + return $.getJSON('/' + queryUrl, function (data) { return process(data.items); },'json'); }, 350), From 37fcecc28d458c2d95c49e95fc50adc696cd2c5f Mon Sep 17 00:00:00 2001 From: Jeffrey Warren Date: Mon, 20 May 2019 13:30:10 -0400 Subject: [PATCH 2/2] Update restful_typeahead.js --- app/assets/javascripts/restful_typeahead.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/restful_typeahead.js b/app/assets/javascripts/restful_typeahead.js index 3ee4b61f44..b898a66a6f 100644 --- a/app/assets/javascripts/restful_typeahead.js +++ b/app/assets/javascripts/restful_typeahead.js @@ -18,7 +18,7 @@ $(function() { var queryUrl = 'api/srch/' + qryType + '?query=' + encoded_query; if (window.hasOwnProperty('ga')) { tracker = ga.getAll()[0]; - tracker.send("pageview", queryUrl); + tracker.send("pageview", queryUrl + '&typeahead=true'); } return $.getJSON('/' + queryUrl, function (data) { return process(data.items);