=== Optooki ===
Contributors: optooki
Tags: cookie consent, gdpr, cookie banner, consent mode, privacy
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.2.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

GDPR cookie consent banner with tracker blocking, Google Consent Mode v2 and consent records, managed from your Optooki dashboard.

== Description ==

Optooki is a hosted consent management platform, operated in France (https://optooki.com). Create an account, design the banner and declare your cookies in the Optooki dashboard; the plugin loads the banner on your site and holds trackers until your visitors consent.

The plugin is free and complete: it has no premium version and no locked feature. It needs an Optooki account. A free plan covers one small site (1,000 consents a month, no time limit); paid plans add sites and monthly consents. On the free plan, the preference center shows a discreet "Powered by Optooki" text, without a link; paid plans do not show it. The plugin itself adds no credit or link to your site.

= Banner =

* Five layouts (box, bar, floating island, centered modal, side panel), each in three sizes, with light, dark or automatic theme.
* "Accept all" and "Reject all" buttons of equal weight, as recommended by European data protection authorities (CNIL guidelines).
* Preference center with one switch per category: preferences, analytics, marketing.
* Available in English, French, German, Spanish and Italian.
* Accessible: keyboard navigation, focus management, screen reader labels, 44 px touch targets on mobile.

= Tracker blocking =

* The scripts and embeds (videos, maps, forms…) of the services you declare in the Optooki dashboard are held until the visitor accepts their category. The plugin reads that list from your published configuration, twice a day and whenever you save the settings.
* Until the list has been read, common trackers are held: Google Analytics (gtag), Meta Pixel, Hotjar, Microsoft Clarity, LinkedIn Insight and TikTok Pixel, and embedded YouTube and Vimeo videos.
* Add your own scripts with the `optooki_blocked_scripts` filter.

= Works with your other plugins =

* Caching and optimization plugins: the banner is excluded automatically from delay, deferral and combination in WP Rocket, LiteSpeed Cache, Autoptimize, SiteGround Optimizer, W3 Total Cache, WP-Optimize and Cloudflare Rocket Loader. For other optimizers, the settings page says what to exclude.
* Tracking plugins (Site Kit, PixelYourSite, Pixel Manager for WooCommerce, GTM4WP, MonsterInsights, WooCommerce, Jetpack, HubSpot…): the settings page checks that their service is declared in your dashboard, and that WP Consent API is installed when they need it.
* PixelYourSite: each pixel follows its own consent category. Google Analytics starts with audience measurement, Meta and the other ad pixels with marketing, and the events it sends from your server follow the same choices.
* Another cookie banner plugin still active (Complianz, CookieYes, Cookiebot…) is flagged, since visitors would be asked twice.

= State of the installation =

A card at the top of Settings > Optooki lists what works and what needs attention, with a button to fix each point: banner turned off or not published, trackers not held, cookies found by the last scan and not declared, optimizer settings, WP Consent API. The same checks appear in Tools > Site Health.

= Blocks and page builders =

* Gutenberg blocks "Manage cookies button" and "Cookie list", with a preview of your declared services in the editor.
* The same two widgets in Elementor.
* The banner does not open in the preview of Elementor, Divi, Beaver Builder, Bricks, Oxygen, Breakdance, WPBakery and the Customizer, so it never gets in the way while you edit.

= Integrations =

* Google Consent Mode v2, built in.
* WP Consent API: choices are shared with compatible plugins (WooCommerce, Site Kit and others).
* Suggested text for your privacy policy, in Settings > Privacy.

= Consent records =

Each choice is recorded on your Optooki server with its date, the categories accepted or refused and the banner version. Records can be searched and exported as CSV from the dashboard, to prove consent during an audit. The server only accepts records sent from the domain declared for the site in the dashboard, or one of its subdomains, so another website reusing your script cannot inflate your statistics.

Once WordPress is connected to Optooki, the "Consent records" tab of Settings > Optooki shows them too, read-only and without IP addresses, with filters by choice, date and consent ID. They stay on the Optooki server, where they are sealed: nothing can be changed or deleted from WordPress.

= Cookie policy page =

* One click creates a draft "Cookie policy" page with a short text, the "Manage cookies" button and the list of cookies, kept up to date from your dashboard.
* On any page or post, the "Cookie banner" box keeps the banner closed on that page (for a legal notice, for example). Trackers stay blocked and the button to reopen the choices stays.

= Agencies and networks =

* WP-CLI: `wp optooki status`, `wp optooki setup <site-id>`, `wp optooki enable`, `wp optooki disable`, `wp optooki set <setting> <on|off>` and `wp optooki refresh`.
* Settings can be fixed in wp-config.php: `OPTOOKI_SITE_ID` (a site ID, or an array keyed by blog ID or domain for a network), `OPTOOKI_ENABLED`, `OPTOOKI_AUTO_BLOCK`, `OPTOOKI_WP_CONSENT_API` and `OPTOOKI_HIDE_FOR_ADMINS`. They then show as locked on the settings page.
* On a multisite network, Network Admin > Settings > Optooki shows the state of the banner on every site.

= Shortcodes =

For themes and builders without blocks:

* `[optooki_preferences]`: a "Manage cookies" button (attributes `label` and `class`).
* `[optooki_cookie_list]`: the table of cookies by category, for your cookie policy.
* A custom menu link pointing to `#optooki` also opens the preference center.

== External services ==

This plugin is the WordPress connector of the Optooki service, operated by Milkywi (France) at https://optooki.com. It needs an Optooki account to work; the server address is `https://consent.optooki.com`. The plugin sends nothing until you connect it to Optooki, or enter the server URL and the site ID, in Settings > Optooki.

Once configured, the following requests go to the server URL you entered, and to no other address:

* **Banner script.** Every public page loads the banner script from `https://YOUR-SERVER/s/YOUR-SITE-ID.js`, and the banner then reads its published configuration from the same server. Like any file request, this sends the visitor's IP address, user agent and the page address to the server.
* **Consent records.** When a visitor accepts, rejects or changes their choices, the banner sends a record to `https://YOUR-SERVER/v1/consents`: a random consent identifier, the categories accepted or refused, the banner version and language, the page address, whether the browser sent a Global Privacy Control signal, and the user agent. The server stores a truncated IP address (last byte of IPv4 removed, last 80 bits of IPv6 removed), never the full address.
* **Connection test.** When an administrator clicks "Test the connection" on the settings page, WordPress requests `https://YOUR-SERVER/v1/public/sites/YOUR-SITE-ID/config`. No visitor data is sent.
* **Connect to Optooki.** When an administrator clicks "Connect to Optooki", their browser opens `https://YOUR-SERVER/v1/connect/start` with the address of the settings page, a random one-time value and the domain of the site. After they sign in and pick the site, WordPress exchanges the one-time code it receives for the site ID and a read-only access key, by a request to `https://YOUR-SERVER/v1/connect/exchange`. No visitor data is sent.
* **Published configuration.** Twice a day, when the settings are saved and when an administrator clicks "Update now", WordPress requests `https://YOUR-SERVER/v1/public/sites/YOUR-SITE-ID/config` to read the list of services declared in the dashboard, so that their scripts are held until consent. No visitor data is sent.
* **Summary.** Once connected, the "Optooki: cookie consent" widget of the admin dashboard and the state card of the settings page request `https://YOUR-SERVER/v1/connect/summary` with that read-only key, at most once every 15 minutes, to show the consents of the last 30 days and the last scan. "Disconnect" calls `https://YOUR-SERVER/v1/connect/revoke` and forgets the key. No visitor data is sent.
* **Consent records.** When an administrator opens the "Consent records" tab, WordPress requests `https://YOUR-SERVER/v1/connect/journal` with the same read-only key and the filters chosen. The server returns the records of the site without IP address or user agent; WordPress displays them and stores nothing.

The plugin itself sets no cookie, includes no tracking and contacts no other service. The banner stores the visitor's choice in a first-party cookie named `cm_consent`.

Optooki service: [terms of service](https://optooki.com/terms), [privacy policy](https://optooki.com/privacy), [data processing agreement](https://optooki.com/data-processing). Records are hosted in France.

= Third-party services named in the code (held, never contacted by the plugin) =

The file `includes/class-optooki-frontend.php` contains a list of address patterns of common tracking scripts and video players. The plugin never loads, calls or sends any data to these services, and it adds none of them to your site. It only compares the scripts and video frames already present in your pages (added by your theme, another plugin or yourself) against this list, and holds the matching ones until the visitor accepts the matching category. If the visitor accepts, the browser then loads that script or video as it would without this plugin, and the service receives what its own script collects (usually the IP address, user agent, page address and its own cookies), under its own terms. If the visitor refuses, the script or video is never loaded.

* **Google Analytics and Google Tag Manager** (Google LLC), patterns `googletagmanager.com/gtag` and `google-analytics.com`: audience measurement, held until "analytics" is accepted. [Terms of service](https://policies.google.com/terms), [privacy policy](https://policies.google.com/privacy).
* **Meta Pixel** (Meta Platforms, Inc.), pattern `connect.facebook.net`: advertising measurement, held until "marketing" is accepted. [Terms of service](https://www.facebook.com/legal/terms), [privacy policy](https://www.facebook.com/privacy/policy/).
* **Hotjar** (Hotjar Ltd, a Contentsquare company), pattern `static.hotjar.com`: behavior analytics, held until "analytics" is accepted. [Terms of service](https://contentsquare.com/legal/terms-conditions/), [privacy policy](https://contentsquare.com/privacy-policy/).
* **Microsoft Clarity** (Microsoft Corporation), pattern `clarity.ms`: behavior analytics, held until "analytics" is accepted. [Terms of service](https://clarity.microsoft.com/terms), [privacy policy](https://www.microsoft.com/en-us/privacy/privacystatement).
* **LinkedIn Insight Tag** (LinkedIn Corporation), pattern `snap.licdn.com`: advertising measurement, held until "marketing" is accepted. [Terms of service](https://www.linkedin.com/legal/user-agreement), [privacy policy](https://www.linkedin.com/legal/privacy-policy).
* **TikTok Pixel** (TikTok), pattern `analytics.tiktok.com`: advertising measurement, held until "marketing" is accepted. [Terms of service](https://ads.tiktok.com/i18n/official/policy/terms), [privacy policy](https://www.tiktok.com/legal/page/row/privacy-policy/en).
* **YouTube** (Google LLC), patterns `youtube.com`, `youtu.be` and `youtube-nocookie`: embedded videos, replaced by a placeholder until "marketing" is accepted. [Terms of service](https://www.youtube.com/t/terms), [privacy policy](https://policies.google.com/privacy).
* **Vimeo** (Vimeo, Inc.), pattern `vimeo.com`: embedded videos, replaced by a placeholder until "preferences" is accepted. [Terms of service](https://vimeo.com/legal/terms/), [privacy policy](https://vimeo.com/legal/privacy/policy).

== Installation ==

1. Install and activate the plugin.
2. Create an account at https://app.optooki.com, add your site, customize the banner and publish it.
3. In WordPress, open Settings > Optooki and click "Connect to Optooki": sign in, pick the site (or create it), and you come back with the site ID and the server URL filled in. You can also enter them by hand: the site ID is shown in the "Installation" tab of the dashboard.
4. Click "Test the connection". The banner now shows on your site, and a summary of your consents appears on the admin dashboard.

== Frequently Asked Questions ==

= Do I need an Optooki account? =

Yes. The banner, its settings and the consent records live in your Optooki account; the plugin connects WordPress to it. A free plan is available for one small site.

= Is there a premium version of the plugin? =

No. The plugin is the same for every plan and receives every update. What a plan changes is in your account: number of sites, consents per month, the "Powered by Optooki" mention.

= What happens if my site exceeds its plan? =

You receive an email at 80 % and 100 % of the monthly quota, and the banner keeps working. After two full months over the quota, a paid subscription moves to the next plan. A free plan has its dashboard restricted, then, thirty days later without a plan change, its banner is suspended: no banner is shown and every tracker held back by the plugin stays blocked, so visitors remain protected. Choosing a suitable plan restores the banner within minutes.

= How do I add a "Manage cookies" link? =

Use the "Manage cookies button" block (or Elementor widget), the `[optooki_preferences]` shortcode (attributes `label` and `class`), or add a custom link pointing to `#optooki` in a menu.

= How do I show the list of cookies in my cookie policy? =

Click "Create the page" in Settings > Optooki for a ready-made draft, or insert the "Cookie list" block (or the `[optooki_cookie_list]` shortcode) in your own page. The table is built from the services declared in the dashboard, in the visitor's language.

= How do I block another script? =

Use the `optooki_blocked_scripts` filter:

`add_filter( 'optooki_blocked_scripts', function ( $map ) { $map['cdn.example.com/tracker.js'] = 'analytics'; return $map; } );`

Available categories are `necessary`, `preferences`, `analytics` and `marketing`.

= Can I disable the banner on a page? =

Yes. Tick "Do not open the banner on this page" in the "Cookie banner" box of the page: trackers stay blocked until the visitor answers, and the button to reopen the choices stays. In code, the `optooki_hide_banner` filter does the same, and the `optooki_is_active` filter removes the banner entirely (trackers are then no longer held either).

= I use a caching or optimization plugin (WP Rocket, Autoptimize, LiteSpeed Cache…) =

WP Rocket, LiteSpeed Cache, Autoptimize, SiteGround Optimizer, W3 Total Cache, WP-Optimize and Cloudflare Rocket Loader are handled automatically. For another optimizer, exclude the Optooki script (it carries the `data-optooki` attribute) from the "defer", "delay JavaScript execution" and "combine JavaScript files" options; the state card of the settings page reminds you when one is active. The script must stay the first of the page, loaded synchronously: this is what lets it block trackers before they run.

= Consent records do not appear for my staging site =

Records are only accepted from the domain declared for the site in the Optooki dashboard and its subdomains (`www.example.com` and `shop.example.com` both match `example.com`). A staging copy on another domain shows the banner normally but records nothing. Create a separate site in the dashboard for it if you want to keep its records. The same applies to multisite networks and domain mapping: each WordPress site that uses its own domain needs its own Optooki site.

= My site uses a Content Security Policy =

Allow your Optooki server in `script-src` (the banner script) and `connect-src` (consent records). Nothing is needed in `style-src` on current browsers: the banner uses constructed style sheets, which are not subject to it. If your policy relies on nonces, add the nonce to the banner tag with the core `wp_script_attributes` filter; the banner reuses it for the scripts it re-enables after consent.

= Can I use a self-hosted Optooki server? =

Yes. Declare it in wp-config.php, for example `define( 'OPTOOKI_CUSTOM_SERVER', 'https://consent.example.com' );`, then enter the same address in Settings > Optooki. Without this constant, only the official Optooki servers are accepted: the server address chooses the script loaded on every page of your site, so it must be chosen by whoever controls the site files. When the constant is set, only users allowed to add scripts (on a network, the super admins) can change the address.

= Can I read the consent records in WordPress? =

Yes, in the "Consent records" tab of Settings > Optooki, once WordPress is connected. If the connection was made with version 1.1, click "Connect to Optooki" again to allow it. The records stay on the Optooki server; the official export, which serves as proof, is in the dashboard.

= Is the plugin translated? =

The admin screens are written in English, with French, German, Spanish and Italian translations through translate.wordpress.org. The banner itself is translated from the Optooki dashboard, in the same five languages.

== Screenshots ==

1. The settings page: server connection, behavior switches and installation steps.
2. The consent banner on a WordPress site, with "Reject all" and "Accept all" of equal weight.
3. The preference center, with one switch per category.
4. In the Optooki dashboard: choose a theme or reuse your site's colours, with a live preview.
5. In the Optooki dashboard: the record of every consent, searchable and exportable as CSV.

== Changelog ==

= 1.2.2 =
* PixelYourSite: each pixel follows its own consent category. Accepting only audience measurement now starts Google Analytics without the Meta Pixel, and the events PixelYourSite sends from your server (Meta Conversions API) wait for the same consent.
* Pixel Manager for WooCommerce is recognized: the settings page checks that its services are declared and that WP Consent API is installed, which it reads to start each pixel with its own category.
* WP Consent API: the "functional" category is granted from the first page view, before any choice.

= 1.2.1 =
* WP-Optimize is now handled automatically: the banner and the held scripts are left out of its delay, deferral and merging.
* The number of undeclared cookies follows the services declared in the dashboard, without waiting for a new scan, and the cookies declared but not published yet are counted apart.
* Spacing fixed in the admin dashboard widget.

= 1.2.0 =
* New: the scripts and embeds of the services declared in the Optooki dashboard are held until consent, not only a fixed list of common trackers.
* New: a card at the top of the settings page shows the state of the installation, with a button to fix each point, also in Tools > Site Health.
* New: "Consent records" tab, read-only, with filters and pages.
* New: "Manage cookies button" and "Cookie list" blocks, and the same widgets for Elementor.
* New: one-click cookie policy page, and a box to keep the banner closed on a given page.
* New: automatic exclusions for WP Rocket, LiteSpeed Cache, Autoptimize, SiteGround Optimizer, W3 Total Cache and Cloudflare Rocket Loader; checks for tracking plugins and other cookie banners.
* New: WP-CLI commands, settings that can be fixed in wp-config.php, and a network page on multisite.
* The banner no longer opens in the preview of page builders.

= 1.1.0 =
* New: "Connect to Optooki" button. Sign in, pick the site, and the site ID and the server URL are filled in, with nothing to copy and paste.
* New: "Optooki: cookie consent" widget on the admin dashboard: consents of the last 30 days, "accept all" rate, last scan and a link to the dashboard.
* The connection uses a read-only key, kept apart from the settings, that can be revoked from the plugin or from the Optooki dashboard.

= 1.0.1 =
* Security: the server address can only be an official Optooki server, or a self-hosted server declared in wp-config.php (constant OPTOOKI_CUSTOM_SERVER). A site saved with another address loads the banner from the official server, and the settings page says why.
* Security: on a network, only users allowed to add scripts can change the address of a declared self-hosted server.

= 1.0.0 =
* First public release.
* Banner script printed with the WordPress script API, at the very top of the head.
* Admin screens in English, with a French translation.
* Suggested privacy policy text.
* Settings removed from every site of a network when the plugin is deleted.


== Upgrade Notice ==

= 1.2.2 =
With PixelYourSite, Google Analytics starts with audience measurement alone, and the server events wait for consent.

= 1.2.1 =
Handles WP-Optimize automatically, and keeps the count of undeclared cookies up to date.

= 1.2.0 =
Holds the services declared in your dashboard, shows the state of the installation, adds blocks, a cookie policy page and the consent records in WordPress.

= 1.1.0 =
Connect WordPress to Optooki in one click, and follow your consents from the admin dashboard.

= 1.0.1 =
Security update: the server address is restricted to the official Optooki servers, or to a self-hosted server declared in wp-config.php.

= 1.0.0 =
First public release.
