Pinterest Addtocart event code -Value Missing

shamsul96
Tourist
7 0 0

Hello Everyone!

I need help to fix the Pinterest Addtocart event code -Value Missing.

I tried hard to fix the warning but failed to fix it. I take help from youtube videos, blogs.

See the screenshots: 

shamsul96_0-1634987494813.png

 

I add the following code in my sections/product-template.liquid

 

<script>
pintrk('track', 'pagevisit',
       {
line_items: [
{
  product_id: '{{product.id}}'
  product_category: '{{product.type}}'
}
]
});
  pintrk('track', 'addtocart', {
value: {{ product.price | money_without_currency }}',
    currency: '{{ shop.currency }}',
line_items: [
{
  product_id: '{{product.id}}'
  product_category: '{{product.type}}'
}
]
});
</script>

 

I also get help from here: https://help.pinterest.com/en/business/article/link-your-shopify-and-pinterest-accounts to add checkout event.

Note: I use Warehouse theme. (Not Os 2.0). and I manually set up the Pinterest tag on my Shopify website.

Can you help me to fix the Pinterest Tag warning? Please don't recommend installing app.

Thanks in advance. 

Replies 5 (5)

Niki_K
Shopify Partner
447 45 124

Hi @shamsul96,

the file you choose for the Pinterest tracking code is correct, however, could you please specify more in which part have you exactly inserted the code? 

As for the add2cart event, you need to add the piece of code into the add2cart button section. In other words, you have to find, where the add2cart button section starts and use onclick event so that add2cart fires when the user adds the product into the cart. 

 

<button type="submit" name="add"
                xxxxxxxxxx code
 onclick="pintrk('track', 'addtocart', {value: {{ product.price | divided_by: 100 }}, currency: '{{ shop.currency }}', line_items: [{ product_id: '{{ product.id }}', product_category: {% assign first_category = product.collections | map: "title" | first %} '{{first_category}}' }]} );">
                xxxxxxxxxx code
 </button>

 

Send me a link to your store to niki@ecommercepot.com and I'll help you out.
For more info what I do, visit my agency website ecommercepot.com or my personal website nikikozak.me.
shamsul96
Tourist
7 0 0

I use this code on my add to cart button.

 {%- else -%} <button onclick="pintrk('track', 'addtocart');" type="submit" class="product-form__add-button button button--primary" data-action="add-to-cart">{{ 'product.form.add_to_cart' | t }}</button> {%- endif -%}

 

Is It okay?

Niki_K
Shopify Partner
447 45 124

Hi @shamsul96,

you're missing the value, currency and line items in the code. Pinterest Tag helper and analytics won't be tracking the add to cart event and it will be showing you errors because it's missing the mentioned attributes. 

Send me a link to your store to niki@ecommercepot.com and I'll help you out.
For more info what I do, visit my agency website ecommercepot.com or my personal website nikikozak.me.
shamsul96
Tourist
7 0 0

So, How can I fix it? 

<button type="submit" name="add"
                xxxxxxxxxx code
 onclick="pintrk('track', 'addtocart', {value: {{ product.price | divided_by: 100 }}, currency: '{{ shop.currency }}', line_items: [{ product_id: '{{ product.id }}', product_category: {% assign first_category = product.collections | map: "title" | first %} '{{first_category}}' }]} );">
                xxxxxxxxxx code
 </button>

 

Here xxxxxxxxxx code means interest tag ID?

 

Please let me know. thanks

Niki_K
Shopify Partner
447 45 124

Hi @shamsul96,

the xxxxx code means the rest of the code in the button tag. I just didn't copied the entire button tag since it might vary according to the theme. Nevermind, here's the entire code I've in the button tag. You don't need to add anything else to the add to cart button. The Pinterest tag id should be inserted in the theme.liquid file. Plus, in the checkout section -> additional scripts there should be the tracking code for the checkout event.

If it's not working, write me PM, I'll be happy to help you. 

<button type="submit" name="add"
    {% unless current_variant.available %} aria-disabled="true"{% endunless %}
     aria-label="{% unless current_variant.available %}{{ 'products.product.sold_out' | t }}{% else %}{{ 'products.product.add_to_cart' | t }}{% endunless %}"
     class="btn product-form__cart-submit{% if section.settings.enable_payment_button %} btn--secondary-accent{% endif %}"
      data-add-to-cart onclick="pintrk('track', 'addtocart', {value: {{ product.price | divided_by: 100 }}, currency: '{{ shop.currency }}', line_items: [{ product_id: '{{ product.id }}', product_category: {% assign first_category = product.collections | map: "title" | first %} '{{first_category}}' }]} );">
       <span data-add-to-cart-text>
           {% unless current_variant.available %}
                {{ 'products.product.sold_out' | t }}
           {% else %}
                {{ 'products.product.add_to_cart' | t }}
           {% endunless %}
        </span>
        <span class="hide" data-loader>
             {% include 'icon-spinner' %}
        </span>
</button>

 

Send me a link to your store to niki@ecommercepot.com and I'll help you out.
For more info what I do, visit my agency website ecommercepot.com or my personal website nikikozak.me.