=== Enkrat Cookie ===
Contributors: olegtix
Tags: cookie, cookie consent, gdpr, cookie banner, consent
Donate link: https://enkrat.com/donate/
Requires at least: 6.9
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.2.7
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Cookie banner for GDPR and Russian 152-FZ: consent by category, analytics, ads and embeds blocked until consent, a consent log.

== Description ==

Enkrat Cookie shows a cookie banner and makes sure analytics, advertising and embedded content do not load until the visitor allows them.

What sets it apart:

* **The law of every country, without GeoIP.** Consent, a notice or no banner depending on the visitor’s country, detected from the device time zone right in the browser: no geolocation service, no IP lookup, and full-page caching keeps working.
* **Russian 152-FZ as well as GDPR.** Yandex Metrica, VK Ads, Rutube, VK Video, Dzen and Yandex Maps are blocked just like Google services, and the banner can link to the separate consent document required in Russia since 1 September 2025.
* **Blocking that works with page caching.** The server rewrites tracker tags the same way for every visitor, a small guard catches scripts inserted later, and the decision is made in the browser.
* **No account, no cloud, no limits.** Everything runs inside WordPress: no sign-up, no page view quotas, no paid tier. The consent log stays in your database and stores no IP addresses.
* **Page builders.** In the Bricks, Elementor, Divi, Oxygen and Breakdance editors the page shows no banner and a single settings button.

Three modes:

* **Consent by category.** Visitors choose what to allow: necessary (always on), analytics, advertising, external services. Scripts of a category do not run until it is allowed.
* **Notice only.** A banner with a single “Got it” button, nothing is blocked.
* **By country.** Consent, a notice or no banner at all, depending on the visitor’s country. Out of the box the plugin follows the law of every country: consent where the law requires it (the EU and EEA, the UK, Russia, Belarus, Kazakhstan, Turkey, Brazil, China and about 115 more), a notice where informing visitors is enough (the USA, Japan, Australia and others), no banner where there is no personal data law. The lists are updated with the plugin, and laws that are adopted but not yet in force (India, Sri Lanka, Bangladesh, Paraguay) switch to consent on their effective date. Exceptions override the law: pick a country from the list and its mode, for example a notice for Uzbekistan and no banner for India.

What is blocked until consent:

* Tracking codes set up in the plugin: Google Analytics 4, Google Tag Manager, Yandex Metrica, VK Ads / Top.Mail.Ru.
* Known services added by the theme or other plugins (autoblocking): Google Analytics, Google Tag Manager, Google Ads, Meta Pixel, TikTok Pixel, Microsoft Advertising, LinkedIn Insight Tag, Pinterest Tag, X Pixel, Seznam Sklik, Hotjar, Microsoft Clarity, Yandex Metrica, Yandex Advertising Network, VK Ads, LiveInternet, Calltouch, Roistat.
* Videos and maps (YouTube, Vimeo, VK Video, Rutube, Dzen, Yandex Maps, Google Maps): a placeholder with a button is shown instead.

How blocking works:

1. The server rewrites the page HTML: tracker scripts get `type="text/plain"` and their address moves to `data-enkrat-src`. The HTML is the same for every visitor, so the plugin works with full-page caching.
2. A small guard at the top of `<head>` intercepts scripts that trackers insert dynamically.
3. After consent the scripts run in their original order. When consent is withdrawn, the page reloads and the services’ cookies on the site domain are removed.

Speed:

* Pages without third-party trackers are not parsed at all: a fast substring check decides whether rewriting is needed.
* Minified assets: about 12 KB of JavaScript for the banner and 3 KB for the inline guard, before gzip. Rules by country for the whole world add about 2 KB (1.3 KB gzipped) to the page.
* For a visitor who has already allowed everything, the guard does not touch the page.

Design:

