Tracking internal search keywords for reporting on Experience Profile and Experience Analytics in Sitecore

Sitecore offers the possibility of tracking internal keyword search in your site, so you can have a better understanding of your visitors and their engagement.

Now, there are 3 types of keywords described in the following table.

  • Internal keywords
    • Lists the keywords used in searches on the website.
  • External Keywords
    • A list of the distinct keywords that the contact used in search engines, such as Google or Bing. For selected keywords, you can see more detailed information, such as a list of the search engines, visit duration, and value.
  • Paid Keywords
    • Lists the distinct paid keywords used, for example, from Google AdWords. For selected keywords, you can see more detailed information, such as a list of sources, visit duration, and value.

Source: https://doc.sitecore.com/users/90/sitecore-experience-platform/en/experience-profile-dashboard.html

In my case, I had the need of tracking Internal searches, so I created the following utility to help me achieve it.

public static bool TrackInternalKeywordSearch(string keywordText, string pageVisitedGuid)
        {

            // If tracker is not active or page is not available we can't track the search
            bool IsActive = Tracker.Current != null && Tracker.Current.IsActive;
            var page = Tracker.Current.Interaction.CurrentPage;
            if (IsActive && page != null)
            {
                // This is to track the search keyword under specific page item (Url)
                Guid pageVisited = Sitecore.Context.Database.GetItem(pageVisitedGuid).ID.Guid;

                //This is the Guid of the Search event, you can find yours at /sitecore/system/Settings/Analytics/Page Events/Search
                page.Register(new PageEventData("Search", new Guid("{0C179613-2073-41AB-992E-027D03D523BF}"))
                {
                    ItemId = pageVisited,
                    Data = keywordText,
                    DataKey = keywordText,
                    Text = keywordText,

                });
                return true;
            }
            return false;
        }

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.