Hi ! h_title
Support
Home
Developers
Javascript implementation
Javascript implementation

Heads up! We have a new documentation site and this article has been rewritten.

Check out the latest version of this article →

Searches made from a Javascript implementation can be measured in two ways:

  1. Measure searches with a direct Google Analytics implementation
  2. Measure searches with Google Tag Manager

1. Measure searches by means of direct Google Analytics implementation

Measuring searches using a direct Google Analytics implementation uses the analytics.js script by Google. This script needs to be implemented on the site or page separately.

For more information, click here.

Step 1: Setup in Tweakwise App

To configure Google Analytics in the Tweakwise App, find the 'JS implementation' module in the sidebar. Choose the 'Google Analytics' type:

This setting sends a 'Page view' to Google Analytics when a visitor executes a search. The URL of the 'Page view' will be sent like this: “/search?tn_q={{searchterm}}”.

Step 2: Setup in Google Analytics

The right search parameter needs to be set in order for Google Analytics to understand where in the URL the search term is located. This can be done in the 'View Settings' on the 'Admin' page.

Set up the Site Search Settings like this:

2. Measure searches with Google Tag Manager

The measurement of searches using Google Tag Manager uses the Google Tag Manager script by Google. This script needs to be implemented on the site or page separately.

For more information on the implementation, click here.

Step 1: Setup in Tweakwise App

To configure Google Analytics in the Tweakwise App, find the 'JS implementation' module in the sidebar. Choose the 'Google Tag Manager' type:

Step 2: Setup in Google Tag Manager

Various Variables, Triggers, and Tags need to be created in Google Tag Manager in order to measure the search term. To prevent any pollution of Google Analytics search terms, we will pass the search term on to Google Analytics after 3 seconds.

Step 3: Create a variable that can extract the search term from the event

This variable has the 'Data Layer Variable' type and the 'query' name.

Step 4: Create a 'Search' trigger

This trigger has the 'Custom Event' type and the 'Search' name.


Step 5: Create a 'Search timed' trigger

This trigger has the 'Custom Event' type and the 'Search.timed' name.

Step 6: Create a 'Trigger search after 3s' tag

This tag has the 'Custom HTML' type and the 'Search' trigger as firing trigger. The content of the HTML is as follows:

<script>

(function() {


  clearTimeout(window.twdSearchTimer);

  window.twdSearchTimer = window.setTimeout(function(){


    window.dataLayer.push({

      'event': 'Search.timed',

      'query': {{SearchTerm}}

    });

   

  }, 3000);


})();

</script>

Step 7: Create a 'Page view' tag

This tag has the 'Google Analytics: Universal Analytics' type and the 'Page View' track type. The firing trigger of this tag needs to be the just created 'Search.timed'.

It's important to note that the 'Enable overriding settings in this tag' needs to be checked. Next, you can add the 'page' field with the value “/search?tn_q={{SearchTerm}}” under 'More settings > Fields to set'.

 

Step 8: Setup Google Analytics

The right search parameter needs to be set in order for Google Analytics to understand where in the URL the search term is located. This can be done in the 'View Settings' on the 'Admin' page.

Set up the Site Search Settings like this:

 

 


Has reading the relevant articles not helped you?

Share article

Link copied to clipboard

Cookies

We are using cookies.

Want to know more? Take a look at our cookie statement.

The Livechat uses trackingcookies, do you accept these cookies?

Accept