analytics.subscribe("product_added_to_cart", async (event) => {
capture('add_to_cart', {
price: event.data.cartLine.merchandise.price.amount,
product_title: event.data.cartLine.merchandise.product.title,
quantity: event.data.cartLine.quantity,
total_cost: event.data.cartLine.cost.totalAmount.amount,
});
});
analytics.subscribe("product_viewed", (event) => {
capture('product_viewed', {
url: event.context.document.location.href,
product_id: event.data.productVariant.product.id,
product_price: event.data.productVariant.price.amount,
product_currencyCode: event.data.productVariant.price.currencyCode,
product_title: event.data.productVariant.product.title,
product_variant: event.data.productVariant.title,
product_sku: event.data.productVariant.sku,
product_image: event.data.productVariant.image.src,
});
});
analytics.subscribe("checkout_started", (event) => {
capture('checkout_started', {
token: event.data.checkout.token,
url: event.context.document.location.href,
client_id: event.clientId,
email: event.data.checkout.email,
phone: event.data.checkout.phone,
first_name: event.data.checkout.shippingAddress.firstName,
last_name: event.data.checkout.shippingAddress.lastName,
address1: event.data.checkout.shippingAddress.address1,
address2: event.data.checkout.shippingAddress.address2,
city: event.data.checkout.shippingAddress.city,
country: event.data.checkout.shippingAddress.country,
countryCode: event.data.checkout.shippingAddress.countryCode,
province: event.data.checkout.shippingAddress.province,
provinceCode: event.data.checkout.shippingAddress.provinceCode,
zip: event.data.checkout.shippingAddress.zip,
orderId: event.data.checkout.order.id,
currency: event.data.checkout.currencyCode,
subtotal: event.data.checkout.subtotalPrice.amount,
shipping: event.data.checkout.shippingLine.price.amount,
value: event.data.checkout.totalPrice.amount,
tax: event.data.checkout.totalTax.amount,
items: event.data.checkout.lineItems,
});
});
analytics.subscribe("checkout_completed", (event) => {
identify(event.data.checkout.email, {
email: event.data.checkout.email,
name: event.data.checkout.shippingAddress.firstName,
phone: event.data.checkout.phone,
});
});
analytics.subscribe("checkout_completed", (event) => {
capture('purchase', {
token: event.data.checkout.token,
url: event.context.document.location.href,
client_id: event.clientId,
email: event.data.checkout.email,
phone: event.data.checkout.phone,
first_name: event.data.checkout.shippingAddress.firstName,
last_name: event.data.checkout.shippingAddress.lastName,
address1: event.data.checkout.shippingAddress.address1,
address2: event.data.checkout.shippingAddress.address2,
city: event.data.checkout.shippingAddress.city,
country: event.data.checkout.shippingAddress.country,
countryCode: event.data.checkout.shippingAddress.countryCode,
province: event.data.checkout.shippingAddress.province,
provinceCode: event.data.checkout.shippingAddress.provinceCode,
zip: event.data.checkout.shippingAddress.zip,
orderId: event.data.checkout.order.id,
currency: event.data.checkout.currencyCode,
subtotal: event.data.checkout.subtotalPrice.amount,
shipping: event.data.checkout.shippingLine.price.amount,
value: event.data.checkout.totalPrice.amount,
tax: event.data.checkout.totalTax.amount,
items: event.data.checkout.lineItems,
});
});