woocommerce / woocommerce-google-analytics-integration

WordPress plugin: Provides the integration between WooCommerce and Google Analytics.
http://wordpress.org/plugins/woocommerce-google-analytics-integration/
172 stars 69 forks source link

Add E2E testing to track events across all page types #385

Closed mikkamp closed 7 months ago

mikkamp commented 7 months ago

Changes proposed in this Pull Request:

With the focus on shifting towards blocks yet still supporting classic pages, we have to cover the following types of pages to track their events:

  1. Traditional pages using the classic shortcodes.
  2. Default WooCommerce pages which are created during install, most have been switched to blocks when starting with a new site.
  3. The "Products (Beta)" block.
  4. The "Product Collection (Beta)" block. This one is intended to replace the Products block.

To test this manually is a large burden. This PR copies over the E2E we have for tracking in GLA and modifies them to work with the GA events we send. This makes it easier to test the events across several different page/block types.

The tests in this PR did highlight some inconsitencies, and events that aren't being tracked, so the following changes are needed to make these tests pass:

Detailed test instructions:

  1. Install any required patches as listed above
  2. Install all npm dependencies nvm use && npm ci
  3. Build assets either through npm start or npm run build
  4. Ensure we don't have any conflicting E2E docker instances running (like the one from GLA)
  5. Start the wp-env site npm run wp-env:up
  6. Install browser (only needed once) npx playwright install chromium
  7. Run tests npm run test:e2e
  8. Confirm tests are successful

Note: workflow is included (direct copy from GLA). We can only trigger it once this PR is merged (unless you want to clone the repo to test it).

Additional details:

These test aim to cover the most common scenarios, but while testing I still came across the following inconsistencies/parts we aren't covering (these can be addressed in follow up PR's):

Changelog entry

mikkamp commented 7 months ago

Run e2e tests again, all tests passed except:

[chromium] › gtag-events/blocks-pages.test.js:160:2 › GTag events on block pages › Add to cart event is sent from a product collection block shop page

Which is related to the code change from https://github.com/woocommerce/woocommerce-google-analytics-integration/pull/378#issuecomment-1987786319. Not sure if I change the code locally wrong?

The code you changed is right, did you rebuild the assets after that change? I'm not quite sure why it would be failing otherwise. Maybe you can check the site at http://localhost:8889 to see how it handles the "Product Collection Shop" page. Make sure to add some test settings to enable tracking, during E2E that's enabled and cleared.

mikkamp commented 7 months ago

@tomalec Thanks for the review. Since this is approved and working, I'm going to merge it so we can focus on the other issues and get them tested. We can always refactor / change any other details later if needed.