Integration Guides
Umbraco
Add OnyxMetric analytics to your Umbraco site
Umbraco renders pages with Razor templates stored as .cshtml files in Views, editable in the backoffice under Settings > Templates. Put the tag in the master template.
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 Umbraco
- In the backoffice, open Settings and expand Templates.
- Open the master template your other templates use as their layout. If you have none, create one and point your page templates at it.
- Add the tag before
</head>and click Save:
@using Umbraco.Cms.Web.Common.PublishedModels;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>@Model.Name</title>
<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>
</head>
<body>
@RenderBody()
</body>
</html>- Check that each page template points at it, for example
Layout = "Master.cshtml";. A template withLayout = null;renders its own<head>and needs the tag added directly.
Saving in the backoffice writes the file to Views/Master.cshtml in the project, so you can also edit it in your IDE and commit it.
To keep the ID out of the template, store it in appsettings.json and read it through IConfiguration.
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
- Change not visible: Razor views compile on first request. If you edited the file outside the backoffice on a published site, restart the app or redeploy.
- Preview counts as visits: the backoffice Preview button renders your template with unpublished content, so editor previews are tracked.
- Backoffice is not tracked:
/umbracois a separate app that does not use your templates. - Several master templates: a multi-site install with one layout per site needs the tag in each, or in a partial view rendered from every layout.
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.