The context object
In events, the context
object is used to describe additional information about the user visiting the site, the page being visited, the location from which they are browsing, the device on which they are browsing, and so on.
Context
objects are an integral part of all API requests for search, recommendation, and content widgets. The event
object allows the same context
object to be sent to any Discover API. This means that the context object data is standardized across all Sitecore Discover services.
Additionally, the context
object is used when events are posted using a REST API call. In the absence of the Discover beacon, you must send information like device
and geo
in API calls using the context
object.
The following table lists objects supported by the context
object.
Name |
Type |
Description |
---|---|---|
|
Required when sending events using the Events API. User's browser or device information. | |
|
Required when sending events using the Events API. User's location information. | |
|
Required only when the user has selected a fitment. User's fitment information in context of the product. | |
|
Required for user login and user info events. User's information such as address, gender, ID, and so on. | |
|
Optional. Information about the advertising campaign. | |
|
Required if locale is used. Information about the current page, such as URL, referrer, and so on. | |
|
Required when the event is an order event with BOPIS and the store has not been specified at the product level. Information about store for BOPIS orders |
The following represents a generic event containing a context
object:
{
"type": "...",
"name": "...",
"value": {
"products": [
{
"sku": "191258"
}
],
"index": "1",
"text": "diamond rings",
"type": "category",
"context": {
"fitment": {
"ids": [
"fit-id1",
"fit-id2"
]
},
"geo": {
"ip": "10.x.x.x",
"country": "US",
"state": "California",
"city": "San Mateo",
"zip": "94404"
},
"page": {
"locale_language": "en",
"locale_country": "us",
"locale_currency": "usd"
},
"user": {
"id": "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": "US"
}
},
"store": {
"id": "s123",
"group": "g1"
}
}
}
}