Area: Episerver Profile Store
Applies to versions: Tracking.Core 1.9 and higher

Visitor group tracking

If you want to see a report about users who "visited the Contact Us page," you can create a visitor group with that criteria, and then track the visitor group. To filter by visitor groups, you need to update your solution’s tracking events to send the user’s visitor group information, because the standard installation currently does not add this tracking event by default.

EPiServer.Tracking.Cms 1.9.0 provides a new extension method: ITrackingService.TrackVisitorGroup(TrackingData<VisitorGroupTrackingDataWrapper>, HttpContextBase). Calling this method sends a track event with visitor group track data in the payload.

Note: This is similar to calling the ITrackingService.Track<TPayload>(TrackingData<TPayload>, HttpContextBase) method with TPayload is VisitorGroupTrackingData (which is also exposed in EPiServer.Tracking.Cms 1.9.0).

Visitor groups tracking data validation notes

  • If an error occurs during validation of visitor group track data, then the track event is dropped when processing, rather than logging the error. 
  • By calling the extension method, it sets (and overrides) the track EventType to epiVisitorGroup (which is a reserved event type name for EpiServer visitor group tracking data), and event processing is based on this value to consolidate visitor group data into Profile.
  • By calling the extension method, it sets (and overrides) the track Value to Include: [Include item]. Exclude: [Exclude item]. For example: Include: VG1, VG2, VG3. Exclude: VG4, VG5.

Episerver allows checking only if an IPrincipal is matched to a specific visitor group. Episerver does not allow getting all visitor groups of an IPrincipal.

Visitor group track data contains the following information items:

  • IncludeVisitorGroups contains newly matched visitor groups of an IPrincipal (of a user or anonymous who is being track).
  • ExcludeVisitorGroups contains visitor groups that recently did not match an identity.

For example, if you check (under an IPrincipal) whether a new user belongs to a visitor group (using VisitorGroupHelper.IsPrincipalInGroup), a match places the user on the IncludeVisitorGroups list; no match places the user on the ExcludeVisitorGroups list.

When a user is no longer considered a "new user", then the user is tracked again with "new user" being on the ExcludeVisitorGroups list, removing new status from the user's Profile when the tracking event is later processed.

Sample code:

var user = HttpContext.Current.User;
var vgHelper = new VisitorGroupHelper();
var visitorGroup = visitorGroupRepository.Load(visitorGroupGuidId);
var isMatch = vgHelper.IsPrincipalInGroup(user, "new user");
var trackData = new TrackingData<VisitorGroupTrackDataWrapper>
    Payload = new VisitorGroupTrackDataWrapper
        Epi = new VisitorGroupTrackingData
            IncludeVisitorGroups = new [] { "new user" }, //matched group
            ExcludeVisitorGroups = Enumerable.Empty<string>()
trackingService.TrackVisitorGroupAsync(trackData, httpContext);
Do you find this information helpful? Please log in to provide feedback.

Last updated: Jul 08, 2019