Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

add_to_cart event GA4

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 06-15-2023, 12:11 PM
 
keystone keystone is offline
 

X-Adept
  
Join Date: Jul 2006
Location: USA
Posts: 787
 

Default 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}
__________________
www.uscandleco.com - X-Cart Version 4.7.11 Gold Plus php7.3
mods:
reCaptcha
running on UNIX

www.keystonecandle.com X-Cart Gold Plus - Version 4.7.11 php7.2
mods:
reCaptcha
cdseo pro
running on UNIX
Reply With Quote
  #2  
Old 06-16-2023, 05:28 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,197
 

Default 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...
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #3  
Old 06-16-2023, 06:32 AM
 
keystone keystone is offline
 

X-Adept
  
Join Date: Jul 2006
Location: USA
Posts: 787
 

Default Re: add_to_cart event GA4

Oh, alright thanks Steve.
__________________
www.uscandleco.com - X-Cart Version 4.7.11 Gold Plus php7.3
mods:
reCaptcha
running on UNIX

www.keystonecandle.com X-Cart Gold Plus - Version 4.7.11 php7.2
mods:
reCaptcha
cdseo pro
running on UNIX
Reply With Quote
  #4  
Old 08-17-2023, 11:59 AM
 
jw@leathergroups.com jw@leathergroups.com is offline
 

Newbie
  
Join Date: Apr 2013
Posts: 2
 

Default 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?
Reply With Quote
  #5  
Old 11-12-2024, 05:28 AM
 
mcintyremedia mcintyremedia is offline
 

Newbie
  
Join Date: Jun 2011
Posts: 5
 

Default Re: add_to_cart event GA4

Did you get his worked out? Thanks
__________________
216 Digital Marketing - Cleveland, OH Cleveland SEO.
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 09:02 AM.

   

 
X-Cart forums © 2001-2020