How to troubleshoot Tracker.Current is not initialized error in sitecore

If you are getting the following error 

Tracker.Current is not initialized
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Tracker.Current is not initialized
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:

[InvalidOperationException: Tracker.Current is not initialized]
   Sitecore.Analytics.Pipelines.StartAnalytics.StartTracking.Process(PipelineArgs args) +335
   (Object , Object[] ) +74
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +484
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, Boolean failIfNotExists) +39
   Sitecore.Analytics.Pipelines.StartAnalytics.StartAnalyticsPipeline.Run() +363
   Sitecore.Mvc.Analytics.Pipelines.MvcEvents.RequestBegin.StartTracking.Process(RequestBeginArgs args) +137
   (Object , Object[] ) +74
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +484
   Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +22
   Sitecore.Mvc.Pipelines.PipelineService.RunPipeline(String pipelineName, TArgs args) +193
   Sitecore.Mvc.Routing.RouteHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +74
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +923
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157

There are few steps that you can follow to find the root cause of problem

0- Look into your sitecore logs

1- Look into Sitecore.Analytics.Model.config make sure all the custom interfaces you are defined are valid, configs might have been added on custom config file. It might be a good idea to look into /sitecore/admin/showconfig.aspx page and find all under model/elements/* and model/entities/facets/*

If you have element or facet pointing to invalid namespace you might get the above error.
You can comment out the custom ones and see if that fixes the issue. Then you can add elements and facets back one by one to find the culprit.

2-  make sure all the classes inherited from Sitecore.Analytics.Model.Framework.Facet are Serializable for more information have a read of this blog post https://mhwelander.net/2016/08/24/tracker-current-is-not-initialized/

3- Look settings of Sitecore.Analytics.Tracking.config and check how your shared state set it up.
make sure your connectionStringName is in your ConnectionStrings.config file and it's valid.

 <sharedSessionState defaultProvider="mssql">
        <providers>
          <clear/>
          <!-- To enable inProc, replace mssql provider with inProc
              <add name="InProc" type="System.Web.SessionState.InProcSessionStateStore" />
              SOPA CHANGES
          -->
          <add name="mssql"
               type="Sitecore.SessionProvider.Sql.SqlSessionStateProvider,Sitecore.SessionProvider.Sql"
               connectionStringName="sharedsession"
               pollingInterval="2"
               compression="true"
               sessionType="shared" />
        </providers>

        <manager type="Sitecore.Analytics.Tracking.SharedSessionState.SharedSessionStateManager, Sitecore.Analytics">
          <param desc="configuration" ref="tracking/sharedSessionState/config" />
        </manager>

        <config type="Sitecore.Analytics.Tracking.SharedSessionState.SharedSessionStateConfig, Sitecore.Analytics">
          <param desc="maxLockAge">5000</param>
          <!-- If an item in session state is already locked, this parameter is the time in milliseconds that the system is idle before making another attempt to apply a lock. -->
          <param desc="timeoutBetweenLockAttempts">10</param>
        </config>
      </sharedSessionState>


more read:
https://community.sitecore.net/technical_blogs/b/getting_to_know_sitecore/posts/introducing-contact-facets

Comments