The data-searchstax-results tracking attribute is required for click analytics. If you're using a custom Drupal Views template and your Analytics dashboard shows searches but zero clicks, this attribute is likely missing from your template.
How Click Tracking Works
The SearchStax Drupal module tracks clicks in two steps:
- The module's
searchstax_preprocess_views_viewfunction adds adata-searchstax-resultsattribute to the results container. - The tracking script (
searchstax.tracking.js) looks for that attribute to attach click handlers.
If the attribute is missing, the tracking script can't find your results. Clicks won't be tracked.
Why Custom Templates Can Break Click Tracking
When you create a custom Views template (like views-view--product-search.html.twig), you control what gets rendered. If your template doesn't include the {{ attributes }} variable, the data-searchstax-results attribute won't appear in the output.
How to Verify the Issue
- Go to your search results page.
- View the page source (right-click > View Page Source, or Ctrl+U / Cmd+U).
- Search for
data-searchstax-results.
If the attribute is missing, that's likely causing your click tracking issue.
How to Fix It
You've got two options:
Option 1: Include the attributes variable (recommended)
Add {{ attributes }} to your custom Twig template on the results container element. This renders all attributes from Drupal and its modules, including data-searchstax-results.
Option 2: Hardcode the attribute
Add data-searchstax-results directly to the container element in your template:
<div class="view-content" data-searchstax-results>
{# your results loop here #}
</div>
Verifying the Fix
After making the change:
- Clear your Drupal cache.
- View the page source again and confirm
data-searchstax-resultsis present. - Perform a few test searches and click on results.
- Check your Analytics dashboard. Click data may take up to an hour to appear.
Related Resources
- Tracking API (Javascript): Details on how analytics events work
- Why you should move from Drupal Views to UI Kits: An alternative approach that handles analytics automatically