1
votes

With a site I manage, site search and site search category queries aren't present, but I was hoping to manipulate the page path URIs to form GA-readable URIs in Google Tag Manager.

Example #1

/search-all/search_one

Where 'search-all' is the site search category and 'search_one' is the site search keyword. Output required would be:

/site-search?search_cat=all&search_term=search_one

Example #2

/search-category1/search_two

Where 'search-category1' is the site site category and 'search_two' is the site search keyword. Output required would be:

/site-search?search_cat=category1&search_term=search_two

Can anyone help?

2

2 Answers

0
votes

Universal Analytics Admin

Create two custom dimensions:

  • Dimension1: Search Category; Scope HIT
  • Dimension2: Search Term; Scope HIT

Your Website

Add these search informations in dataLayer:

dataLayer.push({
    'searchCat':'Search',
    'searchKey':'Category one'
}); 

Google Tag Manager

Extend your current Tag for Universal Analytics type Pageview. Goto More Settings -> Custom Dimensions and set:

  • index 1 and assign macro type dataLayer searchCat
  • index 2 macro type dataLayer searchKey

OR you can track it as an event.

dataLayer.push({
    'eventCategory':'Search',
    'eventAction':'Category one',
    'eventLabel': 'Keyword',
    'event':'fire'
}); 
0
votes

You can use 2 Javascript variables to get first and second parts of URL.

To do that you can use document.location.pathname.split ('/').

Than go to Google Analytics tag - Fields to Set and set value of "page" field to /search? search_cat={{var1}}&search_query={{var2}}.

Activate this tag only on search pages.