Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.7.4 #2440

Merged
merged 14 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Going forward, Google will always add the prefix "legacy-" for the branch suppor

- [Usage Tracking](./src/Tracking/README.md)
- [Hooks defined or used in GLA](./src/Hooks/README.md)
- [gtag consent mode](./docs/gtag-consent-mode.md)
- [gtag consent mode & cookie banners](./docs/gtag-consent-mode.md)

<p align="center">
<br/><br/>
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
*** WooCommerce Google Listings and Ads Changelog ***

= 2.7.4 - 2024-06-25 =
* Add - Integration with the WP Consent API plugin.
* Dev - Add E2E tests for WP Consent API integration.
* Tweak - Add docs note about WP Consent API integration.

= 2.7.3 - 2024-06-18 =
* Fix - Fatal error when loading campaign in the marketing overview section.
* Tweak - Replace woo.com references with woocommerce.com.
Expand Down
10 changes: 8 additions & 2 deletions docs/gtag-consent-mode.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
## Googla Analytics (gtag) Consent Mode
## Google Analytics (gtag) Consent Mode

Unless you're running the [Google Analytics for WooCommerce](https://woocommerce.com/products/woocommerce-google-analytics/) extension for a more sophisticated configuration, Google Listings and Ads will add Google's `gtag` to help you track some customer behavior.

To respect your customers' privacy, we set up the default state of [consent mode](https://support.google.com/analytics/answer/9976101). We set it to deny all the parameters for visitors from the EEA region. You can add an extension or CMP that delivers a banner or any other UI to let visitors update their consent in runtime.
To respect your customers' privacy, we set up the default state of [consent mode](https://support.google.com/analytics/answer/9976101). We set it to deny all the parameters for visitors from the EEA region.

