-
-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update docs: add section about iframemanager
- Loading branch information
Showing
3 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
02a10ee
There was a problem hiding this comment.
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