Skip to content

Commit

Permalink
Added the 'new_customer' parameter on the 'purchase' event
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Mar 12, 2024
1 parent 98b3e6f commit 1ba3b44
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Release date: 2024-MM-DD
Find out about what's new in our [our release post](https://gtmkit.com/gtm-kit-1-20/).

#### Enhancements:
* Added support for the 'new_customer' parameter on the 'purchase' event, which is used for customer acquisition reporting and Google Smart Shopping campaigns.
* Added a debug log for debugging the 'purchase' event without make a purchase.

#### Bugfixes:
Expand Down
6 changes: 4 additions & 2 deletions src/Integration/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace TLA_Media\GTM_Kit\Integration;

use Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore;
use Automattic\WooCommerce\StoreApi\StoreApi;
use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
use Automattic\WooCommerce\StoreApi\Schemas\V1\CartItemSchema;
Expand Down Expand Up @@ -561,14 +562,15 @@ public function get_purchase_event( WC_Order $order, array $data_layer = [] ): a
$order_value -= $shipping_total;
}

$data_layer['event'] = 'purchase';
$data_layer['ecommerce'] = [
$data_layer['event'] = 'purchase';
$data_layer['ecommerce'] = [
'transaction_id' => (string) $order->get_order_number(),
'value' => (float) $order_value,
'tax' => (float) $order->get_total_tax(),
'shipping' => (float) $shipping_total,
'currency' => $order->get_currency(),
];
$data_layer['new_customer'] = ! DataStore::is_returning_customer( $order );

$coupons = $order->get_coupon_codes();

Expand Down

0 comments on commit 1ba3b44

Please sign in to comment.