10

We're getting a ton of errors from an RSS page on one of the websites when bots hit it to get/parse RSS:

Exception: System.InvalidOperationException
Message: Tracker.Current is not initialized
Source: Sitecore.Analytics
at Sitecore.Analytics.Pipelines.StartAnalytics.StartTracking.Process(PipelineArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Analytics.Pipelines.HttpRequest.StartAnalytics.Process(RenderLayoutArgs args)

There are thousands of errors in logs. The RSS page is fairly standard - using standard FeedDeliveryLayout.

<%@ Page Language="c#" EnableSessionState="false" EnableViewState="false" Inherits="Sitecore.Syndication.Web.FeedDeliveryLayout, Sitecore.Kernel" CodePage="65001" %>

I disabled analytics a few hours ago for this page by going to Appearance ->Tracking ->Attributes ->Settings ->Disable analytics. There are still errors in the log though.

Are there any other settings I need to change to disable analytics for this page?

7

The reason the tracker is not initialized is because it can't work with session state disabled.

As I understand, you don't want this page to be tracked anyway. To ensure that xDB tracking is disabled, just add the following code into the page:

<script runat="server">

protected override void OnPreInit(EventArgs e)
{
    Tracker.Enabled = false;
}

</script>

This way, the startAnalytics pipeline will be aborted way before the StartTracking processor, which is where your exceptions occur.

You may have to add the following lines at the top of the page:

<%@ Page Language="C#" %>
<%@ Import Namespace="Sitecore.Analytics" %>
  • Thanks! Could this just go directly into sitecore\shell\Applications\Feeds\Layouts\FeedDeliveryLayout.aspx ? – alexp83 Oct 21 '16 at 17:05
  • @alexp83 Yes, that's exactly where I meant it to go! – Dmytro Shevchenko Oct 21 '16 at 17:05
  • As a follow-up, what does 'Disable Analytics' option do when enabled from the 'Tracking' field in Sitecore? Seems like it should be disabling analytics and tracking altogether... – alexp83 Oct 21 '16 at 17:11
  • 1
    @alexp83 Yes, to my understanding, it's supposed to do that, but for some reason, that feature doesn't always work. I would advise to raise this with Sitecore Support. – Dmytro Shevchenko Oct 21 '16 at 17:14
3

The Disable Analytics option on item is used during the Processing/Aggregation activities of Sitecore Analytics, specifically the processItem pipeline.

<processItem patch:source="Sitecore.Analytics.config">
  <processor type="Sitecore.Analytics.Pipelines.ProcessItem.CollectParameters,Sitecore.Analytics"/>
  <processor type="Sitecore.Analytics.Pipelines.ProcessItem.TriggerCampaigns,Sitecore.Analytics"/>
  <processor type="Sitecore.ExperienceExplorer.Business.Pipelines.ProcessItem.InteractionValuePipeline, Sitecore.ExperienceExplorer.Business" patch:source="Sitecore.ExperienceExplorer.config"/>
  <processor type="Sitecore.Analytics.Pipelines.ProcessItem.RegisterPageEvents,Sitecore.Analytics"/>
  <processor type="Sitecore.ExperienceExplorer.Business.Pipelines.ProcessItem.SaveInitialProfilesPipeline, Sitecore.ExperienceExplorer.Business" patch:source="Sitecore.ExperienceExplorer.config"/>
  <processor type="Sitecore.Analytics.Pipelines.ProcessItem.ProcessProfiles, Sitecore.Analytics"/>
  <processor type="Sitecore.ExperienceExplorer.Business.Pipelines.ProcessItem.ProfilesPipeline, Sitecore.ExperienceExplorer.Business" patch:source="Sitecore.ExperienceExplorer.config"/>
</processItem>

The reason you are seeing the error pop-up, even on the default FeedDeliveryLayout is because of the startAnalytics pipeline. As Dmytro points out, manually setting the Tracker.Enable to false on the layout is a way of telling Sitecore to ignore tracking for that request, which checked in the CheckPreconditions processor of the same pipeline.

Interesting to note, other reasons why this pipeline would not proceed:

  • Tracker.Enable is false
  • SiteContext is null
  • Context.Page is null
  • site.Tracking().EnableTracking() isfalse`
<startAnalytics patch:source="Sitecore.Analytics.Tracking.config">
  <processor type="Sitecore.Analytics.Pipelines.StartAnalytics.CheckPreconditions, Sitecore.Analytics"/>
  <processor type="Sitecore.Analytics.Pipelines.StartAnalytics.CreateTracker, Sitecore.Analytics"/>
  <processor type="Sitecore.Analytics.Pipelines.StartAnalytics.StartTracking, Sitecore.Analytics"/>
</startAnalytics>

Specifically the StartTracking processor:

  public class StartTracking
  {
    public virtual void Process(PipelineArgs args)
    {
      Assert.ArgumentNotNull((object) args, "args");
      Assert.IsNotNull((object) Tracker.Current, "Tracker.Current is not initialized");
      Tracker.Current.StartTracking();
      Log.Debug("[Analytics]: Start tracking: " + (object)         

      ... code snipped ...

    }
  }

The Assert is Not Null is throwing the error. If you wanted to manually fix the way this reports, you could create a custom processor that goes before StartAnalytics, and instead of doing a Assert.IsNotNull at the begging, you could check for null, perform a Log.Debug() signifying that the Tracker is null here, and then gracefully abort out of the pipeline.

public class CheckNullTracker
{
    public virtual void Process(PipelineArgs args)
    {
        Assert.ArgumentNotNull((object)args, "args");

        if (Tracker.Current == null)
        {
            Log.Debug("Tracker.Current is not initialized");
            Tracker.Enabled = false;
            args.AbortPipeline();
        }
    }
}

The above custom processor is more of a fundamental example. Care should be taken. The Tracker.Current use case is utilized in a whole bunch of pipeline processors and other areas. Appropriate uses of Tracker should always include a check to ensure Tracker.Current is not null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.