Home » Blog » Lead Generation »
Weâll be looking at tracking Infusionsoft order forms via e-commerce tracking feature of google analytics.
GTM would be used for the setup process.
Here are some important prerequisites:
- Make sure analytics tracking is turned on in View > E-commerce settings
- GTM Code is installed on all pages of the site.
Hereâs what youâll get
- E-commerce Transaction Data in Google Analytics
- No Duplicate Tracking of order IDs
The code to prevent duplicate tracking was inspired from here.
Youâll be ready in no time. Just follow these 3 simple steps:
- Infusionsoft E-commerce Tracking Code Setup in GTM
- Google Analytics E-commerce Tracking Tag
- Infusionsoft Order Form Setup
Infusionsoft E-commerce Tracking Code Setup in GTM
- Create Custom Variables of type URL > Select Query & type âorderIdâ. (make sure you use the right capitalisation here!)
- Create a new Custom HTML tag & paste the following code.
<script>
function captureOrder(){
window.dataLayer = window.dataLayer || []
var d=[];
var t = 0
var productName=/productName=([^&]+)/i.exec(location.search)[1].split(',');
var price=/price=([^&]+)/i.exec(location.search)[1].split(',')
var orderId = /orderId=([^&]+)/i.exec(location.search)[1]
if(productName.length != price.length) { return false }
for(var i=0;i<productName.length;i++)
{
d.push({
'sku': '100' +"-"+productName[i],
'name': productName[i] ,
'price': parseFloat(price[i]),
'quantity': 1
})
t+=parseFloat(price[i])
}
dataLayer.push({
'transactionId' : orderId,
'transactionTotal' : t,
'transactionProducts' : d,
'event' : 'transaction_success'
})
}
var orderID = /orderID=([^&]+)/i.exec(location.search)[1];
if(document.cookie.indexOf('orderIds')>-1){
var trackedOrderIds = /orderIds=([^;]+)/g.exec(document.cookie)[1].split("|");
if(trackedOrderIds.indexOf(orderID)==-1){
captureOrder();
trackedOrderIds.push(orderID);
var d = new Date();
d.setTime(d.getTime() + (180*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = "orderIds=" + trackedOrderIds.join('|') + "; " + expires;
}
}else{
captureOrder();
var trackedOrderIds = [];
trackedOrderIds.push(orderID);
var d = new Date();
d.setTime(d.getTime() + (180*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = "orderIds=" + trackedOrderIds.join('|') + "; " + expires;
}
</script>
- Create a Trigger with the following configuration:
(Make sure to enter the correct Thank you page URL by replacing the â/order-success/â)
Google Analytics E-commerce Tracking Tag
- Create Google Analytics Tag with Type âTransactionâ
- Trigger the above tag with a custom event named âtransaction_successâ.
Infusionsoft Order Form Setup
- Go To E-commerce > E-commerce Setup > Order Forms.
- Create an order form or open the once created.
- Here, you can include any number of products. The only thing to check here is quantity should be 1 for each product & user should not be able to change the quantity.
- In Thank you page tab, make sure to use the thankyou page on your domain.
- Now most important part. When you paste your thankyou page URL, include the âproductNameâ& âpriceâ parameter.
Eg: If you have a single product âProductAâ for price 100.
Thankyou Page URL: www.xyz.com/order-success/?productName=ProductA&price=100Eg: If you have 2 products âProductAâ & âProductBâ for price 100 & 120 respectively.
Thankyou Page URL: www.xyz.com/order-success/?productName=ProductA,ProductB&price=100,120
& so onâŠ.. - You can replace the âProductAâ& âProductBâ with any name you like. The same will appear as the product name in google analytics.
- Lastly, check the option âPass contactâs information to the Thank You Pageâ.
- Make sure you have products with the single quantity which cannot be changed by users.Also, in Google Analytics, the e-commerce settings in the view should be turned on.You should use the Thankyou page URL on your domain instead of infusionsoftâs.Let me know if you implement it successfully or face any issues.
Ready to Grow Your Business?
Jos Aguiar is a father, entrepreneur and traveler. He’s been building brands and helping businesses grow since 2010. Since founding leadshunt in 2021 he’s been on a mission to help create a new standard of excellence within the industry combining expertise in traffic generation and education of clientele through our content and learning materials. His aim is to not merely sell you leads, but to leave you permanently better.