UNPKG

@ecomplus/widget-tiktok-pixel

Version:
2 lines 2.97 kB
var widgetTiktokPixel=function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="/assets/vendor/",n(n.s=2)}([function(t,e){t.exports=void 0},function(t,e){t.exports=void 0},function(t,e,n){"use strict";n.r(e);var o=n(1);const r=o.$ecomConfig.get("currency")||"BRL",a=t=>{const e={currency:r,content_id:t.sku,content_name:t.name,value:Object(o.price)(t),content_type:"product"};return t.categories&&t.categories.length&&(e.content_category=t.category_tree||t.categories[0].name),e};var c=n(0),i=n.n(c);e.default=()=>{if("object"==typeof window.ttq){const e=window.ttq;(t=>{const e=window.storefront&&window.storefront.context;e&&"products"===e.resource&&t.track("ViewContent",a(e.body))})(e),t=e,setTimeout(()=>{if(document.querySelectorAll("[data-sku]").length&&"/search"===window.location.pathname){const e=new URLSearchParams(document.location.search);t.track("Search",e.get("term"))}},300),((t,e)=>{const n=window.storefrontApp&&window.storefrontApp.router;if(n){let e,o,a;const c=t=>{const{amount:e}=t||window.storefrontApp,n={value:e&&e.total||i.a.data&&i.a.data.subtotal||0,currency:r,contents:[]};return i.a.data&&Array.isArray(i.a.data.items)&&i.a.data.items.forEach(({sku:t,quantity:e,name:o,price:r})=>{n.contents.push({content_id:t,content_name:o,price:r,content_type:"product",quantity:e})}),n},u=n=>{const r=c();!e||n<=1?(t.track("InitiateCheckout",r),e=!0):n<=2?t.track("CompleteRegistration"):o||(t.track("AddPaymentInfo"),o=!0)},s=(e,n)=>{if(!a){if(window.localStorage.getItem("ttq.orderIdSent")!==e){let o;if(n)try{o=JSON.parse(n)}catch(t){o=null}t.track("CompletePayment",{...c(o)}),window.localStorage.setItem("ttq.orderIdSent",e)}a=!0}};let d;const l=({name:t,params:e})=>{switch(t){case"cart":u(1);break;case"checkout":e.id||u(2),u(3);break;case"confirmation":clearTimeout(d),e.json?s(e.id,decodeURIComponent(e.json)):d=setTimeout(()=>{e.json?s(e.id,decodeURIComponent(e.json)):s(e.id)},e.json?1:1500)}};n.currentRoute&&l(n.currentRoute),n.afterEach(l)}})(e),(t=>{i.a.on("addItem",({item:e})=>{t.track("AddToCart",a(e))})})(e)}var t}}]).default; //# sourceMappingURL=widget-tiktok-pixel.var.min.js.map