TYPO3
Add OnyxMetric analytics to your TYPO3 site
TYPO3 sitepackages build the page <head> from TypoScript rather than an HTML template. Add the script as a page.includeJS entry in your sitepackage's setup file.
Copy your tracking snippet
In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:
<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>YOUR_SITE_ID is the numeric ID of your site.
Add the snippet to TYPO3
-
Open your main TypoScript setup file, usually
<sitepackage>/Configuration/TypoScript/setup.typoscript. It is the one that already containspage = PAGE. -
Add the script to the
pageobject:page = PAGE page { includeJS { onyxmetric = https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID onyxmetric.async = 1 } }The site ID is part of the URL, so no
data-*attribute is needed and this works on every supported TYPO3 version. -
To track production only, wrap the include in an
applicationContextcondition:[applicationContext == "Production"] page.includeJS.onyxmetric = https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID page.includeJS.onyxmetric.async = 1 [END] -
Optionally keep the ID in
constants.typoscriptso the setup file can be committed without site-specific values:# constants.typoscript onyxmetric { siteId = YOUR_SITE_ID } # setup.typoscript page.includeJS.onyxmetric = https://app.onyxmetric.com/api/script.js?siteId={$onyxmetric.siteId} page.includeJS.onyxmetric.async = 1 -
Deploy the sitepackage and flush the TYPO3 caches.
Check that it works
Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.
If nothing arrives:
- View the page source and search for
script.js?siteId=to confirm the tag is present. - In the browser's Network tab, check that
script.jsreturns200and that requests go to/api/track. - Turn off ad blockers, or proxy the script through your own domain.
- Read script troubleshooting for other causes.
Troubleshooting
- Script not in the page source: TYPO3 caches rendered pages. Flush caches from the backend toolbar or run
vendor/bin/typo3 cache:flush. - Wrong TypoScript file: if several files define
page, open the TypoScript object browser and check the resultingpage.includeJS. - Condition never matches:
applicationContextcomes from theTYPO3_CONTEXTenvironment variable. If it is unset, TYPO3 runs asProduction, so check the value on each environment.
Next steps
- Track custom events such as signups, purchases, and clicks.
- Identify users to tie sessions to accounts.
- Proxy the script through your own domain to get past ad blockers.
- Script attributes let you skip or mask URLs and tag events.