# Cookie Consent Storing

* Navigate to Cloudflare’s official website by clicking on the following link:\
  <https://www.cloudflare.com/>
* If you already have a Cloudflare account, simply log in.
* If you don't have an account, click on **"Start for Free"** as shown in the image below to create a new account.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FCsKYl39k4BHYEzmqcnBJ%2FScreenshot%202025-02-08%20164645.png?alt=media&#x26;token=aa24d9b1-d994-4000-8492-18d54e184f4a" alt=""><figcaption></figcaption></figure>

* You can easily sign up for a Cloudflare account using your **Google** or **Apple** account for a faster registration process.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2F371863KkMheIxthoVlJL%2FScreenshot%202025-02-08%20165205.png?alt=media&#x26;token=c6f0b3b3-13b8-46f6-997a-0cb00feec9e5" alt=""><figcaption></figcaption></figure>

* After a successful login, you will be redirected to the Cloudflare dashboard. In the left sidebar menu, find **Compute (Workers)**, click on it to expand the options, and then select **Workers & Pages**.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FndzeKUDDTn5hHbS7EiE7%2FScreenshot%202025-02-08%20165943.png?alt=media&#x26;token=72ba5e57-b9eb-4f66-9701-6ebdec2daa98" alt=""><figcaption></figcaption></figure>

* Then, click **"Create"** to add a new worker.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2Fn9b2SM1OUZZYxvWcVTB3%2FScreenshot%202025-02-09%20102920.png?alt=media&#x26;token=ce762f27-dd02-4a65-a021-8b2e7f7a4dfc" alt=""><figcaption></figcaption></figure>

* You will be redirected to the **Create an Application** page. Under the **Workers** tab, click on **Quick Start**, as shown in the image below.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FQBefj6VPl6VyQaoA8by2%2FScreenshot%202025-02-09%20103427.png?alt=media&#x26;token=bfdfcf9e-f6ac-4fbc-ac77-d4ea44df865e" alt=""><figcaption></figcaption></figure>

* Give your worker a name and click **Deploy**. In our example, we have named the worker **cookie-consent-flowappz**.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FHrmvfSHxPQbWIWBgXIU4%2FScreenshot%202025-02-09%20104110.png?alt=media&#x26;token=b195ce23-762b-4d82-9278-b669f9dbfece" alt=""><figcaption></figcaption></figure>

* You will be redirected to the **Success** page. Click **Edit Code** to proceed.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FYo22pBrlVtqINGDRN95J%2FScreenshot%202025-02-09%20104613.png?alt=media&#x26;token=1bd0664d-57e8-4b2c-a1ec-54b988a6fcb5" alt=""><figcaption></figcaption></figure>

* Then, paste the following code into the code editor and click **Deploy**.

```
export default{async fetch(e,s){const t={"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET, HEAD, POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Allow-Credentials":"true","Access-Control-Max-Age":"86400"};if("OPTIONS"===e.method)return new Response(null,{headers:t});if("POST"===e.method)try{const o=await e.json(),{cookiePreferences:r,expiryDate:n,browserInfo:a,userIp:c,action:l}=o;if(!(r&&n&&a&&c&&l))return new Response("Invalid payload: Missing required fields.",{status:400,headers:t});const i={action:l,userIp:c,browserInfo:a,cookiePreferences:r,expiryDate:n,timestamp:(new Date).toISOString()};return await s.CONSENTS.put(c,JSON.stringify(i)),new Response("Consent preferences successfully stored.",{status:200,headers:t})}catch(e){return console.error("Failed to store data in KV:",e),new Response("Failed to store consent preferences.",{status:500,headers:t})}return new Response("Method Not Allowed",{status:405,headers:t})}};
```

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FqLIzj2kUcdlcKxAlloF0%2FScreenshot%202025-02-09%20114324.png?alt=media&#x26;token=0d38dca7-f9e9-454e-8386-b992cfc77f60" alt=""><figcaption></figcaption></figure>

