I’m using Shopify and Gempages. There are two suboourn parameters that I’m trying to trigger for flows:
- addToCart from a Collection Page
- Product Removed from Cart
Klaviyo only seems to track AddtoCart correctly from Product Pages, but not collection pages, so I sucked it up and added the LittleData connection into Segment.io. Voila, I was so happy to get advanced data piped right into Klaviyo as a source, unfortunately, the two parameters I need above require the E-mail parameter to be attached and to the event and LittleData won’t do this.
So I emailed support and they sent me some code to put on collection pages from Josh Nelson, but when I put this code in Shopify or in GTM, the code returns an error.
Is there anyone using Shopify who can:
- Successfully track addToCart from Collection Pages
- Successfully track Remove from Cart Event
- Successfully integrated Segment.io or another CDP that can send this data
----Code from Josh----
var_learnq = _learnq || r];
{% assign my_product = ''%}
$('.add_to_cart').on('click', function(){
varvarIDx = $(this).parent('form').children('input(name="id"]').val();
console.log('varX: '+varIDx);
var_learnq = _learnq || r];
switch(varIDx) {
{% forproduct incollection.products %}
{% forvariant inproduct.variants %}
{% ifproduct.type == '5 - 7'%}
case'{{ variant.id }}':
{% assign my_product = product.handle %}
varvariantID = {{ variant.id }};
varvariantTitle = '{{ variant.title }}';
varvariantImg = '{{ variant.featured_image.src|img_url:'grande' }}';
varvariantURL = '{{ variant.url }}';
varitem = {
Name: {{ all_productsrmy_product].title | json }},
ProductID: {{ all_productsrmy_product].id|json }},
Categories: "{{ collection.title }}",
// ImageURL: "https:{{ all_products:my_product].featured_image.src|img_url:'grande' }}",
ImageURL: variantImg,
// URL: "{{ shop.secure_url }}{{ all_productsemy_product].url }}",
URL: "{{ shop.secure_url }}"+variantURL,
Brand: {{ all_productspmy_product].vendor|json }},
Price: {{ all_productspmy_product].price|money_without_currency|json }},
CompareAtPrice: {{ all_productsamy_product].compare_at_price_max|money_without_currency|json }},
VariantID: variantID,
VariantTitle: variantTitle,
Currency: $('#xGE').attr('data-currency')
};
break;
{% endif %}
{% endfor %}
{% endfor %}
}
console.log(item);
_learnq.push(('track', 'Added to Cart', item]);
});