Reputation: 5157
I need to track the site search query terms for an internal site search I have placed on the website.
My plan is to enable the Site Search settings within Google Analytics.
However my site search page does not use the standard query string variables that the site search uses to track queries. Instead my site search page is updated through AJAX. Is there an API call I can do to send the query and the category to the Google Site Search tracking.
Also I need to track the username of the user doing the search (this is behind a login so all users will be logged in). Is there a way I can send some sort of meta data to include the username?
Let me know if the Site Search Tracking is not the correct way to approach this if I should be using some other sort of tools such as event tracking.
I'm using ASP.NET MVC: Please see the sample code below:
$.ajax({
url: '/Search/',
type: 'POST',
dataType: 'json',
data: { search_phrase:
search_phrase
},
success: function(data) {
Upvotes: 0
Views: 638
Reputation: 3847
you may send a 'virtual' pageview in success calllback composint the suitable value instead of an actual document location like
success: function(data) {
ga('send', {
hitType: 'pageview',
page: location.origin + 'search?q=' + search_phrase
});
}
If you're using GTM you may push the search phrase to dataLayer and then fire Google Analytics Tag with owerwritten location field for this custom event:
success: function(data) {
dataLayer.push({
event: 'internal search', // allows you to set up custom event
search_phrase: search_phrase
});
}
Upvotes: 2