Compatibility to Real Cookie Banner
- Dominant language
- JavaScript
- Stars
- 1.4k
- Forks
- 383
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 80
Description
## Feature Description
Hey, Matthew here from devowl.io! 😊
We had a talk with one of the Google Site Kit developers in the [WordCamp Europe 2024 in Torino](https://europe.wordcamp.org/2024/) about the compatibility between our plugin Real Cookie Banner and Google Site Kit. The developer recommended to us to open an issue here on GitHub to evaluate further things.
**First**: Our plugin Real Cookie Banner offers some functions only in the PRO version, including the Google Consent Mode. If any of you need the PRO version, please write to me at https://devowl.io/support and I will send you a license accordingly.
### Google Consent Mode
The first thing we need to do is to make the implementation of the Google Consent Mode work. Currently, Google Site Kit provides the following option:

When this option is enabled, Google Site Kit will add the `gtag('consent', 'default', ...)` snippet to the HTML head:
https://github.com/google/site-kit-wp/blob/da09975064917b82dc3f331b9872e37bd7cb78c0/includes/Core/Consent_Mode/Consent_Mode.php#L91-L96
This conflicts with our Google Consent Mode implementation. Here it would be practical if you provided a filter that completely deactivates the Google Consent Mode functionality of your plugin and lets it be taken over by another plugin. In practice, this could be a filter that simply takes over the plugin name. As a result, for a better user experience, you could also display a corresponding notice:
```php
add_filter('googlesitekit_consent_responsible_plugin', function($name) {
return 'Real Cookie Banner';
});
```

For example, WooCommerce Google Analytics provides a similar hook: [GA4W overwrites the consent mode defaults set by the other extension](https://github.com/woocommerce/woocommerce-google-analytics-integration/blob/e13e3684d235a0fd80cc08a4a993f0571059ede7/README.md#ga4w-overwrites-the-consent-mode-defaults-set-by-the-other-extension)
_Why do we not want to use the WP Consent API plugin?_ We've had this discussion several times and can only say that the Consent API strictly does not correspond to our point of view. The main reason for this is that the Consent API grants consent per category, but not per service as required by the GDPR (see a similar discussion https://github.com/elementor/elementor/pull/12567#issuecomment-814173249).
### Integration in our scanner
Our plugin offers a scanner which scans for used services in all subpages of the WordPress instance. This currently finds Google Analytics when used through Google Site Kit. But when creating the service in our plugin, this could lead to multiple embed codes and therefore lead to conflicts. For this, we have introduced a filter, which allows us to do a "native" integration into any other plugin: https://docs.devowl.io/real-cookie-banner/hooks/RCB_Templates_TechnicalHandlingIntegration.html
This could potentially look like this:

From coding perspective, it is just this code snippet:
```php
add_action('RCB/Templates/TechnicalHandlingIntegration', function ($integration) {
if (
defined('GOOGLESITEKIT_PLUGIN_MAIN_FILE') &&
// google_analytics_embed_active() is a example function which checks if Google Analytics embed is active in your plugin
google_analytics_embed_active() &&
// Replace __FILE__ with your main plugin file (the absolute path to your `your-plugin/your-plugin.php` file)
// See also https://developer.wordpress.org/plugins/plugin-basics/header-requirements/
$integration->integrate(constant('GOOGLESITEKIT_PLUGIN_MAIN_FILE'), 'google-analytics-analytics-4')) {
// Disable opt-in and opt-out script
$integration->setCodeOptIn('');
$integration->setCodeOptOut('');
}
});
```
Whether we can add this hook within our plugin or your plugin is up to you. All we need is a function or API that allows us to check whether Google Site Kit inserts the embed code in the HTML (replacement for `google_analytics_embed_active()`).
### Further outlook
These things would be the first things we should tackle together. To summarize again:
- [ ] Add a filter to disable the implementation of Google Site Kit's Consent Mode
- [ ] Show a notice that another plugin is responsible for the Google Consent Mode
- [ ] Provide API's to check if Google Site Kit is embedding snippets for the available services so we can create a scanner compatibility
Once we have implemented this, we can check and implement further compatibility. We would like to implement all services provided by Google Site Kit.
What do you think?
---------------
_Do not alter or remove anything below. The following sections will be managed by moderators only._
## Acceptance criteria
*
## Implementation Brief
* [ ]
### Test Coverage
*
## QA Brief
*
## Changelog entry
*
Contributor guide
Research direction
Start with includes/Core/Consent_Mode/Consent_Mode.php, the linked Consent Mode implementation, and review how Google Site Kit detects and embeds service snippets. The issue's requested outcome is the three-part checklist: consent-mode ownership, a notice for the responsible plugin, and APIs that expose active embeds for scanner integration; acceptance and test details are not yet provided.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100