I want to track woo commerce events using a custom plugin.
I added the provided tracking code to the header using the wp_head hook, and I need to track pageviews, searches, product views...etc.
I wrote something like this,
add_action('woocommerce_single_product_summary', array(
&$this,
'viewed_product'
) , 15);
And the function :
public function viewed_product()
{
$product_id = get_the_ID();
$product = wc_get_product($product_id);
?>
<script>
xyz.push({
"track" : "productview",
"product_id" : <?php echo $product_id ?>,
"product_name" : <?php echo $product->get_name() ?>,
"product_price" : <?php echo $product->get_price() ?>,,
});
</script>
<?php
I can see that the tracking code is loaded in the header. But when I viewed the product it gives the error,
_xyz is not defined
Any solutions for this issue?