Pinterest AddToCart Event Code on Craft Theme

I’m trying to set up the Pinterest AddToCart Event code on my craft theme, but I can’t seem to find where to paste it.

I know I need to put it on the main.product.liquid, but I can’t find the addtocart button.

Any help would be highly appreciated.

Thank you!

Hi @mzie25

I hope you are doing good and welcome to the Shopify Community!

I am Mehak from MS Web Designer (Top Rated Shopify Certified Experts and eCommerce Consultant from Singapore).

If you cannot use the native Pinterest app for Shopify, you will need to install the code yourself, by following steps:

While steps 1 & 2 are generic (if you have any trouble, you should reach Pinterest support to help you add them), the step 3 (“Add to cart” code) is dependent on the theme.

1.Open the list of themes in your Shopify admin and, for the theme you want to add the code, click on “More actions” then “Edit code” (please note you need to have the theme purchased to do that):

2.In the “Assets” folder, click on “custom.js” file (note that depending on your theme and the custom code you have installed, you may have more files than what is shown in the screenshot below):

3.Add the end of the file, copy-paste the following code:

document.addEventListener('product:added', function(event) {
  pintrk('track', 'addtocart');
});

If you want to get the variant ID, you can get it by using “event.detail.variant.id” code.

4.Click on “Save” button to preserve the change:

Please feel free to contact us in case you need any help.

Regards,

Mehak