* The banner UI lives in Shadow DOM: theme styles do not affect it, and its styles do not leak into the site.
* Card on the left or right, or a bar at the bottom; light, dark or system theme; accent color, corner radius, font.
* “Accept all” and “Necessary only” buttons are equal by default.
* Floating button to change the choice: a round icon or a small text tab at the bottom edge with your own caption. It hides itself on pages that already have a “Cookie settings” button or link, so it does not compete with chat and callback widgets in the corner.
* Optional: the page is dimmed and does not scroll until the visitor chooses.
* The same round button can live in the footer: `[enkrat_cookie_button]`, or `[enkrat_cookie_button text="Cookie settings"]` with a caption.
* Keyboard navigation, mobile layout.
* Page builders: in the editor of Bricks, Elementor, Divi, Oxygen, Breakdance and other builders the page shows only the cookie settings button, once, without the banner, blocking and tracking codes.

Links under the banner: the privacy policy, the cookie policy and a separate consent to personal data processing (in Russia consent must be a separate document since 1 September 2025).

Cookie table: put the `[enkrat_cookie_table]` shortcode on the cookie policy page. The table lists the cookies of the tracking codes set up in the plugin, of the services found on the site and of your own list, grouped by category, with lifetimes and purposes. The plugin also shows which cookies your browser received from the site, so unknown ones can be added to the list in one click.

Consent log stores the date, the decision, the categories, the settings revision and the page address without the query string. IP address, User-Agent and visitor ID are not stored. The log can be exported to CSV.

Translations come from translate.wordpress.org. Banner texts you have not changed follow the site language automatically, which also works with WPML and Polylang.

