Liquid, JavaScript, themes, sales channels
I am trying to add code in my Dawn theme for web tracking.
Klaviyo says to enter this code into the product.liquid template.
<script type="text/javascript">
var _learnq = _learnq || [];
var item = {
Name: {{ product.title|json }},
ProductID: {{ product.id|json }},
Categories: {{ product.collections|map:'title'|json }},
ImageURL: "https:{{ product.featured_image.src|img_url:'grande' }}",
URL: "{{ shop.secure_url }}{{ product.url }}",
Brand: {{ product.vendor|json }},
Price: {{ product.price|money|json }},
CompareAtPrice: {{ product.compare_at_price_max|money|json }}
};
_learnq.push(['track', 'Viewed Product', item]);
_learnq.push(['trackViewedItem', {
Title: item.Name,
ItemId: item.ProductID,
Categories: item.Categories,
ImageUrl: item.ImageURL,
Url: item.URL,
Metadata: {
Brand: item.Brand,
Price: item.Price,
CompareAtPrice: item.CompareAtPrice
}
}]);
</script>
I have been trying to add this into the product.json (as I think that is the equivalent of product.liquid), but then I get the error of "Error: Invalid JSON: unexpected token".
Any help would be greatly appreciated.
You cannot add it in the product.json file, as it only accepts a schema written in json format. It should be added in a file ending in .liquid in order for it to be executed. I you do not have a specific product.liquid file, in the product.json template, you can find the main section that appears on your page in that template: bellow "sections", the first type that appears is most likely to be the central section in your product page. For instance, here it is called "product-form.liquid":
Find the file with that name ending in .liquid and paste the code bellow all the code, but above any {% schema %} tag, and it should be enough.
Thanks a lot, your answer is really helpful to me.😁
Hello, I try to add this html code and get this response:
What i'm dpoing wrong ?
Thank you
User | RANK |
---|---|
38 | |
29 | |
13 | |
12 | |
9 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023