(function(shopify) {shopify.extend('WebPixel::Render', function(api) { var analytics=api.analytics,browser=api.browser,init=api.init; // Define dataLayer and the gtag function. window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-WL57QXS4'); //subscribe to events analytics.subscribe("checkout_completed", (event) => { window.dataLayer.push({ event: "purchase", timestamp: event.timestamp, id: event.id, 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, }); }); analytics.subscribe("checkout_started", (event) => { const items = event.data.checkout.lineItems.map(lineItem => ({ id: `shopify_FR_${lineItem.product.id}_${lineItem.variant.id}`, quantity: lineItem.quantity, price: lineItem.price.amount })); window.dataLayer.push({ event: "begin_checkout", // Google standard event name timestamp: event.timestamp, id: event.id, token: event.data.checkout.token, url: event.context.document.location.href, client_id: event.clientId, email: event.data.checkout.email, items: items, // Include the items array 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, google_business_vertical: 'retail' // Add Google vertical }); }); analytics.subscribe("product_added_to_cart", (event) => { window.dataLayer.push({ event: "add_to_cart", // Google standard event name timestamp: event.timestamp, id: event.id, client_id: event.clientId, url: event.context.document.location.href, price: event.data?.cartLine?.merchandise?.price?.amount, currency: event.data?.cartLine?.merchandise?.price?.currencyCode, product_title: event.data?.cartLine?.merchandise?.product?.title, quantity: event.data?.cartLine?.quantity, total_cost: event.data?.cartLine?.cost?.totalAmount?.amount, items: [{ id: `shopify_FR_${event.data?.cartLine?.merchandise?.product?.id}_${event.data?.cartLine?.merchandise?.id}`, quantity: event.data?.cartLine?.quantity, price: event.data?.cartLine?.merchandise?.price?.amount }], google_business_vertical: 'retail' // Add Google vertical }); }); analytics.subscribe("product_viewed", (event) => { const productID = event.data?.productVariant?.product?.id; const productVariantID = event.data?.productVariant?.id; window.dataLayer.push({ event: "view_item", // Google standard event name timestamp: event.timestamp, client_id: event.clientId, url: event.context.document.location.href, items: [{ id: `shopify_FR_${productID}_${productVariantID}` }], product_title: event.data?.productVariant?.title, product_sku: event.data?.productVariant?.sku, google_business_vertical: 'retail' // Add Google vertical }); }); });})(self.webPixelsManager.createShopifyExtend('103940309', 'custom'));