Add Google Analytics Tracking For single product

Hi!

Google has given me this Tracking code:

To integrate once a customer completes a purchase.

However.

I’d like to make it for a single product.

I found this guide:

Which says to use:

get_items() as $item ) {
$product = $order->get_product_from_item( $item );
if ( ! $product ) { continue; }
$sku = $product->get_sku();
if (preg_match(’/-tp$/’, $sku) === 1) {
return true;
}
}
return false;
}

function my_custom_tracking( $order_id ) {
$order = new WC_Order( $order_id );

if (order_items_include_tracking_pixel($order, $order_id)) {
$total = $order->get_order_total();

// INSERT TRACKING CODE or
// DO YOUR CUSTOM BEHAVIOR HERE
}
}

add_action( ‘woocommerce_thankyou’, ‘my_custom_tracking’ );

?>

And:

if (preg_match(’/-tp$/’, $sku) === 1) {

with the product SKU in the funcitons.php file.

But I’m not sure what exactly to put into the functions.php file for this.

This is the product that I’m trying to track.

https://www.dzdrones.com/product/limitless-frame-and-pod-promo/

Can you help?

Thanks!

Hello There,

I didn’t see the code we need to add. Please use preformatted text to add a code so it will not blend with the text and display as code instead.

< !-- Google Code for Drone Frame Purchase Conversion Page -->
< script type=“text/javascript”>
/* */
< /script>
< script type=“text/javascript” src="//www.googleadservices.com/pagead/conversion.js">
< /script>
< noscript>
< div style=“display:inline;”>
< img height=“1” width=“1” style=“border-style:none;” alt="" src="//www.googleadservices.com/pagead/conversion/975645038/?label=pb_PCMbxtXIQ7tKc0QM&guid=ON&script=0"/>
< /div>

Not sure how to do that so I just added a space in front of each. Hope that works. Thanks!

Hello,

This plugin is a option that will facilitate your way: https://woocommerce.com/products/woocommerce-google-analytics-pro/

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.