|
| 1 | +[](https://www.jsdelivr.com/package/npm/tarteaucitronjs) |
| 2 | +[](https://www.npmjs.com/package/tarteaucitronjs) |
| 3 | +[](https://github.com/AmauriC/tarteaucitron.js/graphs/contributors) |
| 4 | +[](https://github.com/sponsors/AmauriC) |
| 5 | + |
| 6 | +π Hey, I'm Amauri, a french dev that build a GDPR friendly cookie manager. |
| 7 | + |
| 8 | +tarteaucitron was initially a simple script for my personal blog (in 2013), a |
| 9 | +few months later, the Github repository is opened and tarteaucitron is now |
| 10 | +reliable and recognized. |
| 11 | + |
| 12 | +The european cookie law regulates the management of cookies and you should ask |
| 13 | +your visitors their consent before exposing them to third party services. |
| 14 | + |
| 15 | +Clearly this script will: |
| 16 | + |
| 17 | +- Disable all services by default, |
| 18 | +- Display a banner on the first page view and a small one on other pages, |
| 19 | +- Display a panel to allow or deny each services one by one, |
| 20 | +- Store the consent in a cookie for 365 days. |
| 21 | + |
| 22 | +Bonus: |
| 23 | + |
| 24 | +- Load service when user click on Allow (without reload of the page), |
| 25 | +- Incorporate a fallback system (display a link instead of social button and a |
| 26 | + static banner instead of advertising). |
| 27 | + |
| 28 | +# How to use |
| 29 | + |
| 30 | +```html |
| 31 | +<script src="/tarteaucitron/tarteaucitron.js"></script> |
| 32 | + |
| 33 | +<script> |
| 34 | + tarteaucitron.init({ |
| 35 | + "privacyUrl": "", /* Privacy policy url */ |
| 36 | + "bodyPosition": |
| 37 | + "bottom", /* or top to bring it as first element for accessibility */ |
| 38 | +
|
| 39 | + "hashtag": "#tarteaucitron", /* Open the panel with this hashtag */ |
| 40 | + "cookieName": "tarteaucitron", /* Cookie name */ |
| 41 | +
|
| 42 | + "orientation": |
| 43 | + "middle", /* Banner position (top - bottom - middle - popup) */ |
| 44 | +
|
| 45 | + "groupServices": false, /* Group services by category */ |
| 46 | + "showDetailsOnClick": true, /* Click to expand the description */ |
| 47 | + "serviceDefaultState": "wait", /* Default state (true - wait - false) */ |
| 48 | +
|
| 49 | + "showAlertSmall": false, /* Show the small banner on bottom right */ |
| 50 | + "cookieslist": false, /* Show the cookie list */ |
| 51 | +
|
| 52 | + "showIcon": true, /* Show cookie icon to manage cookies */ |
| 53 | + // "iconSrc": "", /* Optional: URL or base64 encoded image */ |
| 54 | + "iconPosition": |
| 55 | + "BottomRight", /* Position of the icon between BottomRight, BottomLeft, TopRight and TopLeft */ |
| 56 | +
|
| 57 | + "adblocker": false, /* Show a Warning if an adblocker is detected */ |
| 58 | +
|
| 59 | + "DenyAllCta": true, /* Show the deny all button */ |
| 60 | + "AcceptAllCta": |
| 61 | + true, /* Show the accept all button when highPrivacy on */ |
| 62 | + "highPrivacy": true, /* HIGHLY RECOMMANDED Disable auto consent */ |
| 63 | + "alwaysNeedConsent": |
| 64 | + false, /* Ask the consent for "Privacy by design" services */ |
| 65 | +
|
| 66 | + "handleBrowserDNTRequest": |
| 67 | + false, /* If Do Not Track == 1, disallow all */ |
| 68 | +
|
| 69 | + "removeCredit": false, /* Remove credit link */ |
| 70 | + "moreInfoLink": true, /* Show more info link */ |
| 71 | + "useExternalCss": |
| 72 | + false, /* If false, the tarteaucitron.css file will be loaded */ |
| 73 | + "useExternalJs": |
| 74 | + false, /* If false, the tarteaucitron.services.js file will be loaded */ |
| 75 | +
|
| 76 | + // "cookieDomain": ".my-multisite-domaine.fr", /* Shared cookie for subdomain website */ |
| 77 | +
|
| 78 | + "readmoreLink": |
| 79 | + "", /* Change the default readmore link pointing to tarteaucitron.io */ |
| 80 | +
|
| 81 | + "mandatory": true, /* Show a message about mandatory cookies */ |
| 82 | + "mandatoryCta": |
| 83 | + true, /* Show the disabled accept button when mandatory on */ |
| 84 | +
|
| 85 | + // "customCloserId": "", /* Optional a11y: Custom element ID used to open the panel */ |
| 86 | +
|
| 87 | + "googleConsentMode": |
| 88 | + true, /* Enable Google Consent Mode v2 for Google ads and GA4 */ |
| 89 | + "bingConsentMode": |
| 90 | + true, /* Enable Bing Consent Mode for Clarity and Bing Ads */ |
| 91 | + "softConsentMode": |
| 92 | + false, /* Soft consent mode (consent is required to load the services) */ |
| 93 | +
|
| 94 | + "dataLayer": |
| 95 | + false, /* Send an event to dataLayer with the services status */ |
| 96 | + "serverSide": |
| 97 | + false, /* Server side only, tags are not loaded client side */ |
| 98 | +
|
| 99 | + "partnersList": |
| 100 | + false, /* Details the number of partners on the popup and middle banner */ |
| 101 | + }); |
| 102 | +</script> |
| 103 | +``` |
| 104 | + |
| 105 | +# Add a service |
| 106 | + |
| 107 | +[Installation guide](https://tarteaucitron.io/en/free-installation-open-source/) |
| 108 | + |
| 109 | +# Customization |
| 110 | + |
| 111 | +## Create custom service |
| 112 | + |
| 113 | +```js |
| 114 | +tarteaucitron.services.mycustomservice = { |
| 115 | + "key": "mycustomservice", |
| 116 | + "type": "ads|analytic|api|comment|other|social|support|video", |
| 117 | + "name": "MyCustomService", |
| 118 | + "needConsent": true, |
| 119 | + "cookies": ["cookie", "cookie2"], |
| 120 | + "readmoreLink": "/custom_read_more", // If you want to change readmore link |
| 121 | + "js": function () { |
| 122 | + "use strict"; |
| 123 | + // When user allow cookie |
| 124 | + }, |
| 125 | + "fallback": function () { |
| 126 | + "use strict"; |
| 127 | + // when use deny cookie |
| 128 | + }, |
| 129 | +}; |
| 130 | +``` |
| 131 | + |
| 132 | +## Events |
| 133 | + |
| 134 | +The following events are available: |
| 135 | + |
| 136 | +- (document) `{SERVICE_KEY}_added` for each enabled service |
| 137 | +- (document) `{SERVICE_KEY}_loaded` for each enabled service |
| 138 | +- (document) `{SERVICE_KEY}_allowed` for each service when allowed |
| 139 | +- (document) `{SERVICE_KEY}_disallowed` for each service when disallowed |
| 140 | + |
| 141 | +- (window) `tac.root_available`: the root element with panel has been created, |
| 142 | + services will be loaded |
| 143 | +- (window) `tac.open_alert` |
| 144 | +- (window) `tac.close_alert` |
| 145 | +- (window) `tac.open_panel` |
| 146 | +- (window) `tac.close_panel` |
| 147 | + |
| 148 | +## Customize text |
| 149 | + |
| 150 | +To change a translation, use `tarteaucitronCustomText` variable. It will be |
| 151 | +merge with the translation shipping with TAC. This variable must be defined |
| 152 | +before the initialization. For example: |
| 153 | + |
| 154 | +```js |
| 155 | +tarteaucitronCustomText = { |
| 156 | + 'support': { |
| 157 | + 'title': 'Support client', |
| 158 | + }, |
| 159 | + 'close': 'Enregistrer et fermer', |
| 160 | +}; |
| 161 | +tarteaucitron.init(...); |
| 162 | +``` |
| 163 | + |
| 164 | +There is a special case for engagement text. By the default, the engagement text |
| 165 | +is _{SERVICE_NAME} is disabled._, however you can change it per service. For |
| 166 | +example: |
| 167 | + |
| 168 | +```js |
| 169 | +tarteaucitronCustomText = { |
| 170 | + "engage-twitter": "Follow us on Twitter!", |
| 171 | +}; |
| 172 | +``` |
| 173 | + |
| 174 | +# Thanks to the sponsors π |
| 175 | + |
| 176 | +|  |  | | |
| 177 | +| ----------------------------------------------------------------------------- | ------------------------------------------------------------------ | - | |
| 178 | +| [Amaury Cleuziou](https://github.com/MoryCorp) - first sponsor π | [Route Optimizer and Route Planner Software](https://route4me.com) | | |
| 179 | +| | | | |
0 commit comments