Skip to content

Instantly share code, notes, and snippets.

@davidknipe
Created January 9, 2018 08:58
Show Gist options
  • Select an option

  • Save davidknipe/e11dbc4f17ff07c01645f73f096cf5cb to your computer and use it in GitHub Desktop.

Select an option

Save davidknipe/e11dbc4f17ff07c01645f73f096cf5cb to your computer and use it in GitHub Desktop.
using System.Web;
using EPiServer.Core;
using EPiServer.Tracking.Core;
namespace AlloyDemoKit.Business.Insight
{
public class TrackingExample
{
private readonly ITrackingService _trackingService;
private readonly HttpContextBase _httpContextBase;
public TrackingExample(ITrackingService trackingService, HttpContextBase httpContextBase)
{
_trackingService = trackingService;
_httpContextBase = httpContextBase;
}
public void Track(IContent page)
{
var trackingData = new TrackingData<Pageview>
{
EventType = typeof(Pageview).Name,
User = new UserData
{
Email = EPiServer.Personalization.EPiServerProfile.Current.Email,
Name = EPiServer.Security.PrincipalInfo.CurrentPrincipal.Identity.Name
},
Value = "Page viewed - " + page.Name,
Payload = new Pageview
{
PageName = page.Name,
PageId = page.ContentLink.ID
}
};
_trackingService.Track(trackingData, _httpContextBase);
}
}
public class Pageview
{
public string PageName { get; set; }
public int PageId { get; set; }
}
public class DefaultPageController : PageControllerBase<SitePageData>
{
public ViewResult Index(SitePageData currentPage)
{
ServiceLocator.Current.GetInstance<TrackingExample>().Track(currentPage);
// Controller logic
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment