Content management systems
Add Loogika to Umbraco
Every Umbraco page comes from a Razor template, a .cshtml file that lives in the Views folder. Add the Loogika tag to the master template that your page templates use as their Layout, just before the closing head tag. You can edit the template in the backoffice under Settings, then Templates.
Last updated .
What do you need before you start?
Copy your script tag from Site Settings in Loogika, under the Tracking Script tab. It looks like this, with your own site ID in place of YOUR_SITE_ID:
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
How do you add Loogika to the Umbraco master template?
Paste the tag into the head of the master template and save. Step 2 also covers a fresh Umbraco install, where you have to create the first template yourself.
- Open the Settings section in the backoffice and expand Templates.
- Find the master template, the one your page templates name as their layout, and open it. The Umbraco tutorial names it Master. If you have none, click the three dots next to Templates and choose Create. Then move the shared
<html>,<head>and<body>markup into the new template. - Add the tag before
</head>and click Save. - Check that each page template points at the master template, for example with
Layout = "Master.cshtml";.
@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.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>
<body>
@RenderBody()
</body>
</html>
A page template with Layout = null; renders its own <head>. Add the tag directly to such a template.
A save in the backoffice writes the file Views/Master.cshtml in the project. You can edit the same file in your code editor and commit it.
How do you store the site ID outside the template?
The file appsettings.json can hold the site ID. Inject IConfiguration into the template and read the value with @Configuration["Loogika:SiteId"] in place of the ID.
How do you check that Loogika is installed?
Load your site in a fresh browser tab and visit a few pages. Loogika shows the pageviews in the dashboard within a few seconds. If nothing arrives, open the page source and look for script.js?siteId=.
Why is the change not visible on the Umbraco site?
A Razor view is compiled when Umbraco first serves it. A published site therefore needs an app restart or a new deploy after you change the file outside the backoffice. Clear any output cache or CDN (content delivery network) in front of the site as well.
When an install runs several sites and each has its own layout, every one of those layouts needs the tag. You can also place the tag in a partial view and render it from every layout:
@await Html.PartialAsync("Loogika")
Does the Umbraco preview count as visits?
Yes, unless you exclude it. The Preview button in the backoffice renders your template with unpublished content, and Loogika treats that view as a normal visit. A preview check around the tag leaves editors out:
@if (!UmbracoContext.InPreviewMode)
{
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
}
The backoffice itself is never tracked. Your templates are not used by the pages under /umbraco, which run as an app of their own.