Add Tracks event with source data

This commit is contained in:
Jeremy Pry 2023-09-06 18:52:18 -04:00 committed by Justin Palmer
parent b787271c86
commit edfe2896b4
No known key found for this signature in database
GPG Key ID: ACAB7C35AA2577AF
1 changed files with 21 additions and 0 deletions

View File

@ -14,6 +14,7 @@ use WC_Customer;
use WC_Log_Levels;
use WC_Logger_Interface;
use WC_Order;
use WC_Tracks;
use WP_User;
/**
@ -103,6 +104,7 @@ class SourceAttributionController implements RegisterHooksInterface {
'woocommerce_checkout_order_created',
function( $order ) {
$source_data = $this->get_source_values();
$this->send_order_tracks( $source_data, $order );
$this->set_order_source_data( $source_data, $order );
}
);
@ -344,4 +346,23 @@ class SourceAttributionController implements RegisterHooksInterface {
return false;
}
}
/**
* Send order source data to Tracks.
*
* @param array $source_data The source data.
* @param WC_Order $order The order object.
*
* @return void
*/
private function send_order_tracks( array $source_data, WC_Order $order ) {
$tracks_data = array(
'origin' => $source_data['origin'] ?? '',
'device_type' => $source_data['device_type'] ?? '(unknown)',
'session_pages' => $source_data['session_pages'] ?? 0,
'order_total' => $order->get_total(),
);
$this->proxy->call_static( WC_Tracks::class, 'record_event', 'order_source_attribution', $tracks_data );
}
}