JavaScript API is accessible through the window.productFruits.api
global variable. Check out the left menu to get more details on JS methods for particular tools.
Before you can use API, you have to check if Product Fruits is initialized. You have 3 ways, choose the method that suits your use case best.
Option 1: Global variable check
You can check window.productFruitsIsReady
for true
.
Option 2: Listen to the ready event
You can also listen to productfruits_ready
event. Don't forget to attach this handler before you run the Product Fruits snippet. For instance:
window.addEventListener('productfruits_ready', function() {
console.log('Product Fruits is ready!');
});
// here comes the Product Fruits snippet
Option 3: Ready callback
You can also provide window.productFruitsReady
function callback. Don't forget to set this before you run the Product Fruits snippet. For instance:
window.productFruitsReady = function() {
console.log('Product Fruits is ready!');
};
// here comes the Product Fruits snippet