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:

//... 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 });
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>
  );
};
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>
  );
};

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);

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