Web Analytics for e commerce

  • Posts: 9
  • Thank you received: 0
5 years 7 months ago #305734

Hello

I want to track this analytics code for e commerce report when the customer has finished the chekout.

<script language='javascript'>;
gtag('event', 'purchase', { 'event_category' : 'ecommerce', 'event_label' : <?php $row->product_name ?> });
</script>;

My Question are:

Where can i put the script (file xxx.php,) ?

I want to track the product name of my shop, i dont know if ($row->product_name) is right varible that i must use it.
I hope your news

Kind Regads.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 7 months ago #305736

Hi,

You can add that code in the file "after_end" of the view "checkout" via the menu Display>Views provided that you didn't enter a "return URL" in your payment method and that your payment method redirects you to the payment gateway at the end of the checkout for the payment.
If it's not the case, then you'll want to add the code int he file "end" of the view "checkout".
In both cases, you can find the products in the order in the array $this->order->products since you can have several products. So your code will have to be something like that:

<script language='javascript'>
<?php foreach( $this->order->products as $row) { ?>
gtag('event', 'purchase', { 'event_category' : 'ecommerce', 'event_label' : '<?php echo $row->order_product_name; ?>' });
<?php }  ?>
</script>

Please Log in or Create an account to join the conversation.

Time to create page: 0.056 seconds
Powered by Kunena Forum