woocommerce / google-listings-and-ads

Sync your store with Google to list products for free, run paid ads, and track performance straight from your store dashboard.
https://woo.com/products/google-listings-and-ads/
GNU General Public License v3.0
44 stars 21 forks source link

Add integration with WP Consent API #2425

Closed martynmjones closed 2 months ago

martynmjones commented 2 months ago

Changes proposed in this Pull Request:

Adds integration with the WP Consent API plugin to better support different consent banner configurations.

If the plugin is installed on a website then the existing consent state will be sent as an update when tracking is initialised. For on-page updates, we're adding an event listener for wp_listen_for_consent_change which is dispatched by WP Consent API when any changes are made.

Detailed test instructions:

General test instruction

  1. Build extension from add/2387-wp-consent-api-integration
  2. Install Complianz and setup a basic consent banner
  3. Debug the site using Tag Assistant while logged out
  4. Grant consent via consent banner
  5. Confirm a Consent event is sent with the updated state
  6. Trigger GLA tracking events on page
  7. Confirm the events are all recorded in Tag Assistant and that the consent On-page Update is Granted (Under the Consent tab) Screenshot 2024-05-20 at 17 50 37
  8. Revoke consent via the consent banner
  9. Confirm that the consent state is no longer Granted in Tag Assistant

Additional details:

Copied and modified slightly from https://github.com/woocommerce/woocommerce-google-analytics-integration/pull/425

Changelog entry

Add - Integration with the WP Consent API plugin

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.

Project coverage is 64.3%. Comparing base (340cb89) to head (210333d). Report is 17 commits behind head on develop.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2425/graphs/tree.svg?width=650&height=150&src=pr&token=UROWUPF1LX&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce)](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2425?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) ```diff @@ Coverage Diff @@ ## develop #2425 +/- ## ============================================ + Coverage 63.4% 64.3% +0.9% - Complexity 0 4281 +4281 ============================================ Files 321 780 +459 Lines 5027 21910 +16883 Branches 1218 1218 ============================================ + Hits 3188 14097 +10909 - Misses 1672 7646 +5974 Partials 167 167 ``` | [Flag](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2425/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | Coverage Δ | | |---|---|---| | [js-unit-tests](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2425/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | `63.4% <ø> (ø)` | | | [php-unit-tests](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2425/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | `64.6% <0.0%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2425?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | Coverage Δ | | |---|---|---| | [src/Google/GlobalSiteTag.php](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2425?src=pr&el=tree&filepath=src%2FGoogle%2FGlobalSiteTag.php&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce#diff-c3JjL0dvb2dsZS9HbG9iYWxTaXRlVGFnLnBocA==) | `0.0% <0.0%> (ø)` | | ... and [458 files with indirect coverage changes](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2425/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce)
tomalec commented 2 months ago

Thanks for implementing it @martynmjones .

I tested it with Complianz and GDPR Cookie Compliance :)

I'm not sure if you already worked on it, but to save some time, I made a branch with E2E tests moved from GA4W https://github.com/woocommerce/google-listings-and-ads/compare/add/2387-wp-consent-api-integration...dev/add-consent-tests?expand=1

tomalec commented 2 months ago

also added some docs notes https://github.com/woocommerce/google-listings-and-ads/compare/add/2387-wp-consent-api-integration...tweak/add-consent-api-docs?expand=1

Feel free to merge those PRs or disregard them if you have a better implementation.

tomalec commented 2 months ago

I also made changes to the public-faceing docs as for GA4W.

martynmjones commented 2 months ago

Hey @tomalec, many thank for adding the tests and docs 🙌 I've merged your branch into this one.

I tested it with Complianz and GDPR Cookie Compliance :)

Thanks for testing! I've not made further changes but have published the PR properly and requested a review to confirm were good to merge into develop.