Google Analytics

With the JS Implementation you can keep track of the search phrases entered by your customers. When enabled, every time a search term is entered, the JS Implementation will send an event to Google Tag Manager. Then, in Google Tag Manager, you will be able to forward this event to Google Analytics.


This article assumes you already have Google Tag Manager integrated in your platform. For more information on how to do this click here.

Enabling analytics

The first step in measuring the search phrases is enabling the analytics option for the JS Implementation. This part is easy, as we can change this in the JavaScript file provided by us.


Alternatively, you can override the configuration of the JS Implementation using JavaScript locally. With this approach you can set the analytics option yourself using JavaScript. For more information on how to do this click here.

Configuring Google Tag Manager

After the analytics option has been enabled for the JS Implementation, we can start with the configuration in Google Tag Manager. By following the steps below you will create the necessary variables, triggers and tags in Google Tag Manager that are needed to handle the search phrase event and send it to Google Analytics.

Step 1: Create a variable

In Google Tag Manager, create a new variable called SearchTerm. This variable should be of type Data Layer Variable and have query as its Data Layer Variable Name.

Step 2: Create a trigger

Next, create a new trigger called Search. This trigger should be of type Custom Event and have Search as its Event name.

Step 3: Create a second trigger

A second trigger should be created with the name Search.timed. It should be of type Custom Event and have Search.timed as its Event name.

Step 4: Create a tag

Next, create a new tag called Trigger search after 3s. This tag should be of type Custom HTML and have the (previously created) Search trigger as its firing trigger. The content of the HTML should be as follows:

  (function() {

    window.twSearchTimer = window.setTimeout(function() {
        'event': 'Search.timed',
        'query': {{SearchTerm}}
    }, 3000);

The final tag should look like this:

Step 5: Create a second tag

Lastly, you need to create a new tag called Search. It should have a type of Google Analytics: GA4 Event.

Set a configuration tag or the measurement ID to connect it to your Google Analytics account.

The tag should have an event name of search and it should contain a parameter called search_term that has the value of the (earlier created) SearchTerm variable.

Step 6: Publish

The only thing that is left is publishing your Google Tag Manager environment. After that, every time a user enters a search term a search event will be sent to your Google Analytics environment. This event will have a parameter called search_term which can be used to keep track of the search phrases.