---
title: "レンダリングのホスト追跡、分析、パーソナライズを有効にしてください"
slug: "enable-rendering-host-tracking-analytics-and-personalization"
abstract: "レンダリングのホスト追跡、分析、パーソナライズを有効にする方法。"
---
# レンダリングのホスト追跡、分析、パーソナライズを有効にしてください

> !重要2024年9月以前にASP.NET Coreアプリを統合した場合、それはレガシーのASP.NET Core Rendering SDK(バージョン22以前)を使用しています。このSDKは更新を受け取っていないため、[最新のASP.NET Core SDKへのアップグレード](https://doc.sitecore.com/xmc/en/developers/asp-net/latest/asp-net-core-sdk/upgrade-from-v22.html)をお勧めします。

レンダリングホストの追跡、分析、パーソナライズを有効にするには、レンダリングホストリクエストを[Sitecoreレイアウトサービス](https://doc.sitecore.com/xp/ja/developers/hd/22/sitecore-headless-development/sitecore-layout-service.html "Sitecore Layout Service") に設定し、訪問者のIPアドレスを[X-Forwarded-Forの](https://en.wikipedia.org/wiki/X-Forwarded-For)HTTPヘッダーとして含める必要があります。

プロキシサーバーやロードバランサーを使用している場合は、[MicrosoftのASP.NET Coreをプロキシサーバーやロードバランサーと連携させる設定](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-3.1) 手順をご参照ください。

追跡および訪問者識別を可能にするために:

1.  Sitecoreのインスタンス [アナリティクスクッキードメイン](https://doc.sitecore.com/xp/en/developers/104/platform-administration-and-architecture/configure-the-analytics-cookie-domain.html) がレンダリングホストドメインと一致するか、空に設定されているか確認してください。
    
2.  Visual Studioのレンダリングホストプロジェクトで、Startup.csファイルをダブルクリックします。
    
3.  レンダリングホストがプロキシサーバーの背後にある場合、ConfigureServices方式で訪問者IPアドレス転送のForwardedHeadersOptionsを設定します。
    
    public void ConfigureServices(IServiceCollection services)
    {
     services.Configure<ForwardedHeadersOptions>(options =>
     {
     options.ForwardedHeaders = ForwardedHeaders.XForwardedFor;
     });
    }
    
    > !警告訪問者のIPアドレスを転送する際の脆弱性のなりすましに注意してください。 [ExpressプロジェクトではX-Forwarded-Forヘッダーの扱いについて議論](https://github.com/expressjs/express/issues/2099)があり、[Gorouterプロジェクトでは訪問者IPアドレスのスプーフィ](https://github.com/cloudfoundry/gorouter/issues/179)ングについて議論があります。
    
4.  AddSitecoreRenderingEngineサービスにWithTrackingオプションを追加して、[Sitecoreレンダリングエンジン](https://doc.sitecore.com/xp/ja/developers/hd/22/sitecore-headless-development/asp-net-core-rendering-engine.html "ASP.NET Core Rendering Engine")でトラッキングを有効にする:
    
    public void ConfigureServices(IServiceCollection services)
    {
     services.AddSitecoreRenderingEngine(options =>
     {
     //Register your components here using options parameter
     }).WithTracking();
    }
    
5.  ロボット検出のサポートを有効にするためにAddSitecoreVisitorIdentificationサービスを追加してください:
    
    public void ConfigureServices(IServiceCollection services)
    {
     services.AddSitecoreVisitorIdentification(options =>
     {
     options.SitecoreInstanceUri = new Uri("https://<sitecore instance>");
     });
    }
    
    SitecoreInstanceUriはSitecoreレイアウトサービスをホストしているSitecoreインスタンスを指し示さなければなりません。
    
6.  Configure法では、以下を追加します。
    
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
     app.UseForwardedHeaders(); // enables visitor IP address forwarding
     app.UseSitecoreVisitorIdentification(); // enables robot detection
    });
    
7.  Startup.csファイルを保存してください。
    
8.  レイアウトにsc-visitor-identification[タグヘルパー](https://doc.sitecore.com/xp/ja/developers/hd/22/sitecore-headless-development/tag-helpers.html "Tag helpers")を追加して、セッションとそのリクエストがロボット訪問者として分類されないようにしてください:
    
    <!DOCTYPE html>
    <html>
     <head>
     <sc-visitor-identification />
     </head>
     <body>
     </body>
    </html>
    
    このタグヘルパーは、/layouts/system/VisitorIdentification.jsを含むJavaScriptスクリプトタグを生成し、必要な連絡先識別要求を実行します。
    
9.  ビューにSitecore.AspNet.Tracking.VisitorIdentificationタグヘルパーを追加してください:
    
    @addTagHelper \*, Sitecore.AspNet.Tracking.VisitorIdentification
    

> !ヒント[Sitecore Rendering Engine SDK](https://doc.sitecore.com/xp/ja/developers/hd/22/sitecore-headless-development/sitecore-asp-net-rendering-sdk--legacy-.html "Sitecore ASP.NET Rendering SDK (legacy)")で利用可能な様々なAPIの動作例は、[Getting Startedテンプレート](https://doc.sitecore.com/xp/ja/developers/hd/22/sitecore-headless-development/walkthrough--using-the-getting-started-template.html "Walkthrough: Using the Getting Started template")を参照してください。