You can also customize your own default state configuration using the `woocommerce_gla_gtag_consent` filter providing any snippet that uses [Google's `gtag('consent', 'default', {…})` API ](https://developers.google.com/tag-platform/security/guides/consent?consentmode=advanced).

After the page loads, the consent for particular parameters can be updated by other plugins or custom code implementing UI for customer-facing configuration using [Google's consent API](https://developers.google.com/tag-platform/security/guides/consent?hl=en&consentmode=advanced#update-consent) (`gtag('consent', 'update', {…})`).

## Cookie banners & WP Consent API

The extension does not provide any UI, like a cookie banner, to let your visitors grant consent for tracking. However, it's integrated with [WP Consent API](https://wordpress.org/plugins/wp-consent-api/), so you can pick another extension that provides a banner that meets your needs.

Each of those extensions may require additional setup or registration. Usually, the basic default setup works out of the box, but there may be some integration caveats.
4 changes: 2 additions & 2 deletions google-listings-and-ads.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Google Listings and Ads
* Plugin URL: https://wordpress.org/plugins/google-listings-and-ads/
* Description: Native integration with Google that allows merchants to easily display their products across Google’s network.
* Version: 2.7.3
* Version: 2.7.4
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Text Domain: google-listings-and-ads
Expand All @@ -30,7 +30,7 @@

defined( 'ABSPATH' ) || exit;

define( 'WC_GLA_VERSION', '2.7.3' ); // WRCS: DEFINED_VERSION.
define( 'WC_GLA_VERSION', '2.7.4' ); // WRCS: DEFINED_VERSION.
define( 'WC_GLA_MIN_PHP_VER', '7.4' );
define( 'WC_GLA_MIN_WC_VER', '6.9' );

Expand Down
61 changes: 61 additions & 0 deletions js/src/wp-consent-api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const consentMap = {
statistics: [ 'analytics_storage' ],
marketing: [ 'ad_storage', 'ad_user_data', 'ad_personalization' ],
};

const setCurrentConsentState = () => {
// eslint-disable-next-line camelcase -- `wp_has_consent` is defined by the WP Consent API plugin.
if ( typeof wp_has_consent === 'function' ) {
if ( window.wp_consent_type === undefined ) {
window.wp_consent_type = 'optin';
}

const consentState = {};

for ( const [ category, types ] of Object.entries( consentMap ) ) {
if (
// eslint-disable-next-line camelcase, no-undef -- `consent_api_get_cookie` is defined by the WP Consent API plugin.
consent_api_get_cookie(
window.consent_api.cookie_prefix + '_' + category
) !== ''
) {
// eslint-disable-next-line camelcase, no-undef -- `wp_has_consent` is defined by the WP Consent API plugin.
const hasConsent = wp_has_consent( category )
? 'granted'
: 'denied';

types.forEach( ( type ) => {
consentState[ type ] = hasConsent;
} );
}
}

if ( Object.keys( consentState ).length > 0 ) {
window.gtag( 'consent', 'update', consentState );
}
}
};

document.addEventListener( 'wp_listen_for_consent_change', ( event ) => {
const consentUpdate = {};

const types = consentMap[ Object.keys( event.detail )[ 0 ] ];
const state =
Object.values( event.detail )[ 0 ] === 'allow' ? 'granted' : 'denied';

if ( types !== undefined ) {
types.forEach( ( type ) => {
consentUpdate[ type ] = state;
} );

if ( Object.keys( consentUpdate ).length > 0 ) {
window.gtag( 'consent', 'update', consentUpdate );
}
}
} );

if ( document.readyState === 'loading' ) {
document.addEventListener( 'DOMContentLoaded', setCurrentConsentState );
} else {
setCurrentConsentState();
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "google-listings-and-ads",
"title": "Google Listings and Ads",
"version": "2.7.3",
"version": "2.7.4",
"description": "google-listings-and-ads",
"author": "Automattic",
"license": "GPL-3.0-or-later",
Expand Down
12 changes: 6 additions & 6 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires at least: 5.9
Tested up to: 6.5
Requires PHP: 7.4
Requires PHP Architecture: 64 Bits
Stable tag: 2.7.3
Stable tag: 2.7.4
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -111,6 +111,11 @@ Yes, you can run both at the same time, and we recommend it! In the US, advertis

== Changelog ==

= 2.7.4 - 2024-06-25 =
* Add - Integration with the WP Consent API plugin.
* Dev - Add E2E tests for WP Consent API integration.
* Tweak - Add docs note about WP Consent API integration.

= 2.7.3 - 2024-06-18 =
* Fix - Fatal error when loading campaign in the marketing overview section.
* Tweak - Replace woo.com references with woocommerce.com.
Expand All @@ -124,9 +129,4 @@ Yes, you can run both at the same time, and we recommend it! In the US, advertis
* Update - Enable users to seamlessly set up conversion tracking, without having to set up merchant center first or requiring campaign creation.
* Update - Move the Google Ads account connection process from step 4 to step 1 of the onboarding flow.

= 2.7.1 - 2024-05-29 =
* Dev - Add info about Legacy Google Ads API Client Library in Readme.
* Fix - Prevent PHP Warning when Statistics is null.
* Update - Implement Account Request Review Requests in the extension.

[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/google-listings-and-ads/trunk/changelog.txt).
21 changes: 20 additions & 1 deletion src/Google/GlobalSiteTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,23 @@ function () {

$this->assets_handler->register( $gtag_events );

$wp_consent_api = new ScriptWithBuiltDependenciesAsset(
'gla-wp-consent-api',
'js/build/wp-consent-api',
"{$this->get_root_dir()}/js/build/wp-consent-api.asset.php",
new BuiltScriptDependencyArray(
[
'dependencies' => [ 'wp-consent-api' ],
'version' => $this->get_version(),
]
)
);

$this->assets_handler->register( $wp_consent_api );

add_action(
'wp_footer',
function () use ( $gtag_events ) {
function () use ( $gtag_events, $wp_consent_api ) {
$gtag_events->add_localization(
'glaGtagData',
[
Expand All @@ -204,6 +218,10 @@ function () use ( $gtag_events ) {

$this->register_js_for_fast_refresh_dev();
$this->assets_handler->enqueue( $gtag_events );

if ( ! class_exists( '\WC_Google_Gtag_JS' ) && function_exists( 'wp_has_consent' ) ) {
$this->assets_handler->enqueue( $wp_consent_api );
}
}
);
}
Expand Down Expand Up @@ -293,6 +311,7 @@ protected function get_consent_mode_config() {
ad_user_data: 'denied',
ad_personalization: 'denied',
region: ['AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IS', 'IE', 'IT', 'LV', 'LI', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB', 'CH'],
wait_for_update: 500,
} );";
/**
* Filters the default gtag consent mode configuration.
Expand Down
Loading