Implement your own cookie consent solution for your Flipbook

Introduction

While Flipbooks does have built-in cookie consent management, we understand that some may prefer to use either their own system or a 3rd party system. On this page we have gathered useful code snippets that can assist in implementing custom cookie consent solutions using either Custom Scripting or the Flipbook JavaScript API.

Using Custom Scripting

iPaper.API.consent.get();

This will return an object that represents the current cookie consent given like below:

{
    allowAdvertisingCookies: true
    allowFunctionalCookies: true
    allowPerformanceCookies: true
}

Optionally, you can also pass a callback function with the command, which will then be invoked when the cookie consent has been retrieved (with the retrieved consent as param):

function consentRetrieved(result){
    // YOUR CODE HERE
};

iPaper.API.consent.get(consentRetrieved);

When updating/setting cookie consent, you can set whether or not (true/false) to allow 3 categories of cookies: Performance, Functional, and Advertising.

iPaper.API.consent.set({
    allowPerformanceCookies: true, 
    allowFunctionalCookies: true, 
    allowAdvertisingCookies: true
});

Optionally, you can also pass a callback function with the command, which will then be invoked once the cookie consent has been updated (with the new/updated cookie consent as param):

function consentUpdated(newConsent){
    // YOUR CODE HERE
};

iPaper.API.consent.set({
    allowPerformanceCookies: true, 
    allowFunctionalCookies: true, 
    allowAdvertisingCookies: true
}, consentUpdated);

If you are using the iPaper Basic Banner rather than Integration as your Flipbook cookie policy, you can toggle the banner to be shown:

iPaper.API.consent.show();

onChange subscriptions

You can add callback functions as subscriptions to when the cookie consent is updated. This means that, as long as these are subscribed, they will be invoked when the cookie consent is updated.

Below is an example of setting up subscriptions as well as unsubscribing an existing subscription:

// Set up subscriptions
var a = iPaper.API.consent.onChange((result) => { console.log('a', result); });
var b = iPaper.API.consent.onChange((result) => { console.log('b', result); });
var c = iPaper.API.consent.onChange((result) => { console.log('c', result); });

// Unsubscribe
a.unsubscribe();

onShow subscriptions

You can add callback functions as subscriptions to when the cookie consent banner is shown. These will be invoked when the “Cookie Policy” link in the Flipbook viewer header is clicked, as well as when after you call iPaper.API.consent.show().

This could for example be used to trigger showing your own cookie consent banner if you have chosen the Flipbook cookie policy Integration.

Please note that if you have the cookie policy set to Integration, and you do not have any onShow subscriptions set up, clicking the “Cookie Policy” link in the Flipbook header will not do anything.

Below is an example of setting up subscriptions as well as unsubscribing an existing subscription:

// Set up subscriptions
var a = iPaper.API.consent.onShow(() => { console.log('a'); });
var b = iPaper.API.consent.onShow(() => { console.log('b'); });
var c = iPaper.API.consent.onShow(() => { console.log('c'); });

// Unsubscribe
a.unsubscribe();

Using the Flipbook JavaScript API

async function iPaperInit() {
    await iPaperAPI.getCookieConsent();
}

This will return an object that represents the current cookie consent given, like the example below:

{
    allowAdvertisingCookies: true
    allowFunctionalCookies: true
    allowPerformanceCookies: true
    allowStrictlyNecessaryCookies: true
    hasPreviousCookieConsent: true
}

When setting/updating cookie consent, you can set whether or not (true/false) to allow 3 categories of cookies: Performance, Functional, and Advertising.

function iPaperInit() {
    iPaperAPI.updateCookieConsent({ 
        allowPerformanceCookies: true, 
        allowFunctionalCookies: true, 
        allowAdvertisingCookies: true
    });
}

Using the code below you can define a callback function that will run when the cookie consent is updated/changed:

function iPaperInit() {
    iPaperAPI.onCookieConsentUpdate = function(newConsent) {
        // YOUR CODE GOES HERE
    };
}

Using the code below you can define a callback function that runs when the “Cookie Policy” button/link in the Flipbook viewer header is clicked:

function iPaperInit() {
    iPaperAPI.onCookieConsentShown = function() {
        // YOUR CODE GOES HERE
    }
}

Please note that by default clicking the “Cookie Policy” button will not do anything if the callback function has not been defined.