Friday, July 31, 2015

Sitecore Experience Profile - Logging Searches aka Internal Keywords

As discussed in my overview on the Sitecore Experience Profile, it is a powerful tool which provides in depth analytics and tracking of users of your Sitecore web site (both anonymous and identified). One interesting feature of the experience profile is the search terms or Internal Keywords. This allows any searches a user makes internally (by any custom searches) appear inside the experience profile.


To register search terms in the experience profile some code will need to be added into your custom search logic.
public void RegisterSearch(string searchterm)
{
    if (searchterm != null)
    {
        if (IsTrackerEnabled())
        {
            var interaction = Tracker.Current.Session.Interaction;
            interaction.CurrentPage.Register(new PageEventData("Search", new Guid(Items.SearchPageID)) { ItemId = new Guid(Items.SearchPageID), Data = searchterm, DataKey = searchterm, Text = searchterm });
        }
    }
}

private static bool IsTrackerEnabled()
{
    return Tracker.IsActive && Tracker.Current.Session != null && Tracker.Current.Session.Interaction != null;
}

No comments:

Post a Comment