Views: 5556
Number of votes: 2
Average rating:

Announcing Visitor Group Tracking and Statistics

EPiServer Visitor Groups have some basic tracking and statistics built-in which tells you how many times a Visitor Group was “visited” or tested for a match, in other words.

Many people have commented that whilst they love Visitor Groups, sooner rather than later, marketing departments or whoever is in charge of a site is going to want more information about how successful their Visitor Groups and criteria are.

Say hello to EPiServerVisitorGroupTracker

With that in mind I have developed a framework called EPiServerVisitorGroupTracker that will give programmers a large amount of information every time a Visitor Group is tested. From this information a huge array of statistics and reports can be compiled which should keep site owners busy for a while.

You hook into the information stream by adding an event handler to the framework. You should do this when the site starts, so either in the Application_Start event or in an EPiServer Initialization Module.

protected void Application_Start(Object sender, EventArgs e)
{
   EPiServerVisitorGroupTracker.
    VisitorGroupEvents.
     VisitorGroupTested += VisitorGroupTested;
}

private void VisitorGroupTested(object sender, 
                                VisitorGroupTestedEventArgs e)
{
    // Record as much or as little from the 
    // VisitorGroupTestedEventArgs as needed               
}

That's it, you're done! How much information to store and where to store it, depends on the requirements you have of course. The EPiServer Dynamic Data Store is an ideal candidate as a store.

Now the juicy bit

What information do you have access to in your event handler? The VisitorGroupTestedEventArgs class is defined as follows:

public class VisitorGroupTestedEventArgs : EventArgs
{
    public VisitorGroup VisitorGroup { get; protected internal set; }
    public IPrincipal CurrentPrincipal { get; protected internal set; }
    public HttpContextBase HttpContext { get; protected internal set; }
    public bool Matched { get; protected internal set; }
    public IEnumerable<VisitorGroupCriterion> CriteriaMatched { get; set; }
    public IEnumerable<VisitorGroupCriterion> CriteriaNotMatched { get; set; }
    public IEnumerable<VisitorGroupCriterion> CriteriaNotTested { get; set; }
    public int PointsMatched { get; set; }
    public PageReference VisitedPageReference { get; set; }
    public string VisitedPageLanguage { get; set; }
}

As you can see, there is plenty of useful information to allow site owners to determine if their Visitor Groups are matching and if not, why not by examining the CriteriaMatched, CriteriaNotMatched and CriteriaNotTested properties. You also have access to all the same information the criteria executed had via the HttpContext and CurrentPrincipal properties.

Performance Considerations

The events will only be fired if statistics are enabled for the Visitor Group in the Visitor Group Admin user interface. Obviously, capturing this information does add extra load to the site so use it with caution.

The events are fired on a separate IIS Request Thread from the original request that triggered the Visitor Group test so responses to page visitors will not be affected by the event firing.

How does it work?

It works by inserting proxies around the VisitorGroupRole class from EPiServer and the criteria classes that EPiServer and others develop. The information presented in the VisitorGroupTestedEventArgs class is captured in these proxies. Unfortunately, I had to use reflection is two places to achieve this but I have a couple of friends on the inside at EPiServer who I can talk to about making the Visitor Group API’s more open in EPiServer vNext Winking smile

Where can I get this?

The EPiServerVisitorGroupTracker assembly is available from EPiServer’s Nuget feed and the source code is available from http://episervervgtracker.codeplex.com

Happy tracking!

    (By Jeff Wallace , 23 August 2011 16:50, Permanent link)

    Marketing teams will definitely want to report on some of these metrics. Nice work Paul!

    (By Guest , 27 March 2017 12:36, Permanent link)

  Please login to post a comment