Skip to main content

Enable rendering host tracking, analytics, and personalization


How to enable rendering host tracking, analytics, and personalization.

To enable rendering host tracking, analytics, and personalization, you must configure the rendering host requests to the Sitecore Layout Service to include the visitor IP address as an X-Forwarded-For HTTP header.

If you are using proxy servers or load balancers, see the Microsoft documentation on configuring ASP.NET Core to work with proxy servers and load balancers for additional instructions.

To enable tracking and visitor identification:

  1. Make sure that the Sitecore instance analytics cookie domain matches the rendering host domain, or is set to empty.

  2. In Visual Studio, in your rendering host project, double-click the Startup.cs file.

  3. If your rendering host is located behind a proxy server, in the ConfigureServices method, configure ForwardedHeadersOptions for visitor IP address forwarding:

    public void ConfigureServices(IServiceCollection services)
      services.Configure<ForwardedHeadersOptions>(options =>
          options.ForwardedHeaders = ForwardedHeaders.XForwardedFor;
  4. Add the WithTracking option to the AddSitecoreRenderingEngine service to enable tracking in Sitecore Rendering Engine:

    public void ConfigureServices(IServiceCollection services)
      services.AddSitecoreRenderingEngine(options =>
          //Register your components here using options parameter
  5. Add the AddSitecoreVisitorIdentification service to enable support for robot detection:

    public void ConfigureServices(IServiceCollection services)
      services.AddSitecoreVisitorIdentification(options =>
          options.SitecoreInstanceUri = new Uri("https://<sitecore instance>");

    The SitecoreInstanceUri must point to the Sitecore instance hosting the Sitecore Layout Service.

  6. In the Configure method, add the following:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      app.UseForwardedHeaders();                 // enables visitor IP address forwarding
      app.UseSitecoreVisitorIdentification();     // enables robot detection
  7. Save the Startup.cs file.

  8. In your layout, add the sc-visitor-identification tag helper to avoid the session and its requests being classified as a robot visitor:

    <!DOCTYPE html>
        <sc-visitor-identification />

    This tag helper renders a JavaScript script tag to include /layouts/system/VisitorIdentification.js, which performs the necessary contact identification requests.

  9. In your views, add the Sitecore.AspNet.Tracking.VisitorIdentification tag helper:

    @addTagHelper *, Sitecore.AspNet.Tracking.VisitorIdentification


Refer to the Getting Started template for a working example of the various APIs available in the Sitecore Rendering Engine SDK.