All examples or directions on implementing xDB always include placing the VisitorIdentification (@Html.Sitecore().VisitorIdentification()) in the head?

This to me is code smell (render-blocking JavaScript). Is there any reason why this must exist in the header? Does this block need to exist on the page prior to rendering html?

1 Answer 1


Yes it does

Except if you don't use xDB or Analytics. In this case, VisitorIdentification is redundant.

What it does

It serves a number of purposes; but the most relevant to you is, it aids robot detection on your site. Sitecore (speaking broadly) functions like this:

  • Assume a new visitor is a robot
  • Send some code to the client via VisitorIdentification
  • If the code responds as expected; assumes it's a real browser client

If you leave it out, Sitecore will assume all your visits are robots (crawlers etc) - and your sessions will time out after 60 seconds.

The robot detection component is enabled by default but to implement it fully you must ensure that you have added the visitor identification control to the layout of each page on your website.

Source: Configure robot detection functionality

Additional links:

And to ease your worry

The VisitorIdentification control actually only outputs the blocking Javascript once - at the initial stage where the system has "auto detected a robot". Once it is satisfied that the session is not a robot, it outputs blank content and is out of your way from that point on.

Witnessed from this, not entirely pretty, piece of code driving this control.

<%  if (Sitecore.Context.Diagnostics.Tracing || Sitecore.Context.Diagnostics.Profiling)
<!-- Visitor identification is disabled because debugging is active. -->
    else if (Sitecore.Analytics.Tracker.IsActive && Sitecore.Analytics.Core.ContactClassification.IsAutoDetectedRobot(Sitecore.Analytics.Tracker.Current.Session.Contact.System.Classification))
<meta name="VIcurrentDateTime" content="<%: DateTime.UtcNow.Ticks %>" />
<script type="text/javascript" src="/layouts/system/VisitorIdentification.js"></script>
  • 1
    "If you leave it out ... your sessions will time out after 60 seconds" - So what's stopping you including it before the closing body tag? The script would still get loaded and the visitor identified as not a robot... (agree on everything in your answer btw)
    – jammykam
    Sep 16, 2017 at 3:25
  • 1
    Well. While we currently know that this is done by script, it wasn't always so and may very well change again in the future. At one point, VisitorIdentification output a link element that downloaded some CSS. According to HTML 4 specification, this MUST appear inside the head element. Sitecore themselves say, VI needs to be in the had section. Source: kb.sitecore.net/articles/977445
    – Mark Cassidy
    Sep 16, 2017 at 9:39
  • Thanks for posting the code driving the control. In theory we could break this out to output the meta tag in the head and the script tag in the body. Whilst I agree it's not very future proof or robust, it's not going to change unless you do a Sitecore upgrade. The reason to do it is quite compelling: the js loads for every single new user to your website. In my tests on my website it added 128ms of render blocking on the initial page load, which in today's climate is pretty unacceptable, especially for something that isn't essential to load the page for the user.
    – theyetiman
    Nov 9, 2017 at 9:43
  • 1
    Could we just update this to update the script tag with defer or async?
    – Justin L.
    Feb 21, 2018 at 16:43
  • The argument against would be a repeat of the above. Me; I believe if the internal mechanics in Sitecore allowed for this approach, it would be done so already.
    – Mark Cassidy
    Feb 21, 2018 at 17:27

Your Answer

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

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