# Updating the Visitor Context

In the `Flagship` SDK, the visitor context is a set of data or attributes associated with a user (visitor) at a given time. This could include information such as the user's location, device type, language preference, or any other custom attributes that you define.

The visitor context is used by Flagship to make decisions about which variations of features or experiments to show to the user. For example, you might have an experiment that shows different versions of a webpage based on the user's location. The visitor context would provide the location data needed to decide which version to show.

**Visitor context** can be set during the **visitor creation process** or whenever with the **visitor instance**

Below are examples in different programming environments:

{% tabs %}
{% tab title="JavaScript" %}

```javascript
//... other  code

//Set during the visitor creation process
const visitor = Flagship.newVisitor({
  visitorId: "your_visitor_id",
  context: { age: 31, isVip: true },
});

// Alternatively, use the updateContext method
visitor.updateContext({ lastPurchaseDate: 1615384464 });
```

{% endtab %}

{% tab title="React" %}

```python
import React from "react";
import { FlagshipProvider, useFlagship } from "@flagship.io/react-sdk";

const App = () => (
  <>
    <FlagshipProvider
      envId="<ENV_ID>"
      apiKey="<API_KEY>"
      visitorData={{
        id: "<VISITOR_ID>",
        hasConsented: true, 
          context: { //Set during the visitor creation process
            isVIP: true,
            country: "NL",
            loginProvider: "Google"
          }
      }}
    >
      <Component/>
    </FlagshipProvider>
  </>
);

const Component = () => {
  const { updateContext } = useFlagship();

  useEffect(() => {
    // Alternatively, use the updateContext method
    updateContext({ isVIP: false });
  }, []);

  return (
    <div>
      <h1>My component</h1>
    </div>
  );
};
```

{% endtab %}

{% tab title="React native" %}

```jsx
import React from "react";
import { FlagshipProvider, useFlagship } from "@flagship.io/react-native-sdk";

const App = () => (
  <>
    <FlagshipProvider
      envId="<ENV_ID>"
      apiKey="<API_KEY>"
      visitorData={{
        id: "<VISITOR_ID>",
        hasConsented: true, 
          context: { //Set during the visitor creation process
            isVIP: true,
            country: "NL",
            loginProvider: "Google"
          }
      }}
    >
      <Component/>
    </FlagshipProvider>
  </>
);

const Component = () => {
  const { updateContext } = useFlagship();

  useEffect(() => {
    // Alternatively, use the updateContext method
    updateContext({ isVIP: false });
  }, []);

  return (
    <div>
      <h1>My component</h1>
    </div>
  );
};
```

{% endtab %}

{% tab title="PHP" %}

```php

use Flagship\Flagship;

//... code

//Set during the visitor creation process
$visitor = Flagship::newVisitor("<VISITOR_ID>", true)
        ->setContext(["isVip" => true, "age"=> 31])
        ->build();

// Alternatively, use the updateContext method
$visitor->updateContext("lastPurchaseDate", 1615384464);
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using Flagship.Main;

//... code

//Set during the visitor creation process
var visitor = Fs.NewVisitor("<VISITOR_ID>", true)
  .SetContext(new Dictionary<string, object> {
    { "isQA", true },
    { "age", 31 }
  })
  .Build();

// Alternatively, use the updateContext method
visitor.UpdateContext("lastPurchaseDate", 1615384464);
```

{% endtab %}
{% endtabs %}

Please consult the reference documentation for your specific SDK for more detailed information:

| SDK                                                                                           |
| --------------------------------------------------------------------------------------------- |
| [Javascript](/server-side/sdks/js-sdk/js-reference.md#updatecontext-method)                   |
| [React-JS](/server-side/sdks/react/react-js-reference.md#updatecontext-method)                |
| [React-Native](/server-side/sdks/react-native/react-native-reference.md#updatecontext-method) |
| [PHP](/server-side/sdks/js-sdk/js-reference.md#updatecontext-method)                          |
| [.NET](/server-side/sdks/net/net-reference.md#updatecontext-method)                           |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.abtasty.com/server-side/sdks/key-features/updating-the-visitor-context.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
