4

In Sitecore 8.0+, the invention of the Sitecore.Analytics.Tracker was introduced to provide Session based Analytic tracking to be sent to xDB. This is maintained in the config file Sitecore.Analytics.Tracking.config.

There are two settings:

  • Analytics.ClusterName
  • Analytics.Hostname

In a multisite configuration with multiple content delivery servers running behind a load balancer, what should the values of these settings be, in order to get Tracker to initialize appropriately?

Scenario 1:

  • Sitecore Sites Config Each Site has Different Start Item:
    • <site name="a" hostname"aaa.com" ... EnableTracking="true" ... />
    • <site name="b" hostname"bbb.com" ... EnableTracking="true" ... />
    • <site name="c" hostname"ccc.com" ... EnableTracking="true" ... />
  • 3 Content Delivery Servers
  • Single IIS Site with bindings for each domain (aaa.com,bbb.com,ccc.com)
  • <setting name="Analytics.ClusterName" value="default-cd-cluster" />
  • <setting name="Analytics.HostName" value="" />
  • Each domain is different from the other.

Result: Error Received Under this scenario when running Tracker.StartAnalytics(). I get the following Stack Trace:

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: 


Line 37:         {
Line 38:             if (!Tracker.IsActive)
Line 39:                 Tracker.StartTracking();
Line 40:         }
Line 41: 

Source File: D:\AgencyCode\XYZClientName-com\src\XYZClientName.Library\Abstractions\Contacts\ContactFactory.cs    Line: 39 

Stack Trace: 


[InvalidOperationException: Tracker.Current is not initialized]
   Sitecore.Analytics.Pipelines.StartAnalytics.StartTracking.Process(PipelineArgs args) +304
   (Object , Object[] ) +74
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +484
   Sitecore.Analytics.Pipelines.StartAnalytics.StartAnalyticsPipeline.Run() +293
   XYZClientName.Library.Abstractions.Contacts.ContactFactory..ctor() in D:\AgencyCode\XYZClientName-com\src\XYZClientName.Library\Abstractions\Contacts\ContactFactory.cs:39
   XYZClientName.Library.Factories.Contacts.SitecoreContactFactory..ctor() +49
   XYZClientName.Library.Managers.XYZClientNameContactManager..ctor() in D:\AgencyCode\XYZClientName-com\src\XYZClientName.Library\Managers\XYZClientNameContactManager.cs:170
   XYZClientName.Web.sitecore_modules.Shell.EmailCampaign.RegisterEmailOpened..ctor() in D:\AgencyCode\XYZClientName-com\web\XYZClientName.Web\sitecore modules\Shell\EmailCampaign\RegisterEmailOpened.aspx.cs:17
   ASP.sitecore_modules_shell_emailcampaign_registeremailopened_aspx..ctor() +16
   __ASP.FastObjectFactory_app_web_xrzs0hqx.Create_ASP_sitecore_modules_shell_emailcampaign_registeremailopened_aspx() +31
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +133
   System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +44
   System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +378
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137

Scenario 2:

  • Sitecore Sites Config Each Site has Different Start Item:
    • <site name="a" hostname"aaa.com" ... EnableTracking="true" ... />
    • <site name="b" hostname"bbb.com" ... EnableTracking="true" ... />
    • <site name="c" hostname"ccc.com" ... EnableTracking="true" ... />
  • 3 Content Delivery Servers
  • Single IIS Site with bindings for each domain (aaa.com,bbb.com,ccc.com)
  • <setting name="Analytics.ClusterName" value="default-cd-cluster" />
  • <setting name="Analytics.HostName" value="aaa.com" />
  • Each domain is different from the other.

Result: Tracker is initialized and working for aaa.com. Fails to load on bbb.com and ccc.com.