Enkrat Cookie is made by [ENKRAT](https://enkrat.com/), a web development studio.

== Installation ==

1. In the admin, go to Plugins → Add New Plugin, search for “Enkrat Cookie”, install and activate it.
2. Go to Settings → Enkrat Cookie: choose the mode, the privacy policy page and your tracking codes.
3. If a tracking code is already in your theme or another plugin, remove it there or keep autoblocking on.
4. Add a “Cookie settings” link to the footer: the `[enkrat_cookie_settings]` shortcode or a menu item with the URL `#enkrat-cookie`.
5. Clear the page cache and check in a private window: in DevTools → Network there must be no requests to tracker domains before consent.

== Frequently Asked Questions ==

= Does it work with caching plugins? =

Yes. The rewritten HTML is the same for all visitors, the decision is made in the browser. Do not combine or delay tracker scripts in the optimizer (for example, Delay JS in WP Rocket or LiteSpeed): the optimizer may change their type before the plugin blocks them. The guard and the banner script carry exclusion attributes for popular optimizers. After changing the settings, clear the page cache.

= Does it work with page builders? =

Yes. Bricks, Elementor, Divi, Oxygen, Breakdance, Brizy, Beaver Builder, Avada, WPBakery and other builders show the page inside their editor. There the plugin shows no banner, blocks nothing and does not run tracking codes, so videos and maps stay visible and your edits are not counted as visits. The floating button appears once, on the page itself, not on the editor panel; turn it off in Settings → Enkrat Cookie → Design → “Show it in page builder editors”. Shortcode buttons are drawn in the editor too.

For a builder the plugin does not recognize:

    add_filter('enkrat_cookie_builder_context', fn($context) => isset($_GET['my-builder']) ? 'canvas' : $context);

`canvas` is the page inside the editor, `editor` is the editor’s own window where the plugin outputs nothing.

= Will the banner hurt conversions? =

After the visitor’s choice nothing has to stay in the corner of the screen: put the `[enkrat_cookie_button]` shortcode in the footer, and the floating button disappears on pages with it. Or switch the floating button to a small text tab at the bottom edge.

= Which WordPress versions are supported? =

WordPress 6.9 and newer: the plugin rewrites pages through the template output buffer that WordPress provides since version 6.9.

= What data does the plugin send to its developer? =

Nothing, unless you allow it. Usage statistics help us know how many sites use the plugin and which versions still need support. If you turn on Settings → Enkrat Cookie → Advanced → Usage statistics, then once a day, and when the plugin is activated, deactivated or deleted, it sends to enkrat.com:

* the site address;
* a random installation ID;
* the plugin and WordPress versions;
* the event: activated, deactivated, deleted or still active.

Email addresses, users, visitors, the consent log and settings are never sent. Copies of the site on local addresses (localhost, .test, .local) send nothing.

To turn statistics off on all client sites at once and hide the switch, add `define('ENKRAT_COOKIE_NO_STATS', true);` to `wp-config.php`. The `enkrat_cookie_send_stats` filter does the same from code. Details: [privacy policy](https://enkrat.com/ek-cookie/privacy/en/).

= How does the plugin know the visitor’s country? =

From the time zone of the visitor’s device, right in the browser. There is no request to a geolocation service (it would receive the visitor’s IP address before consent) and no GeoIP database on the server, the page HTML stays the same for everyone, so page caching keeps working. A VPN does not change the time zone, so the plugin sees where the person actually is. If the browser hides its time zone (Tor Browser, strict anti-fingerprinting settings), the strictest of your modes is used.

To check a country, open the site in Chrome, DevTools → More tools → Sensors → Location → Timezone ID, for example `Asia/Tashkent`. Or use the preview links on the settings page.

= Can I rebrand the plugin for my clients (white label)? =

Yes. Turn it on in Settings → Enkrat Cookie → Advanced → White label and enter your plugin name, author and website. The menu, the settings page and the plugin list then show your name, and the ENKRAT branding and links disappear.

Any administrator of the site can see and turn off that setting. To hide it from a client, add the constant to `wp-config.php` instead:

    define('ENKRAT_COOKIE_WHITE_LABEL', [
        'name'       => 'Cookie Consent',
        'author'     => 'Your Studio',
        'author_uri' => 'https://your-studio.example/',
    ]);

`true` instead of the array gives a neutral name without an author. The constant takes priority over the setting, and the White label card disappears from the admin, so a client with administrator rights cannot see or turn it off. The `enkrat_cookie_white_label` filter does the same from code. Technical names (the folder, the `enkrat_cookie` cookie, `data-enkrat-*` attributes, the JavaScript API) stay as they are: saved visitor choices and theme code depend on them.

= Does the plugin store personal data? =

The consent log does not store IP addresses, User-Agent strings or visitor IDs. The visitor’s choice is kept in the `enkrat_cookie` cookie in their browser.

= How do I translate my own banner texts on a multilingual site? =

Texts left at their defaults are translated automatically. Edited texts are registered for WPML and Polylang through `wpml-config.xml`.

== Screenshots ==

1. The banner: “Necessary only” and “Accept all” are equal. Videos and maps wait behind placeholders until the visitor allows them.
2. The settings window: consent by category, with the services used in each category.
3. A bar at the bottom in the dark theme with your own accent color.
4. The cookie table for the cookie policy page, built by the `[enkrat_cookie_table]` shortcode.
5. Three modes: consent by category, notice only, or by country.
6. Rules by country: consent, a notice or no banner following each country’s law, plus your own exceptions.
7. Appearance: a card or a bar, light, dark or system theme, accent color, corner radius and font.
8. Tracking codes: Yandex Metrica, Google Analytics 4, Google Tag Manager and VK Ads run only after consent.
9. The consent log with statistics for the last 30 days.

== External services ==

Enkrat Cookie connects to third-party services only when you set them up, and to its developer’s server only as described below.

**Tracking codes you set up.** If you enter a Google Analytics 4, Google Tag Manager, Yandex Metrica or VK Ads ID on the Blocking tab, the plugin outputs the official tracking code of that service. In consent mode the visitor’s browser loads it only after the visitor allows its category, in “Notice only” mode right away. The service then receives what its tracking code collects: the page address, the visitor’s IP address, browser details and its own cookies.

* Google Analytics and Google Tag Manager by Google: [terms of service](https://policies.google.com/terms), [privacy policy](https://policies.google.com/privacy).
* Yandex Metrica by Yandex (code from mc.yandex.ru): [terms of use](https://yandex.com/legal/metrica_termsofuse/en/), [privacy policy](https://yandex.com/legal/confidential/en/).
* VK Ads pixel by VK (Top.Mail.Ru code from top-fwz1.mail.ru): [license agreement](https://help.mail.ru/legal/terms/top/la-eng/), [privacy policy](https://help.mail.ru/legal/terms/adsvk/privacy/).

**Built-in list of known services.** To recognize trackers and embeds on your pages, the plugin contains the addresses and cookie names of known services, for example `connect.facebook.net` for the Meta Pixel, `analytics.tiktok.com` or `youtube.com/embed`. The plugin never connects to these addresses and sends them nothing: it only compares the tags of your pages with the list and holds the matching ones back until the visitor allows their category. When the visitor allows it, the visitor’s browser loads the tracker, video or map that you or your theme added to the site, as it would without the plugin.

**Usage statistics, off by default.** Only if you turn them on in Settings → Enkrat Cookie → Advanced, the plugin sends the site address, a random installation ID, the plugin and WordPress versions and the event (active, activated, deactivated, deleted) to `https://enkrat.com/updates/stats/ping.php` once a day and when it is activated, deactivated or deleted. Data of visitors and users is never sent. Service provider: ENKRAT, [privacy policy](https://enkrat.com/ek-cookie/privacy/en/).

== For developers ==

Manual markup:

    <script type="text/plain" data-enkrat-category="analytics">/* code */</script>
    <script type="text/plain" data-enkrat-category="marketing" data-enkrat-src="https://example.com/pixel.js" async></script>
    <iframe data-enkrat-category="external" data-enkrat-src="https://www.youtube.com/embed/ID"></iframe>

The `data-enkrat-skip` attribute excludes a tag from autoblocking.

Shortcodes and template functions:

    [enkrat_cookie_button]      <?php enkrat_cookie_settings_button(); ?>  round “Cookie settings” button
    [enkrat_cookie_settings]    <?php enkrat_cookie_settings_link(); ?>    “Cookie settings” text link
    [enkrat_cookie_table]                                                cookie table for the cookie policy page

Any element with the `enkrat-cookie-open` class or the `data-enkrat-cookie="open"` attribute opens the cookie settings.

A script added with `wp_enqueue_script`:

    add_filter('enkrat_cookie_handles', fn($map) => $map + ['my-handle' => 'analytics']);

Skip page rewriting for some requests:

    add_filter('enkrat_cookie_skip_blocking', fn($skip) => $skip || is_page('landing'));

JavaScript API:

    EnkratCookie.mode;               // 'consent' | 'notice' | 'off'
    EnkratCookie.has('analytics');
    EnkratCookie.get();
    EnkratCookie.open();
    EnkratCookie.acceptCategory('external');
    EnkratCookie.on(state => console.log(state));
    document.addEventListener('enkrat-cookie:change', e => console.log(e.detail));

The `<html>` element gets `data-enkrat-mode="consent|notice|off"`, `data-enkrat-analytics="1|0"` and similar attributes. With rules by country, `html[data-enkrat-mode="off"] .enkrat-cookie-link { display: none; }` hides the footer link where no banner is shown. The `enkrat_cookie_update` event is pushed to `dataLayer` when the choice changes. Google Consent Mode v2 and the WP Consent API are supported.

The minified files `assets/js/*.min.js` and `assets/css/*.min.css` are built with terser and Lightning CSS from the readable files next to them, which are included in the plugin. With `SCRIPT_DEBUG` enabled the plugin loads the readable files.

== Legal notice ==

The plugin helps collect and document consent, but it does not replace a privacy policy or legal advice. In the EU, consent for non-essential cookies follows from the ePrivacy Directive and the GDPR. In Russia, there is no separate cookie law: consent is required when the data collected by analytics and advertising is personal data processed on the basis of consent (Art. 9 of Federal Law 152-FZ).

== Changelog ==

= 1.2.7 =
* The “Found on the site” list on the Advanced tab is now built in the browser. The plugin no longer reads cookies on the server or stores their names, and the WordPress login cookies cannot get into the list.
* Security hardening based on the WordPress.org plugin review.

= 1.2.6 =
* The cookie table no longer keeps services that are gone from the site: a service not seen on the site’s pages for 90 days leaves the table by itself.
* A service found on the site can be removed from the list on the Blocking tab, for example after you delete its code. If the code is still on the site, the service comes back when its page is opened.

= 1.2.5 =
* Compatibility with PHP 7.4: the plugin no longer calls string functions that appeared in PHP 8.

= 1.2.4 =
* The banner preview opens only through the links on the settings page: they are now signed with a nonce.
* An element with a reserved id in the page content can no longer switch off blocking or hide the banner on that page.
* The consent log exports to CSV without warnings on PHP 8.4 and newer, and keeps the port in page addresses.
* Security hardening based on the WordPress.org plugin review.

= 1.2.3 =
* On WordPress 6.9 and newer pages are processed through the template output buffer built into WordPress, together with other plugins that use it.
* Security hardening based on the WordPress.org plugin review.

= 1.2.2 =
* When consent is withdrawn, Yandex Metrica data in the browser's local storage is removed along with its cookies.

= 1.2.1 =
* “Video review” button on the settings page: a 10-minute overview of the plugin with chapters. Shown when the admin language is Russian, the video is in Russian.
* Security hardening based on Plugin Check results.

= 1.2.0 =
* Page builders: Bricks, Elementor, Divi, Oxygen, Breakdance and others. In the builder editor the page looks the way visitors see it after making a choice: the cookie settings button appears once, on the page itself, without the banner, blocking and tracking codes. The button in the editor can be turned off.
* Ukrainian, Spanish and French translations. Regional variants of a language (Mexican Spanish, Canadian French, Austrian German and others) use its main translation.

= 1.1.0 =
* Mode “By country”: consent, a notice or no banner depending on the visitor’s country. The country is detected from the device time zone, without requests to third-party services, and page caching keeps working.
* The plugin follows the law of every country out of the box: consent in the EU, the UK, Russia, Kazakhstan, Turkey, Brazil and about 115 more countries, a notice in the USA, Japan, Australia and others, no banner where there is no personal data law. Laws adopted but not yet in force switch on by themselves on their effective date.
* Exceptions by country: pick a country from the list and its own mode.
* Link to a separate consent to personal data processing under the banner (required in Russia since 1 September 2025).
* Cookie table for the cookie policy page: the `[enkrat_cookie_table]` shortcode lists the site’s cookies by category with lifetimes and purposes, and updates itself.
* The plugin finds cookies on the site and lets you add unknown ones to your own list; your cookies are removed when consent is withdrawn.
* Optional: dim the page and lock scrolling until the visitor chooses.
* Advanced tab: custom blocking rules and the cookie list, so the main tabs stay simple.
* White label for agencies: your own plugin name and author, no ENKRAT branding. Turned on in the Advanced tab, or in wp-config.php to hide the setting from clients.
* The `enkrat-cookie-open` class opens the cookie settings from any button, handy in page builders.
* `EnkratCookie.mode` in the JavaScript API and the `data-enkrat-mode` attribute on `<html>`.
* Optional usage statistics, off by default: if you turn them on in the Advanced tab, once a day the plugin sends its developer the site address, a random installation ID and the plugin and WordPress versions. Nothing else is sent.
* Donate tab: if you like the plugin, you can support its development by card or in cryptocurrency.

= 1.0.0 =
* Cookie consent banner: granular consent by category (necessary, analytics, advertising, external services) or a notice with a single button.
* Analytics, advertising, videos and maps do not load until consent. Autoblocking of known services: Yandex Metrica, Google Analytics, Google Tag Manager, Meta Pixel, VK Ads, TikTok Pixel, Hotjar, Microsoft Clarity and others.
* Tracking codes for Yandex Metrica, Google Analytics 4, Google Tag Manager and VK Ads are set in the plugin and run only after consent.
* Placeholders instead of YouTube, Vimeo, VK Video, Rutube, Yandex Maps and Google Maps until the visitor allows external services.
* Google Consent Mode v2 and the WP Consent API.
* Consent log without IP addresses or visitor IDs, with CSV export.
* English, Russian, German and Czech. Default banner texts follow the site language, edited texts are translated with WPML and Polylang.
* Floating “Cookie settings” button or a text tab, the `[enkrat_cookie_button]` and `[enkrat_cookie_settings]` shortcodes and template functions.
