1. Creeaza un “Custom pixel” in Shopify > Settings > Customer events cu numele “NewsMAN Remarketing” si codul:
const nzmRemarketingId = "00000-0000-000000000000000000000000-00000000000000000000000000000000"; window.dataLayer = window.dataLayer || []; window._nzm = window._nzm || []; window._nzm_config = window._nzm_config || []; (function() { if (!_nzm.track) { var a,m; a=function(f) { return function() { _nzm.push([f].concat(Array.prototype.slice.call(arguments, 0))); } }; m=["identify","track","run"]; for(var i=0;i<m.length;i++) { _nzm[m[i]]=a(m[i]); } var s=document.getElementsByTagName("script")[0]; var d=document.createElement("script"); d.async=true; d.id="nzm-tracker"; d.setAttribute("data-site-id", nzmRemarketingId); d.src="https://retargeting.newsmanapp.com/js/retargeting/track.js"; s.parentNode.insertBefore(d, s); } })(); analytics.subscribe("nzm_identify", (event) => { _nzm.identify({ 'email': event.customData.email, 'first_name': event.customData.firstName, 'last_name': event.customData.lastName }) }); analytics.subscribe("product_viewed", (event) => { dataLayer.push({ ecommerce: null }); dataLayer.push({ event: "view_item", ecommerce: { currency: event.data?.productVariant?.product?.price?.currencyCode, value: event.data?.productVariant?.product?.price?.amount, items: [ { item_id: event.data?.productVariant?.product?.id, item_name: event.data?.productVariant?.product?.title, item_brand: event.data?.productVariant?.product?.vendor, item_variant: event.data?.productVariant?.title, price: event.data?.productVariant?.product?.price?.amount, quantity: 1 } ] } }); }); analytics.subscribe("product_added_to_cart", (event) => { dataLayer.push({ ecommerce: null }); dataLayer.push({ event: "add_to_cart", ecommerce: { currency: event.data?.cartLine?.cost?.totalAmount?.currencyCode, value: event.data?.cartLine?.cost?.totalAmount?.amount, items: [ { item_id: event.data?.cartLine?.merchandise?.product?.id, item_name: event.data?.cartLine?.merchandise?.product?.title, item_brand: event.data?.cartLine?.merchandise?.product?.vendor, item_variant: event.data?.cartLine?.merchandise?.title, price: event.data?.cartLine?.merchandise?.price?.amount, quantity: event.data?.cartLine?.quantity } ] } }); }); analytics.subscribe("product_removed_from_cart", (event) => { dataLayer.push({ ecommerce: null }); dataLayer.push({ event: "remove_from_cart", ecommerce: { currency: event.data?.cartLine?.cost?.totalAmount?.currencyCode, value: event.data?.cartLine?.cost?.totalAmount?.amount, items: [ { item_id: event.data?.cartLine?.merchandise?.product?.id, item_name: event.data?.cartLine?.merchandise?.product?.title, item_brand: event.data?.cartLine?.merchandise?.product?.vendor, item_variant: event.data?.cartLine?.merchandise?.title, price: event.data?.cartLine?.merchandise?.price?.amount, quantity: event.data?.cartLine?.quantity } ] } }); }); analytics.subscribe("checkout_completed", (event) => { dataLayer.push({ ecommerce: null }); const checkout = event.data?.checkout; const checkoutTotalPrice = checkout?.totalPrice?.amount; const checkoutTotalTax = checkout?.totalTax?.amount; const allDiscountCodes = checkout?.discountApplications?.map((discount) => { if (discount.type === 'DISCOUNT_CODE') { return discount.title; } }); const items = checkout?.lineItems?.map((item) => { let discountAmount = 0; item.discountAllocations.forEach((discount) => { if (discount.discountApplication.type == 'DISCOUNT_CODE') { discountAmount += discount.amount.amount; } }); const discountCodes = item.discountAllocations.map((discount) => { if (discount.discountApplication.type == 'DISCOUNT_CODE') { return discount.discountApplication.title; } }); return { item_id: item.variant.product.id, item_name: item.variant.product.title, coupon: discountAmount > 0 ? discountCodes.join() : undefined, discount: discountAmount > 0 ? discountAmount : undefined, item_variant: item.variant.title, price: item.variant.price.amount, quantity: item.quantity } }); dataLayer.push({ event: "purchase", ecommerce: { transaction_id: checkout?.order?.id, value: checkoutTotalPrice, tax: checkoutTotalTax, shipping: checkout?.shippingLine?.price?.amount, currency: checkout?.currencyCode, coupon: allDiscountCodes.length > 0 ? allDiscountCodes.join(',') : undefined, items: items } }); });
Inlocuieste “00000-0000-000000000000000000000000-00000000000000000000000000000000” cu NewsMAN Remarketing ID din contul tau NewsMAN.
2. Editeaza fisierul “theme.liquid” al temei active a magazinului Shopify si adauga, inainte de </body> codul:
{%- if customer -%} <script type="text/javascript"> if (sessionStorage.getItem('nzm_identified') !== '1') { sessionStorage.setItem('nzm_identified', '1'); const email = "{{ customer.email }}"; const firstName = "{{ customer.first_name }}"; const lastName = "{{ customer.last_name }}"; setTimeout(() => { Shopify.analytics.publish('nzm_identify', {email: email, firstName: firstName, lastName: lastName}); }, 100); } </script> {%- endif -%}
Poți descărca sursa codului aici.
Un plugin pentru product feeds Shopify: https://apps.shopify.com/multiple-google-shopping-feeds
OBS: Cand se genereaza feed-ul, campului ID trebuie asociat “product id”, nu “variant id” !!!