# Pinterest tracking pixel

Create a snippet called "pinterest-pixel.liquid" and paste the following code:

snippets/pinterest-pixel.liquid

{% assign pinterestPixel = shop.apps.pinterest.pixel_id %}

<script type="text/javascript">
    !function(e){if(!window.pintrk){window.pintrk=function(){window.pintrk.queue.push(
        Array.prototype.slice.call(arguments))};var
        n=window.pintrk;n.queue=[],n.version="3.0";var
        t=document.createElement("script");t.async=!0,t.src=e;var
        r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(t,r)}}("https://s.pinimg.com/ct/core.js");
    pintrk('load', '{{ pinterestPixel }}');
    pintrk('page');
</script>
<noscript>
    <img height="1" width="1" style="display:none;" alt="" src="https://ct.pinterest.com/v3/?tid={{ pinterestPixel }}&event=init&noscript=1" />
</noscript>

<script>
{% if request.path contains "checkout/thanks/" and first_time_accessed %}
    {% assign orderQuantity = 0 %}
    {% for row in order.line_items %}
        {% increment orderQuantity %}
    {% endfor %}

     pintrk('track', 'checkout', {
       value: {{ order.total_price | money_without_currency | replace: '.', '' | replace: ',', '.' }},
       order_quantity: {{ orderQuantity }},
       currency: '{{ order.currency }}',
     });
{% endif %}

{% if cart.just_added_item %}
      pintrk('track', 'AddToCart', {
        value: {{ cart.just_added_item.variant.price | divided_by: 100 }},
        order_quantity: {{ cart.just_added_item.quantity }},
        currency: '{{ shop.currency }}'
      });
{% endif %}
</script>

Include it in your layout/theme.liquid just before the closing of your </head> tag.

<!doctype html>
<html lang="en">
<head>
    ...
    {% include 'pinterest-pixel' %}
</head>

Now you can enter your Pinterest Pixel ID within Settings ->Setup -> Analytics -> Pinterest Pixel ID and your snippet will use that pixel id.

This is a basic setup of the the pinterest tracking script. We include as a snippet in Codefort so you can customize it however you want.