2
  • 1
    I've found that the Analytics.Hostname setting is useless in a multi-domain site. Since it forces all requests to redirect to that domain. I leave it blank. Note that connectivity errors to MongoDB can cause the tracker to not initialize. Check that :)
    – Kam Figy
    Sep 22, 2016 at 4:50
  • I have since learned in my research that Tracker requires Sitecore Page context be present in order to initialize. So if I want to track a non-web browsing session, like IoT, or RESTfull service, or something where I still want to identify to Sitecore Analytics, this page context must exist. This may be something xConnext resolves. That being said, that is why I was having such a hard time, because the request was happening in a server side pipeline.
    – Pete Navarra
    Sep 22, 2016 at 12:43

2 Answers 2

4

ClusterName is a value of the cluster address to which a server belongs. The name should be identical for all content delivery servers that are in the same cluster. I usually use a string here, not a hosname. I believe this has nothing to do with multisites URLs.

EXM documentation states:

Ensure that the value of the Analytics.ClusterName setting is the hostname of the content delivery server. This is required for a scaled environment to avoid contacts being locked when running EXM. If there is more than one content delivery server in your environment, use the same value for each server. In addition, make sure that the content management server can reach the content delivery server through HTTP using the hostname that you have specified in the Analytics.ClusterName setting of the content delivery server.

The way I see it, as long as the hostname there is accessible by the CMS, you are safe.

Regarding Hostname, it should be left empty when using multisites. This was the reply I got from sitecore support when asked them about it.

Analytics.HostName is a value of the global address (e.g. www.domain.com). This value should be the same for all CDs. But please note that for the multi-site solution the value should be blank (for all CDs). For more details please see the following known issue: https://kb.sitecore.net/articles/792020

2
  • A small addidition. It's not just EXM which requires the Analytics.ClusterName to be set to avoid contacts being locked, that's general for Sitecore. Secondly, re. a HTTP connection between CM and CD. That is required by EXM to be able to request the ecmclientservice.asmx, see doc.sitecore.net/email_experience_manager/setting_up_exm/… Sep 22, 2016 at 9:16
  • I am choosing this as the answer as it most closely answers the intention of my original question. The issue I was having ended up not being this setting at all, but the fact that I was trying to instantiate the Tracker in a pipeline where there is no Sitecore Page Context. Which is a requirement of the Tracker in 8.1U3.
    – Pete Navarra
    Sep 22, 2016 at 22:04
0

The Tracker.current is not initialized is a generic error and does not necessarily mean that there is something wrong with your tracker configuration. In my experience, it means that the problem occurred when trying to initialize a pipeline that has an error in it. Here's an example of what I am talking about:

  1. Using the Sitecore Instance Manager, install a new instance of Sitecore
  2. Edit the Web.config to set the session timeout to 1 minute instead of 20 minutes. Save the file and then browse out to your new site and close the browser. This will cause Sitecore to write the record to Mongo and within a minute or so you should have a record in the database.
  3. Next create a visual studio project for your new website.
  4. Use this code for a new cshtml file:
@using Sitecore.Mvc.Analytics.Extensions
<!DOCTYPE html>
<html lang="en">
  <head>
    @Html.Sitecore().VisitorIdentification()
    I'm tracking you!`
  </head>
  <body></body>
</html>
  1. Login into your sitecore instance, and change the /sitecore/layout/Layouts/Sample Layout Path (in the data section) to point to your new cshtml file. Save and Publish.
  2. Browse the website again and verify that you see the I'm tracking you! message.
  3. Now create another file in your App_Config/Include folder, call it zzz.config, and use this code:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <model>
      <entities>
        <contact>
          <facets>
            <facet name="BadFacetSyntax" contract="BadFacetSyntaxInterface, MyDLLName" />
          </facets>
        </contact>
      </entities>
    </model>
  </sitecore>
</configuration>
  1. This is basically creating a new facet that does not have everything hooked up into it correctly. If you save this file and try to reload the site, you'll get the Tracker.Current is not initialized error. While this is technically a true statement, the problem lies in some custom code, and not in the configuration of your servers.

I am seeing this kind of error whenever there is an exception that happens sometime when the Tracker code is trying to initialize. So, you will probably want to try to look at some other code (outside of the tracker.initialize), as that is most likely where the error is happening. Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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