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

Remove Universal Analytics code #320

Merged
merged 12 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
44 changes: 0 additions & 44 deletions assets/js/src/admin-ga-settings.js

This file was deleted.

63 changes: 3 additions & 60 deletions includes/class-wc-abstract-google-analytics-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ abstract public static function load_analytics( $order = false );
* @param WC_Order $order WC_Order Object
*/
public function add_transaction( $order ) {
if ( 'yes' === self::get( 'ga_enhanced_ecommerce_tracking_enabled' ) || 'yes' === self::get( 'ga_gtag_enabled' ) ) {
wc_enqueue_js( static::add_transaction_enhanced( $order ) );
} else {
wc_enqueue_js( self::add_transaction_universal( $order ) );
}
wc_enqueue_js( static::add_transaction_enhanced( $order ) );
}

/**
Expand Down Expand Up @@ -128,55 +124,6 @@ public static function get_product_identifier( $product ) {
return apply_filters( 'woocommerce_ga_product_identifier', $identifier, $product );
}

/**
* Generate Universal Analytics add item tracking code
*
* @param WC_Order $order WC_Order Object
* @param WC_Order_Item $item The item to add to a transaction/order
* @return string
*/
protected function add_item_universal( $order, $item ) {
$_product = version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_product_from_item( $item ) : $item->get_product();

$code = "ga('ecommerce:addItem', {";
$code .= "'id': '" . esc_js( $order->get_order_number() ) . "',";
$code .= "'name': '" . esc_js( $item['name'] ) . "',";
$code .= "'sku': '" . esc_js( $_product->get_sku() ? $_product->get_sku() : $_product->get_id() ) . "',";
$code .= "'category': " . self::product_get_category_line( $_product );
$code .= "'price': '" . esc_js( $order->get_item_total( $item ) ) . "',";
$code .= "'quantity': '" . esc_js( $item['qty'] ) . "'";
$code .= '});';

return $code;
}

/**
* Generate Universal Analytics transaction tracking code
*
* @param WC_Order $order WC_Order object
* @return string Add Transaction tracking code
*/
protected function add_transaction_universal( $order ) {
$code = "ga('ecommerce:addTransaction', {
'id': '" . esc_js( $order->get_order_number() ) . "', // Transaction ID. Required
'affiliation': '" . esc_js( get_bloginfo( 'name' ) ) . "', // Affiliation or store name
'revenue': '" . esc_js( $order->get_total() ) . "', // Grand Total
'shipping': '" . esc_js( $order->get_total_shipping() ) . "', // Shipping
'tax': '" . esc_js( $order->get_total_tax() ) . "', // Tax
'currency': '" . esc_js( version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ) . "' // Currency
});";

// Order items
if ( $order->get_items() ) {
foreach ( $order->get_items() as $item ) {
$code .= self::add_item_universal( $order, $item );
}
}

$code .= "ga('ecommerce:send');";
return $code;
}

/**
* Returns a 'category' JSON line based on $product
*
Expand Down Expand Up @@ -226,17 +173,13 @@ abstract public function remove_from_cart();

/**
* Enqueue JavaScript to track a product detail view
*
* @param WC_Product $product
*/
abstract public function product_detail( $product );
abstract public function product_detail();

/**
* Enqueue JS to track when the checkout process is started
*
* @param array $cart items/contents of the cart
*/
abstract public function checkout_process( $cart );
abstract public function checkout_process();

/**
* Enqueue JavaScript for Add to cart tracking
Expand Down
Loading