Geo

The context object in a request describes the location and visitor requesting data. The values in the object are used to select which rules are applied during search.

You have to use the locale object to set the geo property of the context for a request included in Sitecore Search JS SDK for React or JS Data package. The locale is represented by two-letter codes for country and language.

Property

Type

Description

ip

string

IP address of the browser or native application of the system the visitor is on. Don't pass the IP address of your proxy. If you don't pass ip, Sitecore gets the IP address from the X-Forwarded-For request header. If your request does not have an X-Forwarded-For header, Sitecore uses the request's IP address.

location

GeoLocation

Object describing a location with latitude and longitude values.

GeoLocation

Property

Type

Description

lat

number

The latitude of the visitor in decimal degrees (DD) format. Don't use spaces. For example, pass -77.0089.

lon

number

The longitude of the visitor in decimal degrees (DD) format. Don't use spaces. For example, pass -120.0017.

Set or update context geo

We recommend you set the geo-location in your first search or recommendation request. The SDK stores this value and sets it in future requests. In a very unlikely situation, if the geo-location changes during a visit, you must update the geo-location for accurate reporting.

To set the locale in context for a search request:

  • Use the following code block, adding or replacing your own values:

    RequestResponse
    query: (query:SearchResultsWidgetQuery) => query.getRequest().setContextGeo({ location: { "41.40338", "2.17403" } })
    

To update the locale in context for a search request:

  • Use the following code block, adding or replacing your own values:

    RequestResponse
    query: (query:SearchResultsWidgetQuery) => query.getRequest().updateContextGeo({ ip:"192.0.2.1"})
    

Do you have some feedback for us?

If you have suggestions for improving this article,