Troubleshooting Analytics Click Tracking in Drupal

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:

  1. The module's searchstax_preprocess_views_view function adds a data-searchstax-results attribute to the results container.
  2. 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

  1. Go to your search results page.
  2. View the page source (right-click > View Page Source, or Ctrl+U / Cmd+U).
  3. 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:

  1. Clear your Drupal cache.
  2. View the page source again and confirm data-searchstax-results is present.
  3. Perform a few test searches and click on results.
  4. Check your Analytics dashboard. Click data may take up to an hour to appear.

Related Resources

Articles in this section