Skip to content
Open
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
6 changes: 3 additions & 3 deletions facebook-commerce-events-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ private function is_pixel_enabled() {
private function add_hooks() {

// inject Pixel
add_action( 'wp_head', array( $this, 'inject_base_pixel' ) );
add_action( 'wp_head', array( $this, 'inject_base_pixel' ), 1 );
add_action( 'wp_footer', array( $this, 'inject_base_pixel_noscript' ) );

// ViewContent for individual products
add_action( 'woocommerce_after_single_product', array( $this, 'inject_view_content_event' ) );
add_action( 'woocommerce_after_single_product', array( $this, 'maybe_inject_search_event' ) );
add_action( 'woocommerce_after_single_product', array( $this, 'inject_view_content_event' ), 20 );
add_action( 'woocommerce_after_single_product', array( $this, 'maybe_inject_search_event' ), 20 );

// ViewCategory events
add_action( 'woocommerce_after_shop_loop', array( $this, 'inject_view_category_event' ) );
Expand Down
24 changes: 24 additions & 0 deletions includes/Events/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected function prepare_user_data( $data ) {
'client_user_agent' => $this->get_client_user_agent(),
'click_id' => $this->get_click_id(),
'browser_id' => $this->get_browser_id(),
'external_id' => $this->get_external_id(),
)
);
// Country key is not the same in pixel and CAPI events, see:
Expand Down Expand Up @@ -277,6 +278,29 @@ protected function get_browser_id() {
return ! empty( $_COOKIE['_fbp'] ) ? wc_clean( wp_unslash( $_COOKIE['_fbp'] ) ) : '';
}

/**
* Retrieves the external ID based on the session's customer ID.
*
* @since 2.0.0
*
* @return string The external ID if available, or an empty string otherwise.
*/
protected function get_external_id()
{
// Ensure the WooCommerce session exists and has the get_customer_id method
if (isset(WC()->session) && method_exists(WC()->session, 'get_customer_unique_id')) {
$customer_id = WC()->session->get_customer_unique_id();

// Return the customer ID as a string if it exists
if (! empty($customer_id)) {
return strval($customer_id);
}
}

// Return an empty string if no customer ID is available
return '';
}


/**
* Gets the data.
Expand Down