DataSag guides · Updated 27 October 2026
Verify DataSag analytics on Grav 1.7 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 Grav 1.7 Twig themes.
Start with the Grav 1.7 Twig themes installation
These instructions target Grav's documented 1.7 Twig theme structure. Find the active theme's templates/partials/base.html.twig and add the deferred tracker inside head. Preserve existing blocks, asset output and page content. Maintain the change in a custom or inherited theme rather than an unmanaged installed-theme edit, then clear relevant caches and inspect public output.
Grav page templates commonly extend the shared base, but modular pages and custom templates can use another structure. Check the active theme and inheritance before assuming the base file covers every route. Do not treat a browser tracker as a Grav backend plugin.
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 Grav 1.7 Twig themes
- Confirm the active Grav 1.7 theme and inspect its templates/partials/base.html.twig. Trace a normal page template to that base and preserve the theme's asset and content blocks while adding the external keyed script.
- Clear the relevant theme or page cache through your normal deployment workflow, then open a public page outside Admin. Inspect the generated head and initial pageview request rather than relying on the source file alone.
- Check a modular landing page and another content template if your site uses them. Their Twig inheritance may differ. Verify whether each intended document reaches the same base and compare its tracked pathname with the public URL.
The active Twig base emits one keyed tracker for each tested template, including modular coverage checked separately.
Complete the collection checks
- 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.
- 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.
- 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.
- Open that DataSag project, choose a date range containing today and inspect the matching path. Use the configured report timezone when checking dates.
- 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 Grav 1.7 Twig themes
The shared installation belongs in the head in the active theme templates/partials/base.html.twig. 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 Grav 1.7 Twig themes guides
- Fix DataSag analytics not working
- 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 Grav 1.7 Twig themes setup guide · Search and AI visibility
References
Official Grav 1.7 Twig themes documentation covers the integration point. For DataSag data handling, read the privacy policy. Use support if a request fails after these checks.