Configure Google Analytics 4 (GA4) with Site Search

If you already have a Google Analytics 4 account, you can configure your Google Analytics 4 (GA4) and use Search Element Callback to get a detailed search queries report.

If you do not have a Google Analytics 4 account, you will need to create a Google Analytics 4 account and then configure your Google Analytics 4 account.

Make sure you have enabled Site Search in GA4 to capture a view of search events each time a visitor performs a search on your site:

https://support.google.com/analytics/answer/9216061

Once your Google Analytics 4 (GA4) is configured correctly,  Search Element Callbacks can be used on your website where you have implemented your Programmable Search Engine implementation code and your Google Analytics 4 tracking code.  Your callback should call the GA4 'gtag' function with the 'search' event using the given query.

Example Code:

const myWebSearchStartingCallback = (gname, query) => {

   gtag("event", "search", { search_term: query });

   return '';

};

 

window.__gcse || (window.__gcse = {});

window.__gcse.searchCallbacks = {

  web: {

    starting: myWebSearchStartingCallback,

  },

};

 

Configure your Google Analytics 4 to generate report to identify what your visitors search on your website:

https://support.google.com/analytics/answer/13169197

Note: Once all the settings are configured, GA4 reports will take 24/48 hours to reflect the searches performed on your Engine.

For support on queries related to GA4 configuration, please contact:

https://support.google.com/analytics/answer/9026876

https://support.google.com/analytics/gethelp

https://support.google.com/analytics/community

Search
Clear search
Close search
Google apps
Main menu
18446740448089236376
true
Search Help Center
true
true
true
false
false