Updating the Visitor Context
//... 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>
);
};SDK
Last updated
Was this helpful?

