Backends

ASP.NET Core
ASP.NET Core analytics with Stickybeak starts by adding its script to your rendered pages; this guide shows you where it belongs and how to track page views, goals and purchase revenue. It is a lighter alternative to Google Analytics for ASP.NET Core, with live visitors, goals and revenue attribution in one script.
Add the script
Add the site ID to configuration
Copy the ID from Settings in the dashboard. Put it in
appsettings.Production.json, or set the environment variableStickybeak__SiteIdon your production host:{ "Stickybeak": { "SiteId": "YOUR_SITE_ID" } }Add it to your layout
Put this before
</head>:@inject Microsoft.Extensions.Configuration.IConfiguration Configuration <script>window.stickybeak = window.stickybeak || function () { (window.stickybeak.q = window.stickybeak.q || []).push(arguments); };</script> <environment include="Production"> @if (Configuration["Stickybeak:SiteId"] is { Length: > 0 } siteId) { <script defer data-site="@siteId" data-domain="example.com" src="https://app.usestickybeak.com/_cfw/s.js" ></script> } </environment>
Check it's working
Publish first, then follow Verify your install.
Track goals
Give any button or link a data-goal attribute. See Custom goals.
<a asp-page="/Pricing" data-goal="view_pricing">Pricing</a>
Fire a goal after a redirect
TempData is available to the next request and is removed after it is read. Store the goal as JSON:
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid) return Page();
var user = await _accounts.RegisterAsync(Input);
TempData["StickybeakGoal"] = JsonSerializer.Serialize(new { name = "signup", props = new { plan = user.Plan } });
return RedirectToPage("/Welcome");
}
@if (TempData["StickybeakGoal"] is string goalJson)
{
<script>(function (g) { window.stickybeak(g.name, g.props); })(@Html.Raw(goalJson));</script>
}
Track purchases
TempData["StickybeakGoal"] = JsonSerializer.Serialize(new {
name = "purchase",
props = new { revenue = order.Total, currency = order.Currency, order_id = order.Number },
});
See Revenue.
Page changes
In a Blazor Web App, put the tag in <head> in Components/App.razor.
await JS.InvokeVoidAsync("stickybeak", "signup", new { plan = "pro" });
If it isn't working
- Check
ASPNETCORE_ENVIRONMENT=Productionand the production setting.
See Troubleshooting.