Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

HomeDev GuideAPI Reference
Dev GuideAPI ReferenceLegal TermsDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide
Legal TermsDev CommunityOptimizely AcademySubmit a ticket

Optimizely developer documentation

How can we help you?

Try our conversational search powered by Generative AI!

AI OnAI Off

Tracking

Describes tracking in Optimizely Search & Navigation and how to enable and implement automatic and custom tracking for your solution.

Tracking stores statistical data about search queries site visitors submit and the results they click. You can analyze the collected statistics for deeper insight into the search's efficiency. The statistics help identify areas of improvement and optimization so you can provide more relevant content to visitors. To learn how to leverage tracking data to improve search relevance, see Auto Boosting.

Automatic tracking

The recommended way to enable automatic tracking is to call Track() on the search query.

📘

Note

In support of website visitors that do not want to be tracked, the system will look at the Do Not Track (DNT) header of incoming requests, and ignore tracking for visitors for which DNT is enabled.

Example

SearchClient.Instance.UnifiedSearchFor(searchQuery).Track().GetResult()

Track() adds the required tracking information to the URLs of the search hits.

📘

Note

The client side scripts used for tracking require EPiServer.Framework.Web.RenderingTags in the page templates.

Example

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %> <%@ Import Namespace="EPiServer.Framework.Web" %> <%@ Import Namespace="EPiServer.Framework.Web.Mvc.Html" %> <html> <head runat="server"> ... <%= Html.RequiredClientResources(RenderingTags.Header) %> </head> <body> ... <%= Html.RequiredClientResources(RenderingTags.Footer)%> </body> </html>

When using Unified Search, Track() enables tracking of a query and its hits. When using Track() on a non-Unified Search, only query tracking is enabled. Use custom tracking (explained below) to track hits with a non-Unified Search.

Custom tracking

See also the blog post How to do custom query and click tracking with EPiServer Find.

To implement a custom tracking mechanism, use the StatisticsClient, which offers two methods: TrackQuery() and TrackHit().

Access the StatisticsClient as follows:

SearchClient.Instance.Statistics().TrackQuery(...) SearchClient.Instance.Statistics().TrackHit(...)

Use TrackQuery() to track the user query. It returns a TrackQueryResult with the TrackId.

Use the TrackId returned from TrackQuery() to track hits through the existing JavaScript. You typically implement this with a non-Unified Search and must manually enable hit tracking. You must supply the required tracking information as query string parameters in the hit URL.

Tracking query string parameters

  • _t_id – TrackId, returned from client.Statistics().TrackQuery(...).
  • _t_q  – The search query string.
  • _t_tags – Tags for categorization of the collected data. Normally, it contains site and language tags.
  • _t_hit.id – The expected format for a hit ID. (hitId argument to StatisticsClient.TrackHit) is the type name used in the index, and separates the document's ID in the index by a slash. Example: EPiServer_Templates_Alloy_Models_Pages_ProductPage/_cb1b190b-ec66-4426-83fb24546e24136c_en

When SearchHit<T> objects (from GetResult) are available, combine the SearchHit.Type and SearchHit.Id properties for the appropriate search hit.

If you instead must construct this value based on only the object that was indexed, use this syntax:

client.Conventions.TypeNameConvention.GetTypeName(myObj.GetType()) + "/" + client.Conventions.IdConvention.GetId(myObj)

TrackHit()

TrackHit() tracks a search hit; it provides click tracking. TrackHit() takes a query and hit ID as parameters. The hit ID parameter format matches the _t_hit.id parameter above.

Related blog post: How to do custom query and click tracking with EPiServer Find.


Did this page help you?