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

Visitor group tracking

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);

Last updated: Jul 08, 2019