NullReferenceException on Tracking.Current when executing a request for a Quick view

In this article

Symptoms

When trying to fetch the content of a page to populate the Quick view, a 500 error is thrown with a NullReferenceException on Tracking.Current.

Cause

When xDB Tracking is disabled, Tracking.Current is set to null . Every page trying to log xDB analytics when they’re disabled will get a NullReferenceException.

This particular error is caused by the ExcludeCoveoUserAgentProcessor which aborts the Sitecore startAnalytics pipeline when the User Agent is Coveo Sitecore Search Provider to disable tracking in certain scenarios.

This is to ensure that Coveo for Sitecore doesn’t log xDB analytics when fetching the HTML content for the Quick view.

For more information on why the pipeline is canceled, see Disable xDB tracking for single requests.

Resolution

There are two ways to solve this problem: adding null-checks or disabling the processor.

Add null-checks

Ensure that every call to Tracking is wrapped by Tracking.IsActive.

Since other scenarios could disable Tracking, this is the recommended resolution.

Disable the processor

Important

This re-enables analytics logging in your xDB instance.

Create a new Coveo.SearchProvider.EnableCoveoUserAgentForXDB.config and add the following node in it:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <startAnalytics>
        <processor type="Coveo.Analytics.Processors.ExcludeCoveoUserAgentProcessor, Coveo.Analytics">
          <patch:delete />
        </processor>
      </startAnalytics>
    </pipelines>
  </sitecore>
</configuration>