Skip to main content
Skip table of contents

Internal search measurement

Navigating a website by search terms is a very common thing, hence the search bar on most sites is more prominently placed than the main navigation. Accordingly most website owners want to use this informations typed in by users to optimize their website. So if that sounds interesting to you, here is the guide to implement the according measurement of search terms and events with JENTIS Data Capturing platform.

Advanced Skills Note

This content's target audience is experienced JENTIS Tag Manager users who are also experienced with JavaScript coding.

Site Search Events Implementation

In this guide we will use the JENTIS Tag Manager Codes elements to populate the search events at the right time. Based on URL query parameters that indicate a search term. Thus activating a JENTIS Data Layer tracking call and according tags.

Foundation of this is the JENTIS Data Layer model for search events: Internal Search Tracking

Whenever this native data model is used and submitted to JENTIS it will automatically forward the information to all tags with a default setup. For example tools in JENTIS like GA4, Facebook CAPI, etc. come automatically with tags for search events tracking, like the "view_search_results" event within the GA4 model.

So lets start with the implementation.

Code Implementation

The following code will use the default JENTIS State to track a "search" JENTIS Data Layer object. With the advantage of leveraging all the defaults, as by design there are triggers and tags already configured to activate on those "search"-events.

You can just navigate to your JENTIS accounts Server Tag Manager: Codes area. Here, add a new code with the following properties: name and description up to your gusto; the JavaScript code is:


var params = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
    params[key] = value;

var search_term = "";

for(par in params){
  if(SEARCH_QUERY_PARAM_LIST.indexOf(par) >= 0)
    search_term = params[par];

if(search_term && search_term != "")
    "track" : "search",
    "group" : "internal site search",
    "term"  : search_term

Leave the trigger on "JTS Framework Loaded" to activate this code on all page load events.

The configuration in the first line of code is:

- SEARCH_QUERY_PARAM_LIST: Array (Strings) of query parameter keys that might hold a search term, if multiple entries are in the URL the most recent will be used (the last in the queue); feel free to add other query parameters if they are not in the list yet (q, s, search, query and keyword are the most common parameter keys for searches)

What this code will do is to look on all pages for those URL query parameter keys. If present the according term from the parameter value will be tracked as the search term. The JENTIS Data Layer model "search" (document) and a static group ("internal site search") as also the dynamic search term ("term") will be populated. The according default variable for the search term in your JENTIS account is "Search term".

Now it is up to you to either just install default tags for search events or define your own triggers and tags.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.