// Add this code to your Product Page using Velo Dev Mode
$w.onReady(function () {
// Get the product data from the Wix Product Page
$w('#productPage').getProduct()
.then((product) => {
if (product) {
// Map the Wix product data to the Klaviyo item structure
const item = {
"ProductName": product.name,
"ProductID": product._id,
"SKU": product.sku,
"Categories": product.collections.map(c => c.name), // Creates an array of collection names
"ImageURL": product.mainMedia.src, // Gets the main product image URL
"URL": product.productPageUrl,
"Brand": "YOUR BRAND NAME", // Wix doesn't have a default brand field, so you may need to set this manually
"Price": product.price,
"CompareAtPrice": product.comparePrice // This field exists if a product is on sale
};
// Check if the klaviyo object is available before tracking
if (typeof klaviyo !== 'undefined') {
klaviyo.track("Viewed Product", item);
} else {
console.log("Klaviyo object not found. Make sure Klaviyo's main script is installed.");
}
}
})
.catch((error) => {
console.error("Error fetching Wix product data:", error);
});
});