Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Provide site search information to Universal Analytics from Google Tag Manager

We have a site on which we recently started using Google Tag Manager for all our tracking needs.

Before this we had Google Analytics (now upgraded to Universal Analytics) Site Search activated. We had _ga.push-statements with the search parameters sent to Google Analytics, the terms we used was the search string and the number of products found which was sent in an event like:

_gaq.push(['_trackPageview', '/search?q=[SEARCH STRING]&cat=[NUMBER OF RESULTS]']);

Google Analytics received these parameters and used them in Site Search.

Now that we have GTM set up I feel we really should be able to skip this step, many events and other Google Analytics stuff is already integrated in GTM in a good way.

In our dataLayer to GTM we have searchString as well as the number of results and much more information that could be used for site search by Google Analytics.

The question is HOW should you send the information to Google Analytics and HOW should you setup GA to receive it in the best possible way?

like image 572
Tor Sterner Avatar asked Nov 02 '22 00:11

Tor Sterner


1 Answers

Tor Sterner,

the thing is that you have to provide the search string to Google Analytics in URL as a query parameter (in your example, it's named q). In GA web interface, you can then set up the site search settings, fill out the search parameter and that's it.

You were for that reason sending virtual pageviews, and that's what you need to do with GTM as well. However, the better approach would be to simply append the search parameter to URL, something like:

enter image description here

By default, GTM uses url path for Document Path (=Page) dimension. If you append your search string, then yon can setup search query parametr in Analytics interface (View Settings > Site Search) and that's it.

I have used {{Search String}} macro to capture the search phrase - but since I am not sure how search is implemented on your site, you will have to come up with a way how to do this (DataLayer variable, Custom Javascript macro etc.) - and make sure it returns the search query with parameter as well. It should look like this:

?q=searching
like image 174
Petr Havlik Avatar answered Nov 09 '22 16:11

Petr Havlik