Skip Navigation

[Resolved] Track Ajax custom search with Google Analytics

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to track AJAX custom searches with Google Analytics.

Solution:

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
    /**
    * data.view_unique_id (string) The View unique ID hash
    * data.layout (object) The jQuery object for the View layout wrapper
    */
 
    // add any custom JS code here.
 
});
This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 5 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#911946

Tell us what you are trying to do?
We want to trigger a Google Analytics event when a user filters the search results on this page: hidden link
The event code is:
ga('send', 'event', 'Providersearch', 'Treatment Approach', 'Test', 1);
We want to populate the value called 'Test' with the term or terms that the person put into their search (either as a loop through the values they submitted or a comma-separated list of values.

Is there any documentation that you are following?
hidden link
Is there a similar example that we can see?

What is the link to your site?
hidden link

#912084

Hi, I can show you how to trigger your own custom JavaScript when an AJAX form's search results have been updated. Open the Search and Pagination section's JS editor panel in the View editor screen and click the "Frontend Events" button. The wizard will insert the basic event structure for you, like this:

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
	/**
	* data.view_unique_id (string) The View unique ID hash
	* data.layout (object) The jQuery object for the View layout wrapper
	*/

	// add any custom JS code here.

});

This requires that you enable AJAX View updates. If you don't want to use AJAX View updates, you can add your custom JS code there without any event listener callback, and it will be automatically run whenever the page reloads with the selected filters applied to the URL.

You can access any URL parameters with JS and apply them to the GA tracking call:

https://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters

That type of custom code falls outside the scope of support we provide here in the forums, but a skilled developer would be able to assist you. We have a portal set up where you can connect with contractors who may be able to set this up: https://toolset.com/contractors

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.