# 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:

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

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

```

{% endtab %}

{% tab title="React" %}

```jsx
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>
  );
};
```

{% endtab %}

{% tab title="PHP" %}

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

{% 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 }
    )
  .Build();
    
// Alternatively, use the setConsent method
visitor.SetConsent(true);
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
📘 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.
{% endhint %}


---

# 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/managing-visitor-consent.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.