* Then, go back to the **Dashboard**, and in the left-side menu under **Storage and Databases**, click on **KV**.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FLMRRlWyBSSGqzixBflos%2FScreenshot%202025-02-09%20115506.png?alt=media&#x26;token=11c92c49-8bb2-49d9-b06f-667b0bd6e4c6" alt=""><figcaption></figcaption></figure>

* Then, click on **Create**.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FSX0MA4IKiMER5ccuCK6R%2FScreenshot%202025-02-09%20115844.png?alt=media&#x26;token=87c22218-8a9e-4ae4-953a-d04b2eca5096" alt=""><figcaption></figcaption></figure>

* Give a name to the Namespace and click **Add**. In our example, we have used the name **Cookie Consent KV**.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FsCPjreKEcXQ9AVN6ij0M%2FScreenshot%202025-02-09%20115844.png?alt=media&#x26;token=48904f38-5038-4dc0-a4fc-bfb4d43975b0" alt=""><figcaption></figcaption></figure>

* Go to **Workers** and **Pages**, then click on the previously created worker. In our example, it is **cookie-consent-flowappz**.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FjloehmTi0b5T5Ozkvb4G%2FScreenshot%202025-02-09%20120656.png?alt=media&#x26;token=535972f2-74c1-4678-8a30-bc78c090df38" alt=""><figcaption></figcaption></figure>

* Navigate to the **Settings** tab and click on **Variables & Secrets** in the left-side menu.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FEau921MU5EDMAGMHl2qy%2FScreenshot%202025-02-09%20121144.png?alt=media&#x26;token=a2d8fe6b-5938-48b9-9167-4ce1a63a0b48" alt=""><figcaption></figcaption></figure>

* Under the **Bindings** section, click on **Add**.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2Fw4YBAaK9C0D6irRt00FF%2FScreenshot%202025-02-09%20121540.png?alt=media&#x26;token=9ac05afb-649a-4811-8a6b-5c4c7cbdf2fd" alt=""><figcaption></figcaption></figure>

* Then, select the **KV Namespace**.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2F4dAvWrAhAakcfOMJGmOV%2FScreenshot%202025-02-09%20122011.png?alt=media&#x26;token=5d5590e4-1ca7-43e4-8ec9-4a548bbc38c9" alt=""><figcaption></figcaption></figure>

* Enter the variable name as **CONSENTS** and select the KV namespace as **Cookie Consent KV**. After that, click **Deploy**.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2Fj8aTOqpTAT4uux1ieNn8%2FScreenshot%202025-02-09%20122431.png?alt=media&#x26;token=2942d52b-8cd7-4a76-b6e1-880edd6da8c6" alt=""><figcaption></figcaption></figure>

* Right-click on the icon shown in the image and copy the URL.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2F4kUegeqZqkGdZIUE5yq0%2FScreenshot%202025-02-09%20131435.png?alt=media&#x26;token=9618c89c-d3fc-4944-ac0c-ab05ec516f8e" alt=""><figcaption></figcaption></figure>

* Open your cookie consent app in the designer. Navigate to the **Settings** tab, paste the URL into the **Consent Storing Endpoint** input field, and then click **Save Settings**.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2F1DstSsiz83Fz3XJMqCYB%2FScreenshot%202025-02-09%20132644.png?alt=media&#x26;token=6d0f7266-c9db-45c1-b1d5-596608c0241d" alt=""><figcaption></figcaption></figure>

* To view all stored consents, navigate to **KV** under **Storage and Databases**, then click on **Cookie Consent KV**.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2F0Fnh3MeZNjZu8m382zjU%2FScreenshot%202025-02-09%20134405.png?alt=media&#x26;token=1f1a6528-c385-46a0-8512-e54dabb6e4ab" alt=""><figcaption></figcaption></figure>

* Then, navigate to the **KV Pairs** section, where you will see all the users' consents.

<figure><img src="https://2780403897-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwFnNHlS6UwWvtAc4EAxZ%2Fuploads%2FpwobKeGkgT0AmsCCjOtR%2FScreenshot%202025-02-09%20135041.png?alt=media&#x26;token=a4277f78-3468-48f8-8b83-3b71d900357a" alt=""><figcaption></figcaption></figure>
