Skip to content

Instantly share code, notes, and snippets.

@klondaiker
Last active May 6, 2022 14:05
Show Gist options
  • Save klondaiker/f41efc457ea988a0729a5316920e7ddd to your computer and use it in GitHub Desktop.
Save klondaiker/f41efc457ea988a0729a5316920e7ddd to your computer and use it in GitHub Desktop.
$(window).on('m.order-submit', orderSubmitHandler);
var orderSubmitHandler = function(event, order, isOnlinePayment) {
var content_ids = [];
var contents = [];
var product_ids = [];
order.items.forEach(function(item) {
product_ids.push({"id": item.good.productId})
content_ids.push(item.good.globalId);
contents.push(
{
id: item.good.globalId,
quantity: item.count,
item_price: (item.totalPrice.cents/100)/item.count
});
});
var facebookData = {
currency: order.totalWithDeliveryPrice.currencyIsoCode,
value: order.totalWithDeliveryPrice.cents/100,
content_type: 'product',
content_ids: content_ids,
contents: contents
};
console.debug('Purchase data for fbq', facebookData);
try {
fbq('track', 'Purchase', facebookData);
} catch (e) {
console.error('fbq: ', e.message);
}
var vkData = {
"products" : product_ids,
"business_value" : 1000,
"total_price" : (order.totalWithDeliveryPrice.cents/100),
"currency_code": order.totalWithDeliveryPrice.currencyIsoCode
};
console.debug('purchase data for vk', vkData);
try {
VK.Retargeting.ProductEvent(13777, "purchase", vkData);
} catch (e) {
console.error('vkData: ', e.message);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment