when my app is installed I create a script tag (through the shopify API). I am only interested in running this script on product view pages. what is a reliable way to check whether the script is run by a product view page? Should I ask the merchant to put something in to their liquid file manually?
This should work, in your JavaScript:
// If we are on a product page
if (window.location.pathname.indexOf('/products/') !== -1) {
// What's the product handle?
var productHandle = pathname.match(/\/products\/([a-z0-9\-]+)/)[1];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With