Skip to content

Commit

Permalink
Update docs: add section about iframemanager
Browse files Browse the repository at this point in the history
  • Loading branch information
orestbida committed Jan 24, 2023
1 parent 4728f82 commit 02a10ee
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ function getGuideSidebar() {
{ text: 'Callbacks and Events', link: '/advanced/callbacks-events' },
{ text: 'Custom Attribute', link: '/advanced/custom-attribute' },
{ text: 'Revision Management', link: '/advanced/revision-management'},
{ text: 'Consent Logging', link: '/advanced/consent-logging'}
{ text: 'Consent Logging', link: '/advanced/consent-logging'},
{ text: 'IframeManager', link: '/advanced/iframemanager'}
]
},
{
Expand Down
68 changes: 68 additions & 0 deletions docs/advanced/iframemanager.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# IframeManager Configuration
How to properly set up CookieConsent and IframeManager so that changes in state are reflected in both plugins.

Checkout the [demo on Stackblitz](https://stackblitz.com/edit/web-platform-ahqgz3?file=index.js);

::: info Info
This is an example config. and assumes that all iframes belong to the `analytics` category.
:::

## Connect IframeManager -> CookieConsent
When an iframe is accepted via a button click we must notify cookieconsent using the `onChange` callback:

::: warning Note
The `onChange` callback is available in iframemanager v1.2.0+.
:::

```javascript
const im = iframemanager();

im.run({
onChange: ({ changedServices, eventSource }) => {
if(eventSource.type === 'click') {
const servicesToAccept = [
...CookieConsent.getUserPreferences().acceptedServices['analytics'],
...changedServices
];

CookieConsent.acceptService(servicesToAccept, 'analytics');
}
},

services: {
youtube: {
// ...
},

vimeo: {
// ...
}
}
});
```

## 2. Connect CookieConsent -> IframeManager
Enable/disable iframes via CookieConsent:

```javascript
CookieConsent.run({
categories: {
analytics: {
services: {
youtube: {
label: 'Youtube Embed',
onAccept: () => im.acceptService('youtube'),
onReject: () => im.rejectService('youtube')
},
vimeo: {
label: 'Vimeo Embed',
onAccept: () => im.acceptService('vimeo'),
onReject: () => im.rejectService('vimeo')
}
}
}
}
})
```

For more examples or details about the configuration options, checkout the [iframemanger repo](https://github.com/orestbida/iframemanager).
5 changes: 3 additions & 2 deletions docs/essential/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ You can download/import the plugin using one of the following methods:

1. Install via [NPM](https://www.npmjs.com/package/vanilla-cookieconsent).
```shell
npm i vanilla-cookieconsent
yarn add vanilla-cookieconsent
npm i vanilla-cookieconsent@next
yarn add vanilla-cookieconsent@next
pnpm add vanilla-cookieconsent@next
```

Special thanks to [Till Sanders](https://github.com/tillsanders) for bringing the plugin on npm!
Expand Down

1 comment on commit 02a10ee

@vercel
Copy link

@vercel vercel bot commented on 02a10ee Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

cookieconsent-docs – ./

cookieconsent.orestbida.com
cookieconsent-docs-git-v30-beta-orest.vercel.app
cookieconsent-docs-orest.vercel.app

Please sign in to comment.