# CookieInformation

{% hint style="warning" %}
**Note:**

While the implementations below work as intended during the time of writing, we unfortunately cannot guarantee that they will always work for you as-is. Since this is not an official integration with CookieInformation, changes they make to their code base may also have an impact on the snippets below.
{% endhint %}

{% hint style="info" %}
**Note:**

The snippets below are all intended to be used through the Custom Scripting module. If you wish to use them with the Flipbook JavaScript API instead they will require some adjustment.

**Before inserting new `<script>` tags in Custom Scripting containing these snippets, you should ensure that you have loaded the script(s) for CookieInformation first (be aware that loading these&#x20;*****async*****&#x20;can cause issues).**
{% endhint %}

## Setting and updating iPaper Consent

This snippet is an example of how you can set the iPaper consent to be equal to that of CookieInformation.

First, we need to instantiate a new iPaper API instance (if this has not been done already) which we can then use to access the Consent Management methods/functions:

```javascript
const instance = iPaperJsApi(3);
```

Next up, we need to introduce a function that will retrieve the current consent from CookieInformation, and then update the iPaper consent so it matches:

```javascript
function setIpaperConsent() {
    // Get consent for each category
    /* By default, the below will be the names for the categories. However, 
    dependent on your specific set-up, these can have custom names instead */
    const allowPerformanceCookies = CookieInformation.getConsentGivenFor('cookie_cat_statistic') ? true : false;
    const allowFunctionalCookies = CookieInformation.getConsentGivenFor('cookie_cat_functional') ? true : false;
    const allowAdvertisingCookies = CookieInformation.getConsentGivenFor('cookie_cat_marketing') ? true : false;
    
    // Set iPaper consent to match the above
    instance.consent.set({
        allowPerformanceCookies,
        allowFunctionalCookies,
        allowAdvertisingCookies
    });
}
```

After this we need to ensure that the `setIpaperConsent()` function will be run in two cases:

1. When the page initializes/loads
2. When the user changes their consent via the CookieInformation banner

```javascript
// Set/update iPaper consent when page initializes/loads
if (window.CookieInformationScriptLoaded){
    setIpaperConsent();
}

// Listen for changes to CookieInformation consent and update iPaper consent accordingly
window.addEventListener('CookieInformationConsentGiven', () => setIpaperConsent());
```

And that's it!&#x20;

With the full snippet (see below), the iPaper consent will now be set and updated so it matches what your users set in the CookieInformation banner.

```javascript
function setIpaperConsent() {
    // Get consent for each category
    /* By default, the below will be the names for the categories. However, 
    dependent on your specific set-up, these can have custom names instead */
    const allowPerformanceCookies = CookieInformation.getConsentGivenFor('cookie_cat_statistic') ? true : false;
    const allowFunctionalCookies = CookieInformation.getConsentGivenFor('cookie_cat_functional') ? true : false;
    const allowAdvertisingCookies = CookieInformation.getConsentGivenFor('cookie_cat_marketing') ? true : false;
    
    // Set iPaper consent to match the above
    instance.consent.set({
        allowPerformanceCookies,
        allowFunctionalCookies,
        allowAdvertisingCookies
    });
}

// Set/update iPaper consent when page initializes/loads
if (window.CookieInformationScriptLoaded)
    setIpaperConsent();

// Listen for changes to CookieInformation consent and update iPaper consent accordingly
window.addEventListener('CookieInformationConsentGiven', () => setIpaperConsent());
```

## Showing the cookie banner

First, we need to instantiate a new iPaper API instance (if this has not been done already) which we can then use to access the Consent Management methods/functions:

```javascript
const instance = iPaperJsApi(3);
```

To show the CookieInformation banner when the "Cookie Policy" link in the top bar menu has been clicked, you can set up an `onShow` subscription like in the snippet below:

```javascript
instance.consent.onShow(() => {
    CookieConsent.show();
});
```


---

# 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.ipaper.io/flipbook-javascript-api/commands-and-events/consent/example-implementations/cookieinformation.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.
