Managing Visitor Consent

In the Flagship SDK, visitor consent is the permission given by a user (visitor) to allow the application to track their interactions and use their data for personalization and analytics purposes.

Visitor consent is crucial for compliance with data privacy regulations like the General Data Protection Regulation (GDPR). These regulations require businesses to obtain explicit consent from users before collecting or processing their personal data.

Flagship SDKs provide mechanisms to manage visitor consent, allowing you to control whether data is collected or not based on the user's consent status. This ensures that your application respects user privacy and complies with relevant data protection laws.

Visitor consent is required for each visitor and can be set during the visitor creation or whenever with the visitor instance.

Below are examples in different programming environments:

//... code

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

// Alternatively, use the setConsent method
visitor.setConsent(true);

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, //Set during the visitor creation process
          context: {
            isVIP: true,
            country: "NL",
            loginProvider: "Google"
          }
      }}
    >
      <Component/>
    </FlagshipProvider>
  </>
);

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

  useEffect(() => {
    // Alternatively, use the setConsent method
    setConsent(true);
  }, []);

  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])
        ->build();

// Alternatively, use the setConsent method
$visitor->setConsent(true);

πŸ“˜

Information

When a visitor sets consent to false, the data collection features (visitorExposed and sendHit) will be deactivated for them and all hits related to the visitor will be flushed from the pool and the cache.