DataSag guides · Updated 27 October 2026
Fix DataSag analytics not working on Drupal Twig themes
Find the first missing step in the delivery chain: published HTML, executing tracker, tracking request, successful response and project report. Changing several settings at once makes the failure harder to identify. This guide applies to Drupal Twig themes.
Start with the Drupal Twig themes installation
Use a maintained custom theme or subtheme and identify its html.html.twig document wrapper. Add the deferred tracker inside head while preserving Drupal's existing placeholders, attributes and attached assets. Rebuild the relevant caches and inspect the public rendered document. Do not edit Drupal core or replace the full wrapper with a minimal example.
The active public theme and the administration theme can differ. A node or block template is not the global document wrapper, and Ajax-rendered fragments do not represent independent document loads. Check public routes, caching and any separately configured theme before assuming complete coverage.
Use the public project key from the DataSag project you are inspecting. A test on a preview domain does not confirm that the production domain has the same code or settings.
Fix DataSag analytics not working in Drupal Twig themes
- Identify the theme rendering the affected public route. Drupal may use a separate administration theme or route-specific theme behavior, so a tracker visible in Admin does not prove it exists in the visitor document.
- Inspect html.html.twig inheritance and the public response after rebuilding relevant caches. A node or block override only affects that fragment. Preserve required placeholders and asset output while moving a loader to the real document wrapper.
- If the missing event follows an Ajax form or dynamic component update, inspect the browser success handler and Drupal behavior attachment path. PHP preprocess functions cannot call window.datasag, and a validation response is not a successful conversion.
The diagnosis separates public-theme coverage, cached document output and Ajax action success rather than treating a fragment as a page.
Complete the collection checks
- Confirm the change reached the public domain. Inspect the live HTML and clear only caches that serve the old document. A saved editor change may still need publishing.
- Check that tracker.js exists in the Network panel and that the script contains the public key from the same DataSag project you are viewing.
- Check whether your test browser is excluded with datasag_ignore. Restore inclusion with ?datasag_ignore=false only if this browser should count. Respect any consent controls configured on your site.
- Inspect the browser Console for Content Security Policy or script errors. Check /api/track request responses: 400 indicates invalid input, 404 can indicate an unknown project key, and a server failure needs investigation rather than repeated snippet changes.
- Try a controlled browser profile to identify an extension block. Do not bypass a visitor's privacy preferences. Then check the project's selected date range, path and domain.
- Collect the affected public URL, approximate time, request status and installation location for support. Omit account credentials and visitor data from screenshots.
typeof window.datasag?.track
// If undefined, first investigate whether the script executed.
new URL(location.href).searchParams.get('datasag_ignore')
// Also check for a previously saved browser exclusion.What a successful check looks like
The first failed boundary is identified and corrected, and a new controlled visit reaches the right project. The browser Console and Network panel provide the evidence.
Record the public path you tested, the browser state, the approximate time and the observed request. Check one direct page load and one later navigation so the result covers more than the homepage.
Common mistake
Do not replace the public project key with a Supabase, Stripe or provider secret. The browser snippet uses only the project's public tracking key.
Installation snippet for Drupal Twig themes
The shared installation belongs in the head in your custom theme html.html.twig override. Use this as the installation reference while checking the procedure above.
<script defer src="https://www.datasag.com/tracker.js" data-datasag-key="YOUR_PUBLIC_KEY"></script>Related Drupal Twig themes guides
- Verify DataSag analytics
- Fix duplicate analytics pageviews
- Track custom events
- Track UTM campaigns
- Measure AI referral traffic
- Configure CSP for DataSag analytics
- Exclude your own analytics visits
- Load analytics without blocking rendering
Full Drupal Twig themes setup guide · Search and AI visibility
References
Official Drupal Twig themes documentation covers the integration point. For DataSag data handling, read the privacy policy. Use support if a request fails after these checks.