google / google/site-kit-wp

Add E2E tests for Enhanced Conversions data collection during WooCommerce purchases

Open
#12,012 6 comments 0 reactions 1 assignee Claimed by @ankitrox View on GitHub
Next Up P2 Team M Type: Enhancement
Dominant language
JavaScript
Stars
1.4k
Forks
383
Avg merge
4d 14h
Merged PRs (30d)
77

Description

## Feature Description

Add E2E test coverage for Enhanced Conversions (ECEE) data flowing through the **WooCommerce** purchase event. WooCommerce is unique among the supported event providers because it extracts user data **server-side** from a `WC_Order`'s billing details — including phone (E.164 normalization via `WC_Countries`) and a full address (street, city, region, postal code, country) — see `WooCommerce.php::extract_user_data_from_order()`. Because of this distinct code path, it warrants its own E2E coverage separate from the shared client-side form-plugin path.

### Why this exists / Background

Per Slack discussion with @aaemnnosttv:

> *"I don't really want to add e2e tests for each of these plugins […] We should generally have coverage in place for Plugin conversion tracking, the PII aspect is just a part of that, it doesn't warrant a whole separate suite of tests. […] each plugin we add into our flow will impact stability, so we should try to find a kind of middle ground."*

To find that middle ground, the per-plugin ECEE E2E tickets (#11908, #12006, #12008, #12009, #12010, #12011) are consolidated into a single representative form-plugin ticket (see #12013), since those plugins all share the `getUserData( fields )` utility in `assets/js/event-providers/utils.js`. WooCommerce is the **only** plugin with a meaningfully distinct ECEE data flow, so it keeps its own dedicated ticket — this one.

---------------

_Do not alter or remove anything below. The following sections will be managed by moderators only._

## Acceptance criteria

* E2E tests verify that on a completed WooCommerce checkout, the order's billing details (email, phone, name, and address) are sent to `gtag` as Enhanced Conversions user data on the `purchase` event, when all of the following are true:
* The `gtagUserData` feature flag is enabled.
* Plugin Conversion Tracking is enabled.
* At least one of Ads / Analytics 4 / Tag Manager is connected.
* E2E tests cover both **guest checkout** and **logged-in user** purchase scenarios.
* E2E tests verify that no Enhanced Conversions user data is sent on the `purchase` event when:
* Plugin Conversion Tracking is **disabled**.
* The `gtagUserData` feature flag is **disabled**.
* No GTag-using module (Ads, Analytics 4, Tag Manager) is connected.
* E2E tests verify partial-data handling — only the billing fields actually present on the order are sent. Realistic scenarios to cover:
* Orders without a billing phone (phone is optional by default in WooCommerce) produce no phone in the Enhanced Conversions data.
* Orders for a country that does not use a state or postal code produce no `region` / `postal_code` in the Enhanced Conversions data.

#### Notes on test stability

WooCommerce must be installed for these tests to be meaningful — the integration cannot be exercised otherwise. To address Evan's concern about plugin-test fragility (similar to past AMP issues), consider:

* Pinning a known-good WooCommerce version in CI.
* Creating orders programmatically (via WC factory functions / `WC_Order` API or REST) rather than driving the WooCommerce checkout UI.
* Asserting on the `gtag` payload (the integration boundary), not on WooCommerce's UI rendering.

## Implementation Brief
- [ ] In `tests/playwright/specs/enhanced-conversions/woocommerce.spec.ts`
- Browser-only WooCommerce journey: shop -> add to cart -> checkout -> place order -> order received.
- Test purchase payload from dataLayer `event`=`purchase`, assert `event_source=site-kit` and `user_data` contract.
- Cover guest and logged-in purchase paths with deterministic checkout fixtures.
- Cover gating conditions: conversion tracking disabled, `gtagUserData` disabled, and no connected GTag module.
- Use resilient checkout execution for legacy Woo/WP matrix: option-based shop/checkout page resolution, deterministic add-to-cart path, and conditional purchase-event waits for scenarios where conversion scripts are expected to be absent.
- Keep payload assertions aligned with Woo formatter behavior: lowercase names/address fields, E.164 phone normalization, optional region/postal omissions for non-required locales.
- [ ] In `tests/playwright/specs/enhanced-conversions/enhanced-conversions.spec.ts`
- Remove WooCommerce-specific helpers and cases from this file.
- Keep generic enhanced-conversions hashing coverage only (module connectivity + feature-flag permutations).
- [ ] In `tests/playwright/docker/wordpress/plugins/enhanced-conversions.php`
- Retain only test hooks for connected modules / init tags.
- Remove all E2E helper REST endpoints for Woo activation, order creation, and conversion tracking toggles.
- [ ] In `tests/playwright/bin/generate-backup-sql.sh`
- Activate WooCommerce during backup generation and import sample catalog from `woocommerce/sample-data/sample_products.xml`.
- Use `wordpress-importer` for XML import, then uninstall importer before backup export.
- Seed WooCommerce checkout prerequisites in backup generation: create shop/cart/checkout/my-account pages and set Woo page options.
- Seed deterministic payment/store defaults required for browser checkout in E2E (`US:CA` default country and enabled BACS/COD settings).
- Keep WooCommerce active in generated backup to ensure checkout routes and payment methods are available in isolated per-test DBs.
- Build WordPress service when generating backup to guarantee DB snapshot matches current Dockerfile/image inputs.
- Regenerate `tests/playwright/docker/mariadb/backup.sql` after script updates.
- [ ] In `tests/playwright/docker/wordpress/Dockerfile`
- Install WooCommerce in image via zip download flow matching twentynineteen install pattern.
- Pin WooCommerce to a WP 5.2.21-compatible version for Playwright matrix stability.
- [ ] In `tests/playwright/docker-compose.yml`
- Bump `wp` image tag revision to Woo-enabled variant to avoid stale image collisions.
- [ ] In `tests/playwright/playwright.config.ts`
- Ignore new WooCommerce spec on mobile viewport.
- [ ] In `tests/playwright/wordpress/database.ts` and `tests/playwright/wordpress/wordpress.ts`
- Add DB-backed option helpers (`getOption`, `setOption`) so WooCommerce E2E can toggle conversion tracking and resolve page IDs.
- [ ] In `tests/playwright/README.md`
- Update Playwright infra documentation to reflect the revised WordPress image tag format (`${WP_VERSION}-v2`).

### Test Coverage
- Not required as this is E2E test change.

## QA Brief

*

## Changelog entry
*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.