---
title: "Context"
slug: "cloud-sdk-search-context-1539392"
abstract: "The Context class represents context data for a search request. This data is used for getting personalized search results."
---
# Context

|     |     |
| --- | --- |
| Type | Class |
| Import path | `@sitecore-cloudsdk/search/server` |

Details about the site visitor's search request, such as locale, location, device, and web browser information. Sitecore Search uses this data for personalizing search results.

## Constructor

```typescript
Context(context: ContextData)
```

### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `context` | [`ContextData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-contextdata.html "ContextData") | Details about the site visitor's search request, such as locale, location, device, and web browser information. Sitecore Search uses this data for personalizing search results. |

## Properties

| Name | Type | Description |
| --- | --- | --- |
| `_locale` | [`LocaleData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-localedata.html "LocaleData") | The country and language the webpage is being viewed in. |
| `_page` | [`PageData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-pagedata.html "PageData") | The URI the site visitor came to the current webpage from. |
| `_user` | [`UserData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-userdata.html "UserData") | Data about the site visitor. |
| `_store` | [`StoreData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-storedata.html "StoreData") | Data about the online store where the site visitor made the search request. Typically used in Buy Online Pickup In Store retail strategies. |
| `_campaign` | [`CampaignData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-campaigndata.html "CampaignData") | The [UTM parameters](https://en.wikipedia.org/wiki/UTM_parameters) in the URL of the webpage. |
| `_geo` | [`GeoData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-geodata.html "GeoData") | Geographical data about the search request. |
| `_browser` | [`BrowserData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-browserdata.html "BrowserData") | Data about the site visitor's web browser. |

## Accessors

The following properties are available to set:

### get locale { .notintoc }

```typescript
get locale(): LocaleData | undefined
```

Returns the `locale` data of the `Context` instance.

### set locale { .notintoc }

```typescript
set locale(locale: LocaleData)
```

Sets the `locale` data of the `Context` instance.

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `locale` | [`LocaleData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-localedata.html "LocaleData") | The country and language the webpage is being viewed in. |

### get page { .notintoc }

```typescript
get page(): PageData | undefined
```

Returns the `page` data of the `Context` instance.

### set page { .notintoc }

```typescript
set page(page: PageData)
```

Sets the `page` data of the `Context` instance.

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `page` | [`PageData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-pagedata.html "PageData") | The URI the site visitor came to the current webpage from. |

### get user { .notintoc }

```typescript
get user: UserData | undefined
```

Returns the `user` data of the `Context` instance.

### set user { .notintoc }

```typescript
set user(user: UserData | undefined)
```

Sets the `user` data of the `Context` instance.

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `user` | [`UserData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-userdata.html "UserData") | Data about the site visitor. |

### get store { .notintoc }

```typescript
get store(): StoreData | undefined
```

Returns the `store` data of the `Context` instance.

### set store { .notintoc }

```typescript
set store(store: StoreData)
```

