Retrieve segment information from code
Sometimes you need more fine-grained personalization for your website. For this purpose the Umbraco Engage exposes a service called the IAnalyticsStateProvider.
using System.Web.Mvc;
using Umbraco.Engage.Business.Analytics.State;
using Umbraco.Web.Mvc;
public class HomeController : SurfaceController, IRenderController
{
private readonly IAnalyticsStateProvider _analyticsStateProvider;
public HomeController(IAnalyticsStateProvider analyticsStateProvider)
{
_analyticsStateProvider = analyticsStateProvider;
}
...
}public ActionResult HomeTemplate()
{
var analyticsState = _analyticsStateProvider.GetState();
foreach (var pageviewSegment in analyticsState.Pageview.PageviewSegments)
{
if (pageviewSegment.Segment.Name == "MySegment")
{
// Execute custom code
}
}
...
}Last updated
Was this helpful?