in Google Tag Manager and Google Analytics, I am trying to track cart addition so that I can then compare them with effective purchases and see which product I am losing most of my business for.
Till here, I am fine. I set up the following data layer with a product array.
for (var i=0; i < myvariable.length; i++) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push ({
'event': 'AddtoCart',
'ecommerce': {
'currencyCode': myvariable[i]['currency'],
'add': {
'products': [{
'name': myvariable[i]['name'],
'id': myvariable[i]['id'],
'category': myvariable[i]['category'],
'price': myvariable[i]['price'],
'variant': myvariable['variant'],
'dimension1': myvariable[i]['mydimension'],
'quantity': 1,
}]
}
}
});
}
Now, I need to persist data layer throughout the different ecommerce steps in order not to duplicate the values every time user goes ahead or even jump backwards. And here is the problem, based on the structure of the ecommerce I work with:
- Page 1: product list
- Page 2 (optional, depending on the settings): product upgrades
- Page 3: Guest details
- Page 4: Confirmation
In page 1 when a user selects a product he jumps directly to page 2 (if present) or 3. If he wants to select another product he has to go back and select again. All products are stored in the cart, which is generated as soon as the user adds a product, regardless of page the user is.
What I would like to have is to track all product listed in the cart before he either closes the page/jumps out of the purchase process or confirms the purchase. It doesn´t really matter what he adds, removes, re-adds during the purchase process. Basically the last cart status (with all products listed) is what I want to be sent to Google Analytics as an event.
I understand this is something I can achive with cookies, but not sure how exactly I should set it up, store all data in it and then trigger it to GA. I would really appreciate a few hints in this matter.
Thanks in advance for your help.