HomeDev GuideRecipesAPI ReferenceGraphQL
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In
GitHubNuGetDev CommunityDoc feedback

Tracking stores statistical data about search queries submitted by site visitors, and the results that they clicked. The collected statistics can be analyzed, providing administrators with deeper insight into the search's efficiency. The statistics help identify areas of improvement and optimization, so more relevant content can be provided 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.


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.


`Track()` ensures that the required tracking information is added to the URLs of the search hits.


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


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:

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. This requires you to supply 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 contain 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 the ID of the document in the index separated 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 need to construct this value based on only the object that was indexed, use this syntax:

### 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.](🔗)