X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   add_to_cart event GA4 (https://forum.x-cart.com/showthread.php?t=78545)

keystone 06-15-2023 12:11 PM

add_to_cart event GA4
 
Has anyone successfully added an add_to_cart event for GA4 in xcart v.4.7.# using gtag?
I have the purchase event set up and working fine. Here is my current code...
Code:

{if $main eq "order_message" and $orders}
  <!-- Google Analytics 4-->
  <script>
    gtag('event', 'purchase');

    {foreach $orders as $order}
      gtag(
        'event',
        'purchase',
        {csi_get_gtag_ecommerce_data event="purchase" order=$order.order products=$order.products}
      );
    {/foreach}
  </script>
  <!-- End Google Analytics 4 -->
  {/if}


cflsystems 06-16-2023 05:28 AM

Re: add_to_cart event GA4
 
Yes. You can't do it through the tpl files as the purchase event as the add to cart goes through an ajax call so it has to be done with the ajax callback and the add to cart js file. Same goes for some other events at checkout - add payment, add shipping, begin checkout...

keystone 06-16-2023 06:32 AM

Re: add_to_cart event GA4
 
Oh, alright thanks Steve.

jw@leathergroups.com 08-17-2023 11:59 AM

Re: add_to_cart event GA4
 
Quote:

Originally Posted by keystone
Has anyone successfully added an add_to_cart event for GA4 in xcart v.4.7.# using gtag?
I have the purchase event set up and working fine. Here is my current code...
Code:

{if $main eq "order_message" and $orders}
  <!-- Google Analytics 4-->
  <script>
    gtag('event', 'purchase');

    {foreach $orders as $order}
      gtag(
        'event',
        'purchase',
        {csi_get_gtag_ecommerce_data event="purchase" order=$order.order products=$order.products}
      );
    {/foreach}
  </script>
  <!-- End Google Analytics 4 -->
  {/if}



Which file was this used in for the purchase event?


All times are GMT -8. The time now is 11:05 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.