DataSag guides · Updated 27 October 2026

Load analytics without blocking rendering on PHP templates

Use the platform's non-blocking external script mechanism and install the tracker once. Measure the published page before and after the change; script size alone cannot predict the effect on your website. This guide applies to PHP templates.

Start with the PHP templates installation

Add the deferred external script once to the local PHP include that emits your public HTML head. Preserve the existing document structure and include that file through a known local path in the pages you intend to measure. The tracking snippet itself is HTML; it does not need a PHP analytics library.

An independent PHP endpoint may return JSON, redirect before rendering, or use another header include. Keep the tracker in rendered HTML and avoid inserting output before code that needs to send response headers. Do not derive an include path from visitor input.

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.

Load analytics without blocking rendering in PHP templates

  1. Use defer on the external script emitted by the shared PHP header and keep it after any server code that must send response headers. Remove a duplicate synchronous snippet from the final HTML.
  2. Measure the deployed PHP document under fixed network and cache conditions. Include the actual server response time separately from browser download and execution so a backend cache change is not attributed to analytics.
  3. Test a nested page and the first intended action. If your PHP frontend uses partial updates, confirm they do not insert the global tracker again. A small cached transfer does not prove there is only one execution.

The PHP output loads one tracker without parser blocking and the measurement separates backend response cost from browser work.

Complete the collection checks

  1. Record a baseline of the published page using the same browser, device emulation and network settings you will use for comparison. Include a representative content page, not only the homepage.
  2. Use defer for a normal external HTML script, or the framework-specific loading strategy shown in the installation example. Do not add a parser-blocking synchronous script as a shortcut.
  3. Keep one installation in the shared document or layout. Duplicate execution adds work even if the browser reuses the downloaded file.
  4. Inspect the Network waterfall for tracker.js and /api/track. Compare transfer size, timing and request count on a cold load and a cached load.
  5. Check that measurement still starts at the intended point. Loading only after idle or interaction can omit short visits and early clicks; performance and coverage must be evaluated together.
  6. Repeat the measurements and record variability. Report measured results for your page rather than claiming a universal speed improvement or zero performance cost.
// Browser Console, after loading the published page:
performance.getEntriesByType('resource')
  .filter(entry => entry.name.includes('/tracker.js'))
  .map(entry => ({ url: entry.name, durationMs: entry.duration }));
// Cross-origin transfer details may be unavailable.

What a successful check looks like

The script uses a non-blocking loading mechanism, appears once and records the intended visits. Any performance claim comes from repeatable measurements of the actual site.

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 faster lab result does not prove every visitor has a faster experience. Avoid mixing a warm-cache result with a cold-load baseline.

Installation snippet for PHP templates

The shared installation belongs in the head emitted by the shared PHP header include. 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 PHP templates guides

Full PHP templates setup guide · Search and AI visibility

References

Official PHP templates documentation covers the integration point. For DataSag data handling, read the privacy policy. Use support if a request fails after these checks.