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

Track purchase transaction ID #388

Closed mikkamp closed 7 months ago

mikkamp commented 7 months ago

Changes proposed in this Pull Request:

This PR adds the transaction ID (order ID) which is missing from the purchase event. Previously we sent the following details that can be seen here:

'transaction_id' => $order->get_order_number(),
'affiliation'    => get_bloginfo( 'name' ),
'value'          => $order->get_total(),
'tax'            => $order->get_total_tax(),
'shipping'       => $order->get_total_shipping(),
'currency'       => $order->get_currency(),
'items'          => $event_items,

Here we add them back to the details we send with the purchase event.

Closes #387

Detailed test instructions:

  1. Setup the extension for tracking
  2. Create some products to add to the cart
  3. Complete a purchase in an incognito window
  4. Check the purchase event and confirm it contains both the correct transaction ID set to order ID and affiliation set to the site name (if shipping / taxes is enabled those totals can be confirmed as well)

Note: The changed E2E test still relies on a fix in #384 so it's a little harder to test.

Additional details:

In the tests I didn't add a check for confirming the shipping totals and tax totals are tracked correctly. In order to do so we would need to set up a default shipping method. I think we can leave this for a follow up issue.

Changelog entry

mikkamp commented 7 months ago

Went ahead and implemented the suggestions for totals. Merging this now.