// Step 1: Initialize the Pinterest Tag SDK (exclude HTML)
!function(e){if(!window.pintrk){window.pintrk = function () {
window.pintrk.queue.push(Array.prototype.slice.call(arguments))};var
n=window.pintrk;n.queue=[],n.version="3.0";var
t=document.createElement("script");t.async=!0,t.src=e;var
r=document.getElementsByTagName("script")[0];
r.parentNode.insertBefore(t,r)}}("https://s.pinimg.com/ct/core.js");
pintrk('load', 'YOUR_TAG_ID_HERE');
pintrk('page');
// Step 2: Subscribe to customer events and track them with Pinterest Tag
analytics.subscribe("product_viewed", event => {
pintrk('track', 'checkout', {
value: event.data.productVariant.price,
currency: event.data.productVariant.currency,
line_items: [{ product_name: event.data.productVariant.title, product_id: event.data.productVariant.id }]
});
});
analytics.subscribe("product_added_to_cart", event => {
pintrk('track', 'addtocart', {
value: event.data.cartLine.cost.totalAmount,
currency: event.data.cartLine.cost.currencyCode,
line_items: [{ product_name: event.data.cartLine.merchandise.title, product_id: event.data.cartLine.merchandise.id }]
});
});
analytics.subscribe("checkout_started", event => {
pintrk('track', 'checkout', {
value: event.data.checkout.totalPrice,
currency: event.data.checkout.totalPrice.currencyCode
});
});
analytics.subscribe("checkout_completed", event => {
const lineItems = event.data.checkout.lineItems.map(item => ({
product_name: item.title,
product_id: item.variant.id,
quantity: item.quantity,
price: item.variant.price
}));
pintrk('track', 'checkout', {
value: event.data.checkout.totalPrice,
currency: event.data.checkout.totalPrice.currencyCode,
line_items: lineItems
});
});
Pinterest Ads代码集成到Shopify Customer Events里
技术729
未经允许不得转载:迷你笔记 » Pinterest Ads代码集成到Shopify Customer Events里



