Track site search does not work for views with enabled ajax

Created on 19 September 2023, 9 months ago

Problem/Motivation

When using a view with an ajax-enabled search, the trackSiteSearch event works correctly on the initial page load. However, subsequent ajax search actions on the same page are not tracked. This issue arises because the search tracking code is injected into the html_head, which does not function properly for ajax callbacks.

Steps to reproduce

To reproduce this issue:

  1. Enable ajax functionality for a view containing a search feature.
  2. Visit a page with this view.
  3. Open the browser's network tab.
  4. During the first page load, observe that the trackSiteSearch event is triggered in the network tab.
  5. Enter a search query in the filter and perform an ajax submit.
  6. Notice that no trackSiteSearch event is triggered for the ajax search.

Proposed resolution

To address this problem, it is not feasible to rely on the current html_head approach. One solution is to:

  1. Move the search tracking code to a views element data attribute.
  2. Transfer the tracking search code to a new JavaScript file.
  3. Process the data attribute within the JavaScript code.

This approach will ensure that tracking works seamlessly for both ajax and regular search page loads.

API changes

It's important to note that ViewsPostRenderHookHandler::process() requires some modifications in its method signature and code. Hopefully this method is used only inside of matomo module.

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡·πŸ‡ΈSerbia pivica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024