Question
Why is my "purchase" event is not being picked up by GTM?
I've read the documentation and I'm currently attempting to migrate to gtag 4, everything seems to be captured by GTM except the purchase event. Below is the code I implemented, could this be a global object issue? Perhaps other third parties code I have are interfering with it in the global object?
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create','UA-9075829-1','auto');
ga('require','ec');
<cfoutput>
<cfif Variables.bTrackReceipt>
<cfloop query="qOfqCart">
ga('ec:addProduct', {
'id': '#courseid#'
,'name': '#JSStringFormat(coursename)#'
,'category': 'Course'
,'brand': 'My Store'
<cfif unitprice EQ unitdiscountprice>
,'price':'#unitprice#'
<cfelse>
,'price':'#unitdiscountprice#'
</cfif>
,'quantity': '#quantity#'
});
</cfloop>
ga('ec:setAction', 'purchase', {
'id': '#JSStringFormat(Session.sPersPayInfo.InvoiceNumber)#'
,'affiliation': 'My Store'
,'revenue': '#Variables.nTotalPrice#'
,'tax': '#Session.sCartItemTotals.Tax#'
,'shipping': '0'
});
</cfif>
<cfif Len(Request.sTrackFunnelStep)>
ga('send','pageview','#Request.sTrackFunnelStep#');
<cfelse>
ga('send','pageview',location.pathname);
</cfif>
</cfoutput>
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script><cfif (Application.stSiteInfo.SiteType IS "live")>
<!--- This is the default for tracking the receipt in the javascripts below --->
<cfparam name="Variables.bTrackReceipt" default="0">
<!--- BEGIN for GA4 --->
<!--- file used: js-gtag-ga4 --->
<cfinclude template="/ctolms1/pagelets/js-gtag-ga4.cfm">
<!--- END for GA4 --->
<cfif Request.stPageControls.usegoogleremarketing>
<!--- Using cfinclude so ReceiptXML can be passed --->
<cfinclude template="/ctolms1/pagelets/js-google-remarketing.cfm">
</cfif>
<cfif Request.stPageControls.usegoogleanalytics>
<!--- Using cfinclude so ReceiptXML can be passed --->
<cfinclude template="/ctolms1/pagelets/js-google-analytics.cfm">
</cfif>
<cfif Request.stPageControls.usebinguet>
<!--- Using cfinclude so ReceiptXML can be passed --->
<cfinclude template="/ctolms1/pagelets/js-bing-uet.cfm">
</cfif>
<cfif IsDefined("Request.stPageControls.usecje") AND Request.stPageControls.usecje>
<!--- Using cfinclude so ReceiptXML can be passed --->
<cfinclude template="/ctolms1/pagelets/js-cje.cfm">
</cfif>