> For the complete documentation index, see [llms.txt](https://docs.abtasty.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.abtasty.com/server-side/sdks/key-features/managing-visitor-consent.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.abtasty.com/server-side/sdks/key-features/managing-visitor-consent.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
