Created
January 9, 2018 08:58
-
-
Save davidknipe/e11dbc4f17ff07c01645f73f096cf5cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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