Site Search Tracking In Google Analytics | BCS

Site Search Tracking In Google Analytics

Google Analytics Haran Huang 2 years ago (2019-12-12) 749 Views 0 Comments

We know that the  search console report in Google Analytics is very useful, not only to know what the user has searched, but also to know some behavior after the search.

This report needs to be set before data is available:

  • If the URL after your search meets the specifications, for example, the search URL of your website is as follows: http://www.bbccss.com/?q=keyword, this is normal, then the setup is simple.
  • If your search URL does not meet the specifications, your site’s search URL looks like this: https://www.bbccss.com/search / keyword,  this is irregular,  you need to make some adjustments in Google Tag Manager.

Let’s take a look at how to set up these two situations:

Normal

Our search URL is http://www.bbccss.com/?q=keyword, this setup is very simple, use query parameters directly

Use Query Parameters

In the Google Analytics, click View Settings. Under Site Search Settings, set Site Search Tracking to ON:

Site Search Tracking In Google Analytics

 

  • Query parameter: enter the word or words that designate internal query parameters, such as term, search, query, keywords. Sometimes query parameters are designated by just a letter, such as s or q. Enter up to five parameters, separated by commas. Do not enter any additional characters, The search URL here is: http://www.bbccss.com/?q=keyword, just enter q.
  • Strip query parameters out of URL: Select whether or not you want Analytics to strip the query parameter from your URL. This strips only the parameters you provided,Generally not set.
  • Site search categories:If there are multiple search locations on the website and you need to distinguish between different search locations, you need to turn it on.

Here, our search URL is http://www.bbccss.com/?q=keyword, so we need to set q in Query parameter, the complete setting is as follows:

Site Search Tracking In Google Analytics

That’s it,  Site Search Report  in Google Analytics will have data.

Irregular

If the URL of your search result is like this: https://www.bbccss.com/search/keyword, this is irregular. Such as my blog search:

Site Search Tracking In Google Analytics

We can’t set it directly through Site Search Settings, but we can rewrite the URL through Google Tag Manager so that the URL meets the structural requirements of Site Search Settings, which is the structure of q = keyword. There are many ways to achieve it

Filter

If the search results are like this: https://www.bbccss.com/search/keyword

Let’s take a look at how the page field is displayed in Google Analytics, If the page field shows /search/keyword. Then we can create a filter and do the following settings:

Field A -> Extract A: Request URI: ‘^/search/(.*)’
Output To -> Constructor: Search Term: ‘$A1’
Select ‘Field A required’ and ‘Override Output Field’

The detailed settings are as follows:

Site Search Tracking In Google Analytics

 

The function of this setting is to store all the information after /Search/ in $A1, and then assign it to the Search Term field.  Search Term is the search field in the site.

URL Rewriting

Let’s take a look at how to achieve URL rewriting.

Create a Custom JavaScript

Create a Custom JavaScript in Google Tag Manager and name it Search,Then copy the following code into it:

<span style="font-size: 12pt;">function(){
  var url= document.URL
  if (url.indexOf('/search/')>-1){
    return url.slice(30)
  }
}
</span>

The function of this code is to intercept the characters after / search /, that is, the search word, as a variable.

Effect after configuration:

Site Search Tracking In Google Analytics

Configure Trigger

Create a trigger named Search Pages and configure it as follows:

Site Search Tracking In Google Analytics

The function of this trigger is that only the URL contains /search/.

Configure Tag:Rewrite Search URL

Create a Tag named: Rewrite Search URL,Then do the following settings:

Site Search Tracking In Google Analytics

The important point is to set the page to {{Search}} variable in the Field to Set,  the function of this step is to rewrite the URL and rewrite /search/keyword to q=keyword, and the trigger selects Search Pages.

Adjust the default Google Analytics Tags

Adjust the default Google Analytics Tags to exclude Search Pages, otherwise it will trigger twice. Google Analytics Tags are the tags that send data to Google Analytics:

 

Site Search Tracking In Google Analytics

Set Site Search Settings

Set Site Search Settings after URL adjustment specifications:

Site Search Tracking In Google Analytics

Preview and Test

Site Search Tracking In Google Analytics

 

Back to Google Analytics real-time reporting:

Site Search Tracking In Google Analytics

 

The URL in Google Analytics has changed.

Data layer

The method of the data layer is to obtain the search keywords and send them through the data layer, and then rewrite the page. In fact, the principle is to rewrite the page.

Configure Tag: Create custom HTML

The configuration is as follows: The function of this code is to determine whether it is a search by url, if it is, get the keyword, and then send it out through DataLayer.

Site Search Tracking In Google Analytics

 

Configure Trigger

Create a custom event in the trigger in Google Tag Manager and do the following configuration:

Site Search Tracking In Google Analytics

The search here is the event in the DataLayer.

Configuration Variable

Create a Data Layer Variable in the variable and do the following configuration:

Site Search Tracking In Google Analytics

 

Configure Tag: Turn Events Into Page

Configure a tag to convert a custom event into a page. In fact, the principle of this step is to rewrite the url.

Site Search Tracking In Google Analytics

Set Site Search Settings

Set Site Search Settings after URL adjustment specifications:

Site Search Tracking In Google Analytics

Preview and Test

Site Search Tracking In Google Analytics

More

In fact, there are many ways. The principle is to rewrite the page field.

For example, you can write the keyword to the cookie, or obtain it through custom JavaScript, and then rewrite it.


If you don't understand, You can leave a comment below or email me (haran.huang@ichdata.com).
Like (0)
Post my comment
Cancel comment
Expression Texture Bold Strikethrough Center Italic Sign in

Hi, you need to fill in your nickname and email!

  • Nickname (required)
  • Email (required)
  • Website