---
title: Data Protection
slug: headless-sdk/data-protection
docTags: 
createdAt: 2023-05-23T11:29:38.000Z
---

By default, data protection is turned off in the SDK. This means that the SDK will read and write from the browser's storage (localStorage, cookies, etc).&#x20;

For customers who need to comply with data protection rules, you can enable data protection in the SDK by setting **useConsent** to **true**. When this setting is enabled, consent must be given for each session using the SDK using **consentGiven** with a value set to **true**.&#x20;

You can use the following code snippet as an example to enable it:

```javascript
KlevuConfig.init({
  url: "https://eucs23v2.ksearchnet.com/cs/v2/search",
  apiKey: "klevu-160320037354512854",
  useConsent: true, //Either set it to true during initialization
  consentGiven: true, //Either set it to true during initialization
})
// or
KlevuConfig.getDefault().setUseConsent(true)
KlevuConfig.getDefault().setConsentGiven(true) // When you receive the user consent
```

You can either add values per user session within KlevuConfig.init or by calling the methods available to KlevuConfig as shown above.&#x20;