Sets the `store` data of the `Context` instance.

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `store` | [`StoreData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-storedata.html "StoreData") | Data about the online store where the site visitor made the search request. Typically used in Buy Online Pickup In Store retail strategies. |

### get campaign { .notintoc }

```typescript
get campaign(): CampaignData | undefined
```

Returns the `campaign` data of the `Context` instance.

### set campaign { .notintoc }

```typescript
set campaign(campaign: CampaignData)
```

Sets the `campaign` data of the `Context` instance.

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `campaign` | [`CampaignData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-campaigndata.html "CampaignData") | The [UTM parameters](https://en.wikipedia.org/wiki/UTM_parameters) in the URL of the webpage. |

### get geo { .notintoc }

```typescript
get geo(): GeoData | undefined
```

Returns the `geo` data of the `Context` instance.

### set geo { .notintoc }

```typescript
set geo(geo: GeoData)
```

Sets the `geo` data of the `Context` instance.

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `geo` | [`GeoData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-geodata.html "GeoData") | Geographical data about the search request. |

### get browser { .notintoc }

```typescript
get browser(): BrowserData | undefined
```

Returns the `browser` data of the `Context` instance.

### set browser { .notintoc }

```typescript
set browser(browser: BrowserData)
```

Sets the `browser` data of the `Context` instance.

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `browser` | [`BrowserData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-browserdata.html "BrowserData") | Data about the site visitor's web browser. |

## Methods

### _validateContext

Validates the `context` object.

#### Signature { .notintoc }

```typescript
private _validateContext(context: ContextData): void
```

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `context` | [`ContextData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-contextdata.html "ContextData") | Required.<br><br>Details about the site visitor's search request, such as locale, location, device, and web browser information. Sitecore Search uses this data for personalizing search results. |

#### Return value { .notintoc }

Returns void.

#### Errors { .notintoc }

- [`MV-0009`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-server/classes/troubleshooting-the-cloud-sdk.html#UUID-e753bca7-34cd-82c3-cb33-6c1996ac600f_section-idm1903395083329300 "MV errors")

### _validateContextLocale

Validates the context `locale` object.

#### Signature { .notintoc }

```typescript
private _validateContextLocale(locale?: LocaleData): void
```

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `locale` | [`LocaleData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-localedata.html "LocaleData") | Optional.<br><br>The country and language the webpage is being viewed in. |

#### Return value { .notintoc }

Returns void.

#### Errors { .notintoc }

- [`IV-0010`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-server/classes/troubleshooting-the-cloud-sdk.html#UUID-e753bca7-34cd-82c3-cb33-6c1996ac600f_section-idm4566641646518433950839438956 "IV errors")
- [`IV-0011`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-server/classes/troubleshooting-the-cloud-sdk.html#UUID-e753bca7-34cd-82c3-cb33-6c1996ac600f_section-idm4566641646518433950839438956 "IV errors")

### _validateLocation

Validates `latitude` and `longitude`.

#### Signature { .notintoc }

```typescript
private _validateLocation(location: LocationData): void
```

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `location` | [`LocationData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-locationdata.html "LocationData") | The geographical coordinates of the location where the site visitor made the search request. |

#### Return value { .notintoc }

Returns void.

#### Errors { .notintoc }

- [`IV-0012`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-server/classes/troubleshooting-the-cloud-sdk.html#UUID-e753bca7-34cd-82c3-cb33-6c1996ac600f_section-idm4566641646518433950839438956 "IV errors")
- [`IV-0013`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-server/classes/troubleshooting-the-cloud-sdk.html#UUID-e753bca7-34cd-82c3-cb33-6c1996ac600f_section-idm4566641646518433950839438956 "IV errors")

### _validatePage

Validates the `page` object.

#### Signature { .notintoc }

```typescript
private _validatePage(page?: PageData): void
```

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `page` | [`PageData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-pagedata.html "PageData") | The URI the site visitor came to the current webpage from. |

#### Return value { .notintoc }

Returns void.

#### Errors { .notintoc }

- [`IV-0025`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-server/classes/troubleshooting-the-cloud-sdk.html#UUID-e753bca7-34cd-82c3-cb33-6c1996ac600f_section-idm4566641646518433950839438956 "IV errors")

### _validateUser

Validates the `user` object.

#### Signature { .notintoc }

```typescript
private _validateUser(user?: UserData): void
```

#### Parameters { .notintoc }

| Name | Type | Description |
| --- | --- | --- |
| `user` | [`UserData`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-browser/interfaces/cloud-sdk-search-userdata.html "UserData") | Optional.<br><br>Data about the site visitor. |

#### Return value { .notintoc }

Returns void.

#### Errors { .notintoc }

- [`MV-0013`](https://doc.sitecore.com/sdk/en/developers/005/cloud-sdk/cloud-sdk-reference/cloud-sdk-search/cloud-sdk-search-server/classes/troubleshooting-the-cloud-sdk.html#UUID-e753bca7-34cd-82c3-cb33-6c1996ac600f_section-idm1903395083329300 "MV errors")

### removeLocale

Sets the `locale` data to `undefined`.

#### Signature { .notintoc }

```typescript
removeLocale(): void
```

#### Return value { .notintoc }

Returns void.

### removePage

Sets the `page` data to `undefined`.

#### Signature { .notintoc }

```typescript
removePage(): void
```

#### Return value { .notintoc }

Returns void.

### removeUser

Sets the `user` data to `undefined`.

#### Signature { .notintoc }

```typescript
removeUser(): void
```

#### Return value { .notintoc }

Returns void.

### removeStore

Sets the `store` data to `undefined`.

#### Signature { .notintoc }

```typescript
removeStore(): void
```

#### Return value { .notintoc }

Returns void.

### removeCampaign

Sets the `campaign` data to `undefined`.

#### Signature { .notintoc }

```typescript
removeCampaign(): void
```

#### Return value { .notintoc }

Returns void.

### removeGeo

Sets the `geo` data to `undefined`.

#### Signature { .notintoc }

```typescript
removeGeo(): void
```

#### Return value { .notintoc }

Returns void.

### removeBrowser

Sets the `browser` data to `undefined`.

#### Signature { .notintoc }

```typescript
removeBrowser(): void
```

#### Return value { .notintoc }

Returns void.

### removeIds

Sets the `ids` data to `undefined`.

#### Signature { .notintoc }

```typescript
removeIds(): void
```

#### Return value { .notintoc }

Returns void.

### toDTO

Maps the `Context` instance to its DTO (data transfer object) format.

#### Signature { .notintoc }

```typescript
toDTO(): ContextDTO
```

#### Return value { .notintoc }

Returns the `Context` instance in a standardized DTO format.