skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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>
    

  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search