---
title: "Enable rendering host tracking, analytics, and personalization"
slug: "enable-rendering-host-tracking-analytics-and-personalization"
abstract: "How to enable rendering host tracking, analytics, and personalization."
---
# Enable rendering host tracking, analytics, and personalization

> [!important]
> If you integrated your ASP.NET Core app before September 2024, it's using the legacy ASP.NET Core Rendering SDK, version 22 or earlier. This SDK is no longer receiving updates, so we recommend that you [upgrade to the latest version of the new ASP.NET Core SDK](https://doc.sitecore.com/xmc/en/developers/asp-net/latest/asp-net-core-sdk/upgrade-from-v22.html).

To enable rendering host tracking, analytics, and personalization, you must configure the rendering host requests to the [Sitecore Layout Service](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/sitecore-layout-service.html "Sitecore Layout Service") to include the visitor IP address as an [X-Forwarded-For](https://en.wikipedia.org/wiki/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](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-3.1) for additional instructions.

To enable tracking and visitor identification:

1. Make sure that the Sitecore instance [analytics cookie domain](https://doc.sitecore.com/xp/en/developers/104/platform-administration-and-architecture/configure-the-analytics-cookie-domain.html) 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:

    ```csharp
    public void ConfigureServices(IServiceCollection services)
    {
      services.Configure<ForwardedHeadersOptions>(options =>
        {
          options.ForwardedHeaders = ForwardedHeaders.XForwardedFor;
        });
    }
    ```

    > [!warning]
    > Beware of spoofing vulnerabilities when forwarding the visitor IP address. [The express project has a debate about handling the X-Forwarded-For header](https://github.com/expressjs/express/issues/2099), and [the Gorouter project discusses spoofing the visitor IP address](https://github.com/cloudfoundry/gorouter/issues/179).

4. Add the `WithTracking` option to the `AddSitecoreRenderingEngine` service to enable tracking in [Sitecore Rendering Engine](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/asp-net-core-rendering-engine.html "ASP.NET Core Rendering Engine"):

    ```csharp
    public void ConfigureServices(IServiceCollection services)
    {
      services.AddSitecoreRenderingEngine(options =>
        {
          //Register your components here using options parameter
        }).WithTracking();
    }
    ```

5. Add the `AddSitecoreVisitorIdentification` service to enable support for robot detection:

    ```csharp
    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:

    ```csharp
    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](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/tag-helpers.html "Tag helpers") to avoid the session and its requests being classified as a robot visitor:

    ```xml
    <!DOCTYPE html>
    <html>
      <head>
        <sc-visitor-identification />
      </head>
      <body>
      </body>
    </html>
    ```

    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:

    ```text
    @addTagHelper *, Sitecore.AspNet.Tracking.VisitorIdentification
    ```

> [!tip]
> Refer to [the Getting Started template](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/walkthrough--using-the-getting-started-template.html "Walkthrough: Using the Getting Started template") for a working example of the various APIs available in the [Sitecore Rendering Engine SDK](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/sitecore-asp-net-rendering-sdk--legacy-.html "Sitecore ASP.NET Rendering SDK (legacy)").