David McIntyre
David McIntyre

Reputation: 3

Shopify Additional Scripts

Within Shopify's "Additional Scripts" section of the Checkout, I need to add a script (below) for tracking purposes, and for the life of me I cannot get the cart item quantity to render.

Apparently I should be able to use Liquid syntax to render the value, but whenever I do a test, the value is empty.

Below is my script that isn't working.

<script language='JavaScript1.1' async src='//pixel.trackingcompany.com/event/js?mt_id=123&mt_adid=456&mt_exem=&mt_excl=&s1={{ cart.item_count }}'></script>

When it renders, I currently get everything except the {{ cart.item_count }} value.

Upvotes: 0

Views: 1330

Answers (2)

David McIntyre
David McIntyre

Reputation: 3

Thanks Drip! I was able to resolve this using the code below. It the CART variable is not available once the checkout has occurred, so changing to the checkout as you suggested and looping through the line items did the trick!

{% assign count = 0 %}
{% for line_item in checkout.line_items %}
{% assign count = count | plus: line_item.quantity %}
{% endfor %}
<script language='JavaScript1.1' async src='//pixel.trackingcompany.com/event/js?mt_id=123&mt_adid=456&mt_exem=&mt_excl=&s1={{ count }}'></script>

Upvotes: 0

drip
drip

Reputation: 12943

There is no cart item in the checkout process.

You should swap cart.item_count with checkout.line_items.size or order.line_items.size.

Upvotes: 2

Related Questions