Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the 'new_customer' parameter on the 'purchase' event #412

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading