---
title: "イベントオブジェクトにコンテキストを加える"
slug: "adding-context-to-an-event-object"
abstract: "イベントオブジェクトを説明し、Sitecore SearchイベントAPIでの使い方を説明します。"
---
# イベントオブジェクトにコンテキストを加える

[コンテキストオブジェクト](https://doc.sitecore.com/search/en/developers/events-api/index.html) は、すべてのイベントに送信されるSitecore SearchイベントAPIに必要です。Sitecore Searchコンテキストオブジェクトを使って、サイトを訪れる訪問者の追加情報、訪問者の位置情報、訪問中のページ、使用しているデバイスについて記述します。

以下はcontextオブジェクトで送信しなければならない必要なオブジェクトの一覧です。

> !重要これらのオブジェクトは、イベントを正しく記録するためにすべてのcontext objectに含めていなければなりません。

-   browser - browserオブジェクトは、ブラウザのユーザーエージェント(browser.user\_agent)または訪問者がサイトにアクセスするデバイスの種類(browser.device)のいずれかとともに含めなければなりません。
    
    > !注browser.user\_agentが含まれ、業界慣例に正しく従えば、browser.deviceとbrowser.app\_typeが自動的に検出されます。
    
-   geo - geoオブジェクトは、訪問者のIPアドレス(geo.ip)または訪問者の国(geo.country)および州(geo.state)のいずれかを含めなければなりません。
    
    > !注geo.ipが提供されている場合、Sitecore SearchはIPアドレスを使って訪問者の国、州、市、郵便番号を自動的に判定します。
    

以下はイベントにおけるcontextオブジェクトの例です。

> !注イベントオブジェクトデータモデルについては、[Events API参照](https://doc.sitecore.com/search/en/developers/events-api/index.html)を参照してください。

{
 "action": "<event action>",
 "name": "<event name>",
 "value": {
 "entities": 
 {
 "attributes": {
 "author": "<Author of entity>"
 },
 "entity\_subtype": "article/blog",
 "entity\_type": "content, product",
 "id": "<External unique identifier for the entity>",
 "uri": "<URI of the entity>"
 }
 ,
 "context": {
 "browser": {
 "user\_agent": "Mozilla/5.0 (iPhone14,6; U; CPU iPhone OS 15\_4 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/19E241 Safari/602.1"
 },
 "geo": {
 "ip": "10.x.x.x"
 },
 "page": {
 "locale\_language": "en",
 "locale\_country": "us",
 "locale\_currency": "usd"
 },
 "user": {
 "cuid": "user-1234",
 "email": "abc.def@email.com",
 "eid": "<hash\_of\_email>",
 "fbid": "<facebook\_id>",
 "address": {
 "address\_line\_1": "123 Main Street",
 "address\_line\_2": "apartment 123",
 "state": "CA",
 "zip": "90210",
 "country": "USA"
 }
 }
 }
 }
}