OptInOut.js
A simple JavaScript library to manage opting in & out of tracking/marketing/mailing - in fact whatever you want to manage. This was created with EU GDPR in mind.
To get started, check out the quick start below.
Visit our
website for more information, the
documentation or the guides and examples.
The original repository is hosted on
GitLab, there's a mirror on it on
GitHub. You can create issues anywhere, but the main work happens on
GitLab.
Quick Start
$3
You can download the
latest release here. This includes the src & dist directory.
There's also a
npm package.
$3
#### Static HTML
For usage in standard websites with best browser coverage we recommend including the
dist/optinout.js or
dist/optinout.min.js.
Just include the script via a standard script-tag in the header/footer:
$3
#### Initialization
You have to initialize the library before using any of its methods:
OptInOut();
This initializes the library with our default options & storages. Even if you do not want to customize the options you have to add your
services:
OptInOut({
services: {
'facebook': {
mode: 'optIn',
},
'analytics': {
mode: 'optOut',
},
},
});
#### Opt-In & Opt-Out
You can use the global's object "static" methods for quick access to the most important methods of the current instance.
//opting out
OptInOut.optOut('analytics');
//opting in
OptInOut.optIn('facebook');
For easier handling we include a link-helper plugin, which automatically trigger when buttons with specific classes are clicked. Add it as a plugin with
OptInOut.plugins.linkPlugin on initialization and add the
optInOut-optIn class and the
data-service-attribute to your buttons. See
full documentation for details.
#### Checking Status
Checking if something is allowed or not (--> if the user has opted in/opted out) is easy:
OptInOut.isAllowed('facebook');
This method takes the current saved status & the mode of the service into consideration.