DataSag guides · Updated 27 October 2026

Verify DataSag analytics on Drupal Twig themes

A script tag alone does not confirm that analytics works. Verify the published document, the request to DataSag and the matching visit in the correct project. 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.

Verify DataSag analytics in Drupal Twig themes

  1. Confirm the public theme or subtheme and locate its html.html.twig override. The tracker belongs in the document head, not a node or block template. Preserve Drupal's placeholder and attached-asset machinery when adding it.
  2. Rebuild relevant Drupal caches through the site's normal workflow, then open a public content route while signed out. Inspect the actual rendered script and its public key before using an authenticated administration page as evidence.
  3. Open another public route and a page using a different configured theme if one exists. Test Ajax interactions separately from document navigation; a fragment update on the same pathname does not establish another pageview requirement.

The active public document theme emits one keyed tracker, with Ajax fragments and alternate themes treated explicitly.

Complete the collection checks

  1. Open the published website in a normal browser window with the Network panel recording. Use a browser profile where you can control extensions and your consent choice.
  2. Filter network requests for tracker.js. Confirm it returns JavaScript successfully and that the rendered script has the project's data-datasag-key attribute. The example YOUR_PUBLIC_KEY must be replaced.
  3. Filter for /api/track and reload once. Inspect a request with eventName null or absent. Its projectKey and path should match the chosen project and the page you opened.
  4. Open that DataSag project, choose a date range containing today and inspect the matching path. Use the configured report timezone when checking dates.
  5. Navigate to a second path, then use Back. Compare pageview requests with the route changes rather than counting every request as a pageview.
document.querySelectorAll('script[data-datasag-key]').length
// Expected: 1

document.querySelector('script[data-datasag-key]')?.getAttribute('data-datasag-key')
// Expected: your project's public key

typeof window.datasag?.track
// Expected after the script runs: 'function'

What a successful check looks like

One rendered tracker installation, a successful request for the intended page and a corresponding entry in the intended project. Scroll and engagement requests are separate event types.

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

A successful tracker.js download only proves that a file loaded. It does not validate the project key, consent state or tracking endpoint. Test a real published path before declaring setup complete.

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

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.