From 2a8b4344238b0a5e72ad23a842c4068b5fdda619 Mon Sep 17 00:00:00 2001 From: rockwellll Date: Fri, 17 Apr 2026 09:53:56 +0300 Subject: [PATCH 1/4] specify source for tracked checkout --- dist/confirmation.js | 2 +- dist/funnel.js | 2 +- src/utils.js | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/dist/confirmation.js b/dist/confirmation.js index c8424e4..470dc12 100644 --- a/dist/confirmation.js +++ b/dist/confirmation.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hellotext=t():e.Hellotext=t()}(Object("undefined"!=typeof self?self:this),()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function r(e,t){for(var r=0;rZt});var i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"shouldShowSuccessMessage",get:function(){return this.successMessage}}],null&&r(t.prototype,null),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function o(e,t){for(var r=0;re.trim()):this._classes},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("classes must be an array or a string");this._classes=e}},{key:"triggerClasses",get:function(){return"string"==typeof this._triggerClasses?this._triggerClasses.split(",").map(e=>e.trim()):this._triggerClasses},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("triggerClasses must be an array or a string");this._triggerClasses=e}},{key:"id",get:function(){return this._id},set:function(e){this._id=e}},{key:"isSet",get:function(){return!!this._id}},{key:"style",get:function(){return this._style},set:function(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(e=>{var[t,r]=e;if(!["primaryColor","secondaryColor","typography"].includes(t))throw new Error("Invalid style property: ".concat(t));if("typography"!==t&&!this.isHexOrRgba(r))throw new Error("Invalid color value: ".concat(r," for ").concat(t,". Colors must be hex or rgb/a."))}),this._style=e}},{key:"behaviour",get:function(){return this._behaviour},set:function(e){if(!Object.values(m).includes(e))throw new Error("Invalid behaviour value: ".concat(e));this._behaviour=e}},{key:"strategy",get:function(){return this._strategy?this._strategy:"body"==this.container?b.FIXED:b.ABSOLUTE},set:function(e){if(e&&!Object.values(b).includes(e))throw new Error("Invalid strategy value: ".concat(e));this._strategy=e}},{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"isHexOrRgba",value:function(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}}],null&&v(t.prototype,null),r&&v(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function w(e,t){for(var r=0;r{var[t,r]=e;"forms"===t?this.forms=i.assign(r):"webchat"===t?this.webchat=g.assign(r):this[t]=r}),this}},{key:"locale",get:function(){return y.toString()},set:function(e){y.identifier=e}},{key:"endpoint",value:function(e){return"".concat(this.apiRoot,"/").concat(e)}}],null&&w(t.prototype,null),r&&w(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function j(e){var t="function"==typeof Map?new Map:void 0;return j=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return k(e,arguments,C(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),_(n,e)},j(e)}function k(e,t,r){return k=S()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&_(i,r.prototype),i},k.apply(null,arguments)}function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function _(e,t){return _=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},_(e,t)}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}P.apiRoot="https://api.hellotext.com/v1",P.actionCableUrl="wss://www.hellotext.com/cable",P.autoGenerateSession=!0,P.session=null,P.forms=i,P.webchat=g;var E=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_(e,t)}(o,e);var t,r,n,i=(r=o,n=S(),function(){var e,t=C(r);if(n){var i=C(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(t=i.call(this,"".concat(e," is not valid. Please provide a valid event name"))).name="InvalidEvent",t}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(j(Error));function T(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function L(e){for(var t=1;tt===e)}}],(r=[{key:"addSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers=L(L({},this.subscribers),{},{[t]:this.subscribers[t]?[...this.subscribers[t],r]:[r]})}},{key:"removeSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers[t]&&(this.subscribers[t]=this.subscribers[t].filter(e=>e!==r))}},{key:"dispatch",value:function(e,t){var r;null===(r=this.subscribers[e])||void 0===r||r.forEach(e=>{e(t)})}},{key:"listeners",get:function(){return 0!==Object.keys(this.subscribers).length}}])&&M(t.prototype,r),n&&M(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function I(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function R(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:{},t=yield fetch(this.endpoint,{method:"POST",headers:Ut.headers,body:JSON.stringify(le({session:Ut.session},e))});return new X(t.ok,t)},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){fe(o,r,i,a,u,"next",e)}function u(e){fe(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})}],null&&pe(t.prototype,null),r&&pe(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function he(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function de(e,t){for(var r=0;r{var[r,n]=e;t.searchParams.append("style[".concat(r,"]"),n)}),t.searchParams.append("placement",P.webchat.placement);var r=yield fetch(t,{method:"GET",headers:Ut.headers}),n=yield r.json();return Ut.business.data||(Ut.business.setData(n.business),Ut.business.setLocale(n.locale)),(new DOMParser).parseFromString(n.html,"text/html").querySelector("article")},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){he(o,r,i,a,u,"next",e)}function u(e){he(o,r,i,a,u,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})}],null&&de(t.prototype,null),r&&de(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();const ge=me;function we(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Oe(e,t){for(var r=0;r{var[t,r]=e;return r}));Be.set("hello_utm",JSON.stringify(n))}}var t,r;return t=e,(r=[{key:"current",get:function(){try{return JSON.parse(Be.get("hello_utm"))||{}}catch(e){return{}}}}])&&xe(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ae(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.utm=new De,this._url=t}var t,r,n;return t=e,n=[{key:"getRootDomain",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;try{if(!e){var t;if("undefined"==typeof window||null===(t=window.location)||void 0===t||!t.hostname)return null;e=window.location.hostname}var r=e.split(".");if(r.length<=1)return e;for(var n of["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"]){var i=n.split(".");if(r.slice(-i.length).join(".")===n&&r.length>i.length)return".".concat(r.slice(-(i.length+1)).join("."))}var o=r[r.length-1],a=r[r.length-2];return r.length>2&&2===o.length&&a.length<=3?".".concat(r.slice(-3).join(".")):".".concat(r.slice(-2).join("."))}catch(e){return null}}}],(r=[{key:"url",get:function(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}},{key:"title",get:function(){return document.title}},{key:"path",get:function(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}},{key:"utmParams",get:function(){return this.utm.current}},{key:"trackingData",get:function(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}},{key:"domain",get:function(){try{var t=this.url;if(!t)return null;var r=new URL(t).hostname;return e.getRootDomain(r)}catch(e){return null}}}])&&Ae(t.prototype,r),n&&Ae(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function qe(e,t){for(var r=0;r\n ".concat(Ut.business.locale.white_label.powered_by,'\n\n \n \n Hellotext\n \n \n \n \n ')}});var lt=0;function st(e){return"__private_"+lt+++"_"+e}var ft=st("findOrCreateComponent"),pt=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Object.defineProperty(this,ft,{value:yt}),this.data=t,this.element=r||document.querySelector('[data-hello-form="'.concat(this.id,'"]'))||document.createElement("form")}var t,r,n,i;return t=e,r=[{key:"mount",value:(n=function*(){var e,{ifCompleted:t=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t&&this.hasBeenCompleted)return null===(e=this.element)||void 0===e||e.remove(),Ut.eventEmitter.dispatch("form:completed",function(e){for(var t=1;t{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),Ut.business.features.white_label||this.element.prepend(rt.build())},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){ot(o,r,i,a,u,"next",e)}function u(e){ot(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"buildHeader",value:function(e){var t=ct(this,ft)[ft]("[data-form-header]","header");t.innerHTML=e.content,this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}},{key:"buildInputs",value:function(e){var t=ct(this,ft)[ft]("[data-form-inputs]","main");e.map(e=>Ye.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildButton",value:function(e){var t=ct(this,ft)[ft]("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildFooter",value:function(e){var t=ct(this,ft)[ft]("[data-form-footer]","footer");t.innerHTML=e.content,this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}},{key:"markAsCompleted",value:function(e){var t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem("hello-form-".concat(this.id),JSON.stringify(t)),Ut.eventEmitter.dispatch("form:completed",t)}},{key:"hasBeenCompleted",get:function(){return null!==localStorage.getItem("hello-form-".concat(this.id))}},{key:"id",get:function(){return this.data.id}},{key:"localeAuthKey",get:function(){var e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}},{key:"elementAttributes",get:function(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}}],r&&at(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function yt(e,t){var r=this.element.querySelector(e);if(r)return r.cloneNode(!0);var n=document.createElement(t);return n.setAttribute(e.replace("[","").replace("]",""),""),n}function vt(e){var t="function"==typeof Map?new Map:void 0;return vt=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return ht(e,arguments,mt(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),bt(n,e)},vt(e)}function ht(e,t,r){return ht=dt()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&bt(i,r.prototype),i},ht.apply(null,arguments)}function dt(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function bt(e,t){return bt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},bt(e,t)}function mt(e){return mt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},mt(e)}var gt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&bt(e,t)}(o,e);var t,r,n,i=(r=o,n=dt(),function(){var e,t=mt(r);if(n){var i=mt(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(e=i.call(this,"You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id")).name="NotInitializedError",e}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(vt(Error));function wt(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Ot(e,t){for(var r=0;r0&&this.collect()}},{key:"formMutationObserver",value:function(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}},{key:"collect",value:(n=function*(){if(Ut.notInitialized)throw new gt;if(!this.fetching){if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");var e=function(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}(this,St)[St];if(0!==e.length){var t=e.map(e=>ue.get(e).then(e=>e.json()));this.fetching=!0,yield Promise.all(t).then(e=>e.forEach(this.add)).then(()=>Ut.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),P.forms.autoMount&&this.forms.forEach(e=>e.mount())}}},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){wt(o,r,i,a,u,"next",e)}function u(e){wt(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"forEach",value:function(e){this.forms.forEach(e)}},{key:"map",value:function(e){return this.forms.map(e)}},{key:"add",value:function(e){this.includes(e.id)||(Ut.business.data||(Ut.business.setData(e.business),Ut.business.setLocale(y.toString())),Ut.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new pt(e)))}},{key:"getById",value:function(e){return this.forms.find(t=>t.id===e)}},{key:"getByIndex",value:function(e){return this.forms[e]}},{key:"includes",value:function(e){return this.forms.some(t=>t.id===e)}},{key:"excludes",value:function(e){return!this.includes(e)}},{key:"length",get:function(){return this.forms.length}}],r&&Ot(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ct(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}function Et(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Tt(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{};if(this.notInitialized)throw new gt;var r=Rt(Rt({},t&&t.headers||{}),this.headers),n=Rt(Rt({},At.identificationData),t.user_parameters||{}),i=t&&t.url?new Re(t.url):this.page,o=Rt(Rt({session:this.session,user_parameters:n,action:e},t),i.trackingData);return delete o.headers,yield _e.events.create({headers:r,body:o})}),function(e){return i.apply(this,arguments)})},{key:"identify",value:(n=Bt(function*(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(At.id===e)return new X(!0,{json:(t=Bt(function*(){}),function(){return t.apply(this,arguments)})});var n=yield _e.identifications.create(Rt({user_id:e},r));return n.succeeded&&At.remember(e,r.source),n}),function(e){return n.apply(this,arguments)})},{key:"forget",value:function(){At.forget()}},{key:"on",value:function(e,t){this.eventEmitter.addSubscriber(e,t)}},{key:"removeEventListener",value:function(e,t){this.eventEmitter.removeSubscriber(e,t)}},{key:"session",get:function(){return We.session}},{key:"isInitialized",get:function(){return void 0!==We.session}},{key:"notInitialized",get:function(){return!this.business||void 0===this.business.id}},{key:"headers",get:function(){if(this.notInitialized)throw new gt;return{Authorization:"Bearer ".concat(this.business.id),Accept:"application/json","Content-Type":"application/json"}}}],r&&Ft(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();zt.eventEmitter=new A,zt.forms=void 0,zt.business=void 0,zt.webchat=void 0;const Ut=zt,Zt={initialize:e=>{Ut.initialize(e),window.vtexjs?.checkout&&vtexjs.checkout.getOrderForm().done(e=>{const t=(e=>{const t=e?.clientProfileData||{};return{id:t.email,email:t.email,first_name:t.firstName,last_name:t.lastName,phone:t.phone,document:t.document,source:"vtex"}})(e),r=(e=>{const t=e.storePreferencesData||{},r=e.shippingData?.logisticsInfo||[],n=0===r.length?"deliver":(()=>{const e=["pickup","retir","collect","recolha","loja"];return r.some(t=>{const r=(t.selectedSla||"").toLowerCase();return"pickup-in-point"===(t.selectedDeliveryChannel||"").toLowerCase()||e.some(e=>r.includes(e))})?"collect":"deliver"})(),i=(e.items||[]).map(e=>({quantity:e.quantity,price:{amount:(e.sellingPrice||0)+(e.tax||0),currency:t.currencyCode},product:{reference:e.id,categories:Object.values(e.productCategories||{}),name:e.skuName,image_url:e.imageUrl,sku:e.id,source:"vtex",price:{amount:e.price||0,currency:t.currencyCode},brand:e.additionalInfo?.brandName,product:{reference:e.productId,name:e.name,source:"vtex",categories:Object.values(e.productCategories||{}),brand:e.additionalInfo?.brandName}}}));return{reference:e.orderGroup||e.orderFormId,amount:e.value||0,currency:t.currencyCode,delivery:n,items:i}})(e);(t.email||t.phone)&&(Ut.identify(t.email||t.phone,t),Ut.track("order.placed",{user_parameters:t,object_parameters:r}))})}};return t.default})()); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hellotext=t():e.Hellotext=t()}(Object("undefined"!=typeof self?self:this),()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function r(e,t){for(var r=0;rZt});var i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"shouldShowSuccessMessage",get:function(){return this.successMessage}}],null&&r(t.prototype,null),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function o(e,t){for(var r=0;re.trim()):this._classes},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("classes must be an array or a string");this._classes=e}},{key:"triggerClasses",get:function(){return"string"==typeof this._triggerClasses?this._triggerClasses.split(",").map(e=>e.trim()):this._triggerClasses},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("triggerClasses must be an array or a string");this._triggerClasses=e}},{key:"id",get:function(){return this._id},set:function(e){this._id=e}},{key:"isSet",get:function(){return!!this._id}},{key:"style",get:function(){return this._style},set:function(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(e=>{var[t,r]=e;if(!["primaryColor","secondaryColor","typography"].includes(t))throw new Error("Invalid style property: ".concat(t));if("typography"!==t&&!this.isHexOrRgba(r))throw new Error("Invalid color value: ".concat(r," for ").concat(t,". Colors must be hex or rgb/a."))}),this._style=e}},{key:"behaviour",get:function(){return this._behaviour},set:function(e){if(!Object.values(m).includes(e))throw new Error("Invalid behaviour value: ".concat(e));this._behaviour=e}},{key:"strategy",get:function(){return this._strategy?this._strategy:"body"==this.container?b.FIXED:b.ABSOLUTE},set:function(e){if(e&&!Object.values(b).includes(e))throw new Error("Invalid strategy value: ".concat(e));this._strategy=e}},{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"isHexOrRgba",value:function(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}}],null&&v(t.prototype,null),r&&v(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function w(e,t){for(var r=0;r{var[t,r]=e;"forms"===t?this.forms=i.assign(r):"webchat"===t?this.webchat=g.assign(r):this[t]=r}),this}},{key:"locale",get:function(){return y.toString()},set:function(e){y.identifier=e}},{key:"endpoint",value:function(e){return"".concat(this.apiRoot,"/").concat(e)}}],null&&w(t.prototype,null),r&&w(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function j(e){var t="function"==typeof Map?new Map:void 0;return j=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return k(e,arguments,C(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),_(n,e)},j(e)}function k(e,t,r){return k=S()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&_(i,r.prototype),i},k.apply(null,arguments)}function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function _(e,t){return _=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},_(e,t)}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}P.apiRoot="https://api.hellotext.com/v1",P.actionCableUrl="wss://www.hellotext.com/cable",P.autoGenerateSession=!0,P.session=null,P.forms=i,P.webchat=g;var E=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_(e,t)}(o,e);var t,r,n,i=(r=o,n=S(),function(){var e,t=C(r);if(n){var i=C(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(t=i.call(this,"".concat(e," is not valid. Please provide a valid event name"))).name="InvalidEvent",t}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(j(Error));function T(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function L(e){for(var t=1;tt===e)}}],(r=[{key:"addSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers=L(L({},this.subscribers),{},{[t]:this.subscribers[t]?[...this.subscribers[t],r]:[r]})}},{key:"removeSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers[t]&&(this.subscribers[t]=this.subscribers[t].filter(e=>e!==r))}},{key:"dispatch",value:function(e,t){var r;null===(r=this.subscribers[e])||void 0===r||r.forEach(e=>{e(t)})}},{key:"listeners",get:function(){return 0!==Object.keys(this.subscribers).length}}])&&M(t.prototype,r),n&&M(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function I(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function R(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:{},t=yield fetch(this.endpoint,{method:"POST",headers:Ut.headers,body:JSON.stringify(le({session:Ut.session},e))});return new X(t.ok,t)},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){fe(o,r,i,a,u,"next",e)}function u(e){fe(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})}],null&&pe(t.prototype,null),r&&pe(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function he(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function de(e,t){for(var r=0;r{var[r,n]=e;t.searchParams.append("style[".concat(r,"]"),n)}),t.searchParams.append("placement",P.webchat.placement);var r=yield fetch(t,{method:"GET",headers:Ut.headers}),n=yield r.json();return Ut.business.data||(Ut.business.setData(n.business),Ut.business.setLocale(n.locale)),(new DOMParser).parseFromString(n.html,"text/html").querySelector("article")},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){he(o,r,i,a,u,"next",e)}function u(e){he(o,r,i,a,u,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})}],null&&de(t.prototype,null),r&&de(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();const ge=me;function we(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Oe(e,t){for(var r=0;r{var[t,r]=e;return r}));Be.set("hello_utm",JSON.stringify(n))}}var t,r;return t=e,(r=[{key:"current",get:function(){try{return JSON.parse(Be.get("hello_utm"))||{}}catch(e){return{}}}}])&&xe(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ae(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.utm=new De,this._url=t}var t,r,n;return t=e,n=[{key:"getRootDomain",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;try{if(!e){var t;if("undefined"==typeof window||null===(t=window.location)||void 0===t||!t.hostname)return null;e=window.location.hostname}var r=e.split(".");if(r.length<=1)return e;for(var n of["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"]){var i=n.split(".");if(r.slice(-i.length).join(".")===n&&r.length>i.length)return".".concat(r.slice(-(i.length+1)).join("."))}var o=r[r.length-1],a=r[r.length-2];return r.length>2&&2===o.length&&a.length<=3?".".concat(r.slice(-3).join(".")):".".concat(r.slice(-2).join("."))}catch(e){return null}}}],(r=[{key:"url",get:function(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}},{key:"title",get:function(){return document.title}},{key:"path",get:function(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}},{key:"utmParams",get:function(){return this.utm.current}},{key:"trackingData",get:function(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}},{key:"domain",get:function(){try{var t=this.url;if(!t)return null;var r=new URL(t).hostname;return e.getRootDomain(r)}catch(e){return null}}}])&&Ae(t.prototype,r),n&&Ae(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function qe(e,t){for(var r=0;r\n ".concat(Ut.business.locale.white_label.powered_by,'\n\n \n \n Hellotext\n \n \n \n \n ')}});var lt=0;function st(e){return"__private_"+lt+++"_"+e}var ft=st("findOrCreateComponent"),pt=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Object.defineProperty(this,ft,{value:yt}),this.data=t,this.element=r||document.querySelector('[data-hello-form="'.concat(this.id,'"]'))||document.createElement("form")}var t,r,n,i;return t=e,r=[{key:"mount",value:(n=function*(){var e,{ifCompleted:t=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t&&this.hasBeenCompleted)return null===(e=this.element)||void 0===e||e.remove(),Ut.eventEmitter.dispatch("form:completed",function(e){for(var t=1;t{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),Ut.business.features.white_label||this.element.prepend(rt.build())},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){ot(o,r,i,a,u,"next",e)}function u(e){ot(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"buildHeader",value:function(e){var t=ct(this,ft)[ft]("[data-form-header]","header");t.innerHTML=e.content,this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}},{key:"buildInputs",value:function(e){var t=ct(this,ft)[ft]("[data-form-inputs]","main");e.map(e=>Ye.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildButton",value:function(e){var t=ct(this,ft)[ft]("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildFooter",value:function(e){var t=ct(this,ft)[ft]("[data-form-footer]","footer");t.innerHTML=e.content,this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}},{key:"markAsCompleted",value:function(e){var t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem("hello-form-".concat(this.id),JSON.stringify(t)),Ut.eventEmitter.dispatch("form:completed",t)}},{key:"hasBeenCompleted",get:function(){return null!==localStorage.getItem("hello-form-".concat(this.id))}},{key:"id",get:function(){return this.data.id}},{key:"localeAuthKey",get:function(){var e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}},{key:"elementAttributes",get:function(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}}],r&&at(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function yt(e,t){var r=this.element.querySelector(e);if(r)return r.cloneNode(!0);var n=document.createElement(t);return n.setAttribute(e.replace("[","").replace("]",""),""),n}function vt(e){var t="function"==typeof Map?new Map:void 0;return vt=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return ht(e,arguments,mt(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),bt(n,e)},vt(e)}function ht(e,t,r){return ht=dt()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&bt(i,r.prototype),i},ht.apply(null,arguments)}function dt(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function bt(e,t){return bt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},bt(e,t)}function mt(e){return mt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},mt(e)}var gt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&bt(e,t)}(o,e);var t,r,n,i=(r=o,n=dt(),function(){var e,t=mt(r);if(n){var i=mt(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(e=i.call(this,"You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id")).name="NotInitializedError",e}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(vt(Error));function wt(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Ot(e,t){for(var r=0;r0&&this.collect()}},{key:"formMutationObserver",value:function(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}},{key:"collect",value:(n=function*(){if(Ut.notInitialized)throw new gt;if(!this.fetching){if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");var e=function(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}(this,St)[St];if(0!==e.length){var t=e.map(e=>ue.get(e).then(e=>e.json()));this.fetching=!0,yield Promise.all(t).then(e=>e.forEach(this.add)).then(()=>Ut.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),P.forms.autoMount&&this.forms.forEach(e=>e.mount())}}},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){wt(o,r,i,a,u,"next",e)}function u(e){wt(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"forEach",value:function(e){this.forms.forEach(e)}},{key:"map",value:function(e){return this.forms.map(e)}},{key:"add",value:function(e){this.includes(e.id)||(Ut.business.data||(Ut.business.setData(e.business),Ut.business.setLocale(y.toString())),Ut.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new pt(e)))}},{key:"getById",value:function(e){return this.forms.find(t=>t.id===e)}},{key:"getByIndex",value:function(e){return this.forms[e]}},{key:"includes",value:function(e){return this.forms.some(t=>t.id===e)}},{key:"excludes",value:function(e){return!this.includes(e)}},{key:"length",get:function(){return this.forms.length}}],r&&Ot(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ct(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}function Et(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Tt(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{};if(this.notInitialized)throw new gt;var r=Rt(Rt({},t&&t.headers||{}),this.headers),n=Rt(Rt({},At.identificationData),t.user_parameters||{}),i=t&&t.url?new Re(t.url):this.page,o=Rt(Rt({session:this.session,user_parameters:n,action:e},t),i.trackingData);return delete o.headers,yield _e.events.create({headers:r,body:o})}),function(e){return i.apply(this,arguments)})},{key:"identify",value:(n=Bt(function*(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(At.id===e)return new X(!0,{json:(t=Bt(function*(){}),function(){return t.apply(this,arguments)})});var n=yield _e.identifications.create(Rt({user_id:e},r));return n.succeeded&&At.remember(e,r.source),n}),function(e){return n.apply(this,arguments)})},{key:"forget",value:function(){At.forget()}},{key:"on",value:function(e,t){this.eventEmitter.addSubscriber(e,t)}},{key:"removeEventListener",value:function(e,t){this.eventEmitter.removeSubscriber(e,t)}},{key:"session",get:function(){return We.session}},{key:"isInitialized",get:function(){return void 0!==We.session}},{key:"notInitialized",get:function(){return!this.business||void 0===this.business.id}},{key:"headers",get:function(){if(this.notInitialized)throw new gt;return{Authorization:"Bearer ".concat(this.business.id),Accept:"application/json","Content-Type":"application/json"}}}],r&&Ft(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();zt.eventEmitter=new A,zt.forms=void 0,zt.business=void 0,zt.webchat=void 0;const Ut=zt,Zt={initialize:e=>{Ut.initialize(e),window.vtexjs?.checkout&&vtexjs.checkout.getOrderForm().done(e=>{const t=(e=>{const t=e?.clientProfileData||{};return{id:t.email,email:t.email,first_name:t.firstName,last_name:t.lastName,phone:t.phone,document:t.document,source:"vtex"}})(e),r=(e=>{const t=e.storePreferencesData||{},r=e.shippingData?.logisticsInfo||[],n=0===r.length?"deliver":(()=>{const e=["pickup","retir","collect","recolha","loja"];return r.some(t=>{const r=(t.selectedSla||"").toLowerCase();return"pickup-in-point"===(t.selectedDeliveryChannel||"").toLowerCase()||e.some(e=>r.includes(e))})?"collect":"deliver"})(),i=(e.items||[]).map(e=>({quantity:e.quantity,price:{amount:(e.sellingPrice||0)+(e.tax||0),currency:t.currencyCode},product:{reference:e.id,categories:Object.values(e.productCategories||{}),name:e.skuName,image_url:e.imageUrl,sku:e.id,source:"vtex",price:{amount:e.price||0,currency:t.currencyCode},brand:e.additionalInfo?.brandName,product:{reference:e.productId,name:e.name,source:"vtex",categories:Object.values(e.productCategories||{}),brand:e.additionalInfo?.brandName}}}));return{reference:e.orderGroup||e.orderFormId,source:"vtex",delivery:n,items:i}})(e);(t.email||t.phone)&&(Ut.identify(t.email||t.phone,t),Ut.track("order.placed",{user_parameters:t,object_parameters:r}))})}};return t.default})()); \ No newline at end of file diff --git a/dist/funnel.js b/dist/funnel.js index 4d186a9..7afc4aa 100644 --- a/dist/funnel.js +++ b/dist/funnel.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hellotext=t():e.Hellotext=t()}(Object("undefined"!=typeof self?self:this),()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function r(e,t){for(var r=0;r$t});var i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"shouldShowSuccessMessage",get:function(){return this.successMessage}}],null&&r(t.prototype,null),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function o(e,t){for(var r=0;re.trim()):this._classes},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("classes must be an array or a string");this._classes=e}},{key:"triggerClasses",get:function(){return"string"==typeof this._triggerClasses?this._triggerClasses.split(",").map(e=>e.trim()):this._triggerClasses},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("triggerClasses must be an array or a string");this._triggerClasses=e}},{key:"id",get:function(){return this._id},set:function(e){this._id=e}},{key:"isSet",get:function(){return!!this._id}},{key:"style",get:function(){return this._style},set:function(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(e=>{var[t,r]=e;if(!["primaryColor","secondaryColor","typography"].includes(t))throw new Error("Invalid style property: ".concat(t));if("typography"!==t&&!this.isHexOrRgba(r))throw new Error("Invalid color value: ".concat(r," for ").concat(t,". Colors must be hex or rgb/a."))}),this._style=e}},{key:"behaviour",get:function(){return this._behaviour},set:function(e){if(!Object.values(m).includes(e))throw new Error("Invalid behaviour value: ".concat(e));this._behaviour=e}},{key:"strategy",get:function(){return this._strategy?this._strategy:"body"==this.container?b.FIXED:b.ABSOLUTE},set:function(e){if(e&&!Object.values(b).includes(e))throw new Error("Invalid strategy value: ".concat(e));this._strategy=e}},{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"isHexOrRgba",value:function(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}}],null&&v(t.prototype,null),r&&v(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function w(e,t){for(var r=0;r{var[t,r]=e;"forms"===t?this.forms=i.assign(r):"webchat"===t?this.webchat=g.assign(r):this[t]=r}),this}},{key:"locale",get:function(){return y.toString()},set:function(e){y.identifier=e}},{key:"endpoint",value:function(e){return"".concat(this.apiRoot,"/").concat(e)}}],null&&w(t.prototype,null),r&&w(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function j(e){var t="function"==typeof Map?new Map:void 0;return j=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return k(e,arguments,C(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),_(n,e)},j(e)}function k(e,t,r){return k=S()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&_(i,r.prototype),i},k.apply(null,arguments)}function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function _(e,t){return _=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},_(e,t)}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}P.apiRoot="https://api.hellotext.com/v1",P.actionCableUrl="wss://www.hellotext.com/cable",P.autoGenerateSession=!0,P.session=null,P.forms=i,P.webchat=g;var E=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_(e,t)}(o,e);var t,r,n,i=(r=o,n=S(),function(){var e,t=C(r);if(n){var i=C(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(t=i.call(this,"".concat(e," is not valid. Please provide a valid event name"))).name="InvalidEvent",t}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(j(Error));function T(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function x(e){for(var t=1;tt===e)}}],(r=[{key:"addSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers=x(x({},this.subscribers),{},{[t]:this.subscribers[t]?[...this.subscribers[t],r]:[r]})}},{key:"removeSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers[t]&&(this.subscribers[t]=this.subscribers[t].filter(e=>e!==r))}},{key:"dispatch",value:function(e,t){var r;null===(r=this.subscribers[e])||void 0===r||r.forEach(e=>{e(t)})}},{key:"listeners",get:function(){return 0!==Object.keys(this.subscribers).length}}])&&M(t.prototype,r),n&&M(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function I(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function R(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:{},t=yield fetch(this.endpoint,{method:"POST",headers:Zt.headers,body:JSON.stringify(se({session:Zt.session},e))});return new X(t.ok,t)},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){pe(o,r,i,a,u,"next",e)}function u(e){pe(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})}],null&&ye(t.prototype,null),r&&ye(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function he(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function be(e,t){for(var r=0;r{var[r,n]=e;t.searchParams.append("style[".concat(r,"]"),n)}),t.searchParams.append("placement",P.webchat.placement);var r=yield fetch(t,{method:"GET",headers:Zt.headers}),n=yield r.json();return Zt.business.data||(Zt.business.setData(n.business),Zt.business.setLocale(n.locale)),(new DOMParser).parseFromString(n.html,"text/html").querySelector("article")},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){he(o,r,i,a,u,"next",e)}function u(e){he(o,r,i,a,u,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})}],null&&be(t.prototype,null),r&&be(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();const we=ge;function Oe(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Pe(e,t){for(var r=0;r{var[t,r]=e;return r}));Be.set("hello_utm",JSON.stringify(n))}}var t,r;return t=e,(r=[{key:"current",get:function(){try{return JSON.parse(Be.get("hello_utm"))||{}}catch(e){return{}}}}])&&Me(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ie(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.utm=new Ae,this._url=t}var t,r,n;return t=e,n=[{key:"getRootDomain",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;try{if(!e){var t;if("undefined"==typeof window||null===(t=window.location)||void 0===t||!t.hostname)return null;e=window.location.hostname}var r=e.split(".");if(r.length<=1)return e;for(var n of["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"]){var i=n.split(".");if(r.slice(-i.length).join(".")===n&&r.length>i.length)return".".concat(r.slice(-(i.length+1)).join("."))}var o=r[r.length-1],a=r[r.length-2];return r.length>2&&2===o.length&&a.length<=3?".".concat(r.slice(-3).join(".")):".".concat(r.slice(-2).join("."))}catch(e){return null}}}],(r=[{key:"url",get:function(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}},{key:"title",get:function(){return document.title}},{key:"path",get:function(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}},{key:"utmParams",get:function(){return this.utm.current}},{key:"trackingData",get:function(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}},{key:"domain",get:function(){try{var t=this.url;if(!t)return null;var r=new URL(t).hostname;return e.getRootDomain(r)}catch(e){return null}}}])&&Ie(t.prototype,r),n&&Ie(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function He(e,t){for(var r=0;r\n ".concat(Zt.business.locale.white_label.powered_by,'\n\n \n \n Hellotext\n \n \n \n \n ')}});var st=0;function ft(e){return"__private_"+st+++"_"+e}var pt=ft("findOrCreateComponent"),yt=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Object.defineProperty(this,pt,{value:vt}),this.data=t,this.element=r||document.querySelector('[data-hello-form="'.concat(this.id,'"]'))||document.createElement("form")}var t,r,n,i;return t=e,r=[{key:"mount",value:(n=function*(){var e,{ifCompleted:t=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t&&this.hasBeenCompleted)return null===(e=this.element)||void 0===e||e.remove(),Zt.eventEmitter.dispatch("form:completed",function(e){for(var t=1;t{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),Zt.business.features.white_label||this.element.prepend(nt.build())},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){at(o,r,i,a,u,"next",e)}function u(e){at(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"buildHeader",value:function(e){var t=lt(this,pt)[pt]("[data-form-header]","header");t.innerHTML=e.content,this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}},{key:"buildInputs",value:function(e){var t=lt(this,pt)[pt]("[data-form-inputs]","main");e.map(e=>Ye.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildButton",value:function(e){var t=lt(this,pt)[pt]("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildFooter",value:function(e){var t=lt(this,pt)[pt]("[data-form-footer]","footer");t.innerHTML=e.content,this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}},{key:"markAsCompleted",value:function(e){var t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem("hello-form-".concat(this.id),JSON.stringify(t)),Zt.eventEmitter.dispatch("form:completed",t)}},{key:"hasBeenCompleted",get:function(){return null!==localStorage.getItem("hello-form-".concat(this.id))}},{key:"id",get:function(){return this.data.id}},{key:"localeAuthKey",get:function(){var e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}},{key:"elementAttributes",get:function(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}}],r&&ut(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function vt(e,t){var r=this.element.querySelector(e);if(r)return r.cloneNode(!0);var n=document.createElement(t);return n.setAttribute(e.replace("[","").replace("]",""),""),n}function dt(e){var t="function"==typeof Map?new Map:void 0;return dt=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return ht(e,arguments,gt(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),mt(n,e)},dt(e)}function ht(e,t,r){return ht=bt()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&mt(i,r.prototype),i},ht.apply(null,arguments)}function bt(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function mt(e,t){return mt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},mt(e,t)}function gt(e){return gt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},gt(e)}var wt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&mt(e,t)}(o,e);var t,r,n,i=(r=o,n=bt(),function(){var e,t=gt(r);if(n){var i=gt(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(e=i.call(this,"You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id")).name="NotInitializedError",e}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(dt(Error));function Ot(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Pt(e,t){for(var r=0;r0&&this.collect()}},{key:"formMutationObserver",value:function(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}},{key:"collect",value:(n=function*(){if(Zt.notInitialized)throw new wt;if(!this.fetching){if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");var e=function(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}(this,_t)[_t];if(0!==e.length){var t=e.map(e=>ce.get(e).then(e=>e.json()));this.fetching=!0,yield Promise.all(t).then(e=>e.forEach(this.add)).then(()=>Zt.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),P.forms.autoMount&&this.forms.forEach(e=>e.mount())}}},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){Ot(o,r,i,a,u,"next",e)}function u(e){Ot(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"forEach",value:function(e){this.forms.forEach(e)}},{key:"map",value:function(e){return this.forms.map(e)}},{key:"add",value:function(e){this.includes(e.id)||(Zt.business.data||(Zt.business.setData(e.business),Zt.business.setLocale(y.toString())),Zt.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new yt(e)))}},{key:"getById",value:function(e){return this.forms.find(t=>t.id===e)}},{key:"getByIndex",value:function(e){return this.forms[e]}},{key:"includes",value:function(e){return this.forms.some(t=>t.id===e)}},{key:"excludes",value:function(e){return!this.includes(e)}},{key:"length",get:function(){return this.forms.length}}],r&&Pt(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Et(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}function Tt(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function xt(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{};if(this.notInitialized)throw new wt;var r=qt(qt({},t&&t.headers||{}),this.headers),n=qt(qt({},It.identificationData),t.user_parameters||{}),i=t&&t.url?new qe(t.url):this.page,o=qt(qt({session:this.session,user_parameters:n,action:e},t),i.trackingData);return delete o.headers,yield Ce.events.create({headers:r,body:o})}),function(e){return i.apply(this,arguments)})},{key:"identify",value:(n=Bt(function*(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(It.id===e)return new X(!0,{json:(t=Bt(function*(){}),function(){return t.apply(this,arguments)})});var n=yield Ce.identifications.create(qt({user_id:e},r));return n.succeeded&&It.remember(e,r.source),n}),function(e){return n.apply(this,arguments)})},{key:"forget",value:function(){It.forget()}},{key:"on",value:function(e,t){this.eventEmitter.addSubscriber(e,t)}},{key:"removeEventListener",value:function(e,t){this.eventEmitter.removeSubscriber(e,t)}},{key:"session",get:function(){return $e.session}},{key:"isInitialized",get:function(){return void 0!==$e.session}},{key:"notInitialized",get:function(){return!this.business||void 0===this.business.id}},{key:"headers",get:function(){if(this.notInitialized)throw new wt;return{Authorization:"Bearer ".concat(this.business.id),Accept:"application/json","Content-Type":"application/json"}}}],r&&Nt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();Ut.eventEmitter=new A,Ut.forms=void 0,Ut.business=void 0,Ut.webchat=void 0;const Zt=Ut,Jt=e=>{const t=e.storePreferencesData||{},r=e.shippingData?.logisticsInfo||[],n=0===r.length?"deliver":(()=>{const e=["pickup","retir","collect","recolha","loja"];return r.some(t=>{const r=(t.selectedSla||"").toLowerCase();return"pickup-in-point"===(t.selectedDeliveryChannel||"").toLowerCase()||e.some(e=>r.includes(e))})?"collect":"deliver"})(),i=(e.items||[]).map(e=>({quantity:e.quantity,price:{amount:(e.sellingPrice||0)+(e.tax||0),currency:t.currencyCode},product:{reference:e.id,categories:Object.values(e.productCategories||{}),name:e.skuName,image_url:e.imageUrl,sku:e.id,source:"vtex",price:{amount:e.price||0,currency:t.currencyCode},brand:e.additionalInfo?.brandName,product:{reference:e.productId,name:e.name,source:"vtex",categories:Object.values(e.productCategories||{}),brand:e.additionalInfo?.brandName}}}));return{reference:e.orderGroup||e.orderFormId,amount:e.value||0,currency:t.currencyCode,delivery:n,items:i}},Gt=new Set,Wt=e=>`hellotext:vtex-checkout-started:${e}`,$t={initialize:e=>{Zt.initialize(e);const t=e=>{const t=(e=>{const t=e?.clientProfileData||{};return{id:t.email,email:t.email,first_name:t.firstName,last_name:t.lastName,phone:t.phone,document:t.document,source:"vtex"}})(e);(t.email||t.phone)&&Zt.identify(t.email||t.phone,t),async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=e?.orderFormId;if(!r||Gt.has(r)||(e=>{if(!e)return!1;try{return"1"===window.sessionStorage.getItem(Wt(e))}catch(e){return!1}})(r))return;const n={object_parameters:Jt(e),user_parameters:t};Gt.add(r);try{const e=await Zt.track("checkout.started",n);e?.succeeded&&(e=>{if(e)try{window.sessionStorage.setItem(Wt(e),"1")}catch(e){}})(r)}catch(e){}finally{Gt.delete(r)}}(e,t)};$(window).on("orderFormUpdated.vtex",(e,r)=>{t(r)}),window.vtexjs?.checkout&&vtexjs.checkout.getOrderForm().done(t)}};return t.default})()); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hellotext=t():e.Hellotext=t()}(Object("undefined"!=typeof self?self:this),()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function r(e,t){for(var r=0;r$t});var i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"shouldShowSuccessMessage",get:function(){return this.successMessage}}],null&&r(t.prototype,null),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function o(e,t){for(var r=0;re.trim()):this._classes},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("classes must be an array or a string");this._classes=e}},{key:"triggerClasses",get:function(){return"string"==typeof this._triggerClasses?this._triggerClasses.split(",").map(e=>e.trim()):this._triggerClasses},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("triggerClasses must be an array or a string");this._triggerClasses=e}},{key:"id",get:function(){return this._id},set:function(e){this._id=e}},{key:"isSet",get:function(){return!!this._id}},{key:"style",get:function(){return this._style},set:function(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(e=>{var[t,r]=e;if(!["primaryColor","secondaryColor","typography"].includes(t))throw new Error("Invalid style property: ".concat(t));if("typography"!==t&&!this.isHexOrRgba(r))throw new Error("Invalid color value: ".concat(r," for ").concat(t,". Colors must be hex or rgb/a."))}),this._style=e}},{key:"behaviour",get:function(){return this._behaviour},set:function(e){if(!Object.values(m).includes(e))throw new Error("Invalid behaviour value: ".concat(e));this._behaviour=e}},{key:"strategy",get:function(){return this._strategy?this._strategy:"body"==this.container?b.FIXED:b.ABSOLUTE},set:function(e){if(e&&!Object.values(b).includes(e))throw new Error("Invalid strategy value: ".concat(e));this._strategy=e}},{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"isHexOrRgba",value:function(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}}],null&&v(t.prototype,null),r&&v(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function w(e,t){for(var r=0;r{var[t,r]=e;"forms"===t?this.forms=i.assign(r):"webchat"===t?this.webchat=g.assign(r):this[t]=r}),this}},{key:"locale",get:function(){return y.toString()},set:function(e){y.identifier=e}},{key:"endpoint",value:function(e){return"".concat(this.apiRoot,"/").concat(e)}}],null&&w(t.prototype,null),r&&w(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function j(e){var t="function"==typeof Map?new Map:void 0;return j=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return k(e,arguments,C(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),_(n,e)},j(e)}function k(e,t,r){return k=S()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&_(i,r.prototype),i},k.apply(null,arguments)}function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function _(e,t){return _=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},_(e,t)}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}P.apiRoot="https://api.hellotext.com/v1",P.actionCableUrl="wss://www.hellotext.com/cable",P.autoGenerateSession=!0,P.session=null,P.forms=i,P.webchat=g;var E=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_(e,t)}(o,e);var t,r,n,i=(r=o,n=S(),function(){var e,t=C(r);if(n){var i=C(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(t=i.call(this,"".concat(e," is not valid. Please provide a valid event name"))).name="InvalidEvent",t}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(j(Error));function T(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function x(e){for(var t=1;tt===e)}}],(r=[{key:"addSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers=x(x({},this.subscribers),{},{[t]:this.subscribers[t]?[...this.subscribers[t],r]:[r]})}},{key:"removeSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers[t]&&(this.subscribers[t]=this.subscribers[t].filter(e=>e!==r))}},{key:"dispatch",value:function(e,t){var r;null===(r=this.subscribers[e])||void 0===r||r.forEach(e=>{e(t)})}},{key:"listeners",get:function(){return 0!==Object.keys(this.subscribers).length}}])&&M(t.prototype,r),n&&M(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function I(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function R(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:{},t=yield fetch(this.endpoint,{method:"POST",headers:Zt.headers,body:JSON.stringify(se({session:Zt.session},e))});return new X(t.ok,t)},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){pe(o,r,i,a,u,"next",e)}function u(e){pe(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})}],null&&ye(t.prototype,null),r&&ye(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function he(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function be(e,t){for(var r=0;r{var[r,n]=e;t.searchParams.append("style[".concat(r,"]"),n)}),t.searchParams.append("placement",P.webchat.placement);var r=yield fetch(t,{method:"GET",headers:Zt.headers}),n=yield r.json();return Zt.business.data||(Zt.business.setData(n.business),Zt.business.setLocale(n.locale)),(new DOMParser).parseFromString(n.html,"text/html").querySelector("article")},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){he(o,r,i,a,u,"next",e)}function u(e){he(o,r,i,a,u,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})}],null&&be(t.prototype,null),r&&be(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();const we=ge;function Oe(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Pe(e,t){for(var r=0;r{var[t,r]=e;return r}));Be.set("hello_utm",JSON.stringify(n))}}var t,r;return t=e,(r=[{key:"current",get:function(){try{return JSON.parse(Be.get("hello_utm"))||{}}catch(e){return{}}}}])&&Me(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ie(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.utm=new Ae,this._url=t}var t,r,n;return t=e,n=[{key:"getRootDomain",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;try{if(!e){var t;if("undefined"==typeof window||null===(t=window.location)||void 0===t||!t.hostname)return null;e=window.location.hostname}var r=e.split(".");if(r.length<=1)return e;for(var n of["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"]){var i=n.split(".");if(r.slice(-i.length).join(".")===n&&r.length>i.length)return".".concat(r.slice(-(i.length+1)).join("."))}var o=r[r.length-1],a=r[r.length-2];return r.length>2&&2===o.length&&a.length<=3?".".concat(r.slice(-3).join(".")):".".concat(r.slice(-2).join("."))}catch(e){return null}}}],(r=[{key:"url",get:function(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}},{key:"title",get:function(){return document.title}},{key:"path",get:function(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}},{key:"utmParams",get:function(){return this.utm.current}},{key:"trackingData",get:function(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}},{key:"domain",get:function(){try{var t=this.url;if(!t)return null;var r=new URL(t).hostname;return e.getRootDomain(r)}catch(e){return null}}}])&&Ie(t.prototype,r),n&&Ie(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function He(e,t){for(var r=0;r\n ".concat(Zt.business.locale.white_label.powered_by,'\n\n \n \n Hellotext\n \n \n \n \n ')}});var st=0;function ft(e){return"__private_"+st+++"_"+e}var pt=ft("findOrCreateComponent"),yt=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Object.defineProperty(this,pt,{value:vt}),this.data=t,this.element=r||document.querySelector('[data-hello-form="'.concat(this.id,'"]'))||document.createElement("form")}var t,r,n,i;return t=e,r=[{key:"mount",value:(n=function*(){var e,{ifCompleted:t=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t&&this.hasBeenCompleted)return null===(e=this.element)||void 0===e||e.remove(),Zt.eventEmitter.dispatch("form:completed",function(e){for(var t=1;t{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),Zt.business.features.white_label||this.element.prepend(nt.build())},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){at(o,r,i,a,u,"next",e)}function u(e){at(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"buildHeader",value:function(e){var t=lt(this,pt)[pt]("[data-form-header]","header");t.innerHTML=e.content,this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}},{key:"buildInputs",value:function(e){var t=lt(this,pt)[pt]("[data-form-inputs]","main");e.map(e=>Ye.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildButton",value:function(e){var t=lt(this,pt)[pt]("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildFooter",value:function(e){var t=lt(this,pt)[pt]("[data-form-footer]","footer");t.innerHTML=e.content,this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}},{key:"markAsCompleted",value:function(e){var t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem("hello-form-".concat(this.id),JSON.stringify(t)),Zt.eventEmitter.dispatch("form:completed",t)}},{key:"hasBeenCompleted",get:function(){return null!==localStorage.getItem("hello-form-".concat(this.id))}},{key:"id",get:function(){return this.data.id}},{key:"localeAuthKey",get:function(){var e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}},{key:"elementAttributes",get:function(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}}],r&&ut(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function vt(e,t){var r=this.element.querySelector(e);if(r)return r.cloneNode(!0);var n=document.createElement(t);return n.setAttribute(e.replace("[","").replace("]",""),""),n}function dt(e){var t="function"==typeof Map?new Map:void 0;return dt=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return ht(e,arguments,gt(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),mt(n,e)},dt(e)}function ht(e,t,r){return ht=bt()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&mt(i,r.prototype),i},ht.apply(null,arguments)}function bt(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function mt(e,t){return mt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},mt(e,t)}function gt(e){return gt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},gt(e)}var wt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&mt(e,t)}(o,e);var t,r,n,i=(r=o,n=bt(),function(){var e,t=gt(r);if(n){var i=gt(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(e=i.call(this,"You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id")).name="NotInitializedError",e}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(dt(Error));function Ot(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Pt(e,t){for(var r=0;r0&&this.collect()}},{key:"formMutationObserver",value:function(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}},{key:"collect",value:(n=function*(){if(Zt.notInitialized)throw new wt;if(!this.fetching){if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");var e=function(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}(this,_t)[_t];if(0!==e.length){var t=e.map(e=>ce.get(e).then(e=>e.json()));this.fetching=!0,yield Promise.all(t).then(e=>e.forEach(this.add)).then(()=>Zt.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),P.forms.autoMount&&this.forms.forEach(e=>e.mount())}}},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){Ot(o,r,i,a,u,"next",e)}function u(e){Ot(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"forEach",value:function(e){this.forms.forEach(e)}},{key:"map",value:function(e){return this.forms.map(e)}},{key:"add",value:function(e){this.includes(e.id)||(Zt.business.data||(Zt.business.setData(e.business),Zt.business.setLocale(y.toString())),Zt.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new yt(e)))}},{key:"getById",value:function(e){return this.forms.find(t=>t.id===e)}},{key:"getByIndex",value:function(e){return this.forms[e]}},{key:"includes",value:function(e){return this.forms.some(t=>t.id===e)}},{key:"excludes",value:function(e){return!this.includes(e)}},{key:"length",get:function(){return this.forms.length}}],r&&Pt(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Et(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}function Tt(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function xt(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{};if(this.notInitialized)throw new wt;var r=qt(qt({},t&&t.headers||{}),this.headers),n=qt(qt({},It.identificationData),t.user_parameters||{}),i=t&&t.url?new qe(t.url):this.page,o=qt(qt({session:this.session,user_parameters:n,action:e},t),i.trackingData);return delete o.headers,yield Ce.events.create({headers:r,body:o})}),function(e){return i.apply(this,arguments)})},{key:"identify",value:(n=Bt(function*(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(It.id===e)return new X(!0,{json:(t=Bt(function*(){}),function(){return t.apply(this,arguments)})});var n=yield Ce.identifications.create(qt({user_id:e},r));return n.succeeded&&It.remember(e,r.source),n}),function(e){return n.apply(this,arguments)})},{key:"forget",value:function(){It.forget()}},{key:"on",value:function(e,t){this.eventEmitter.addSubscriber(e,t)}},{key:"removeEventListener",value:function(e,t){this.eventEmitter.removeSubscriber(e,t)}},{key:"session",get:function(){return $e.session}},{key:"isInitialized",get:function(){return void 0!==$e.session}},{key:"notInitialized",get:function(){return!this.business||void 0===this.business.id}},{key:"headers",get:function(){if(this.notInitialized)throw new wt;return{Authorization:"Bearer ".concat(this.business.id),Accept:"application/json","Content-Type":"application/json"}}}],r&&Nt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();Ut.eventEmitter=new A,Ut.forms=void 0,Ut.business=void 0,Ut.webchat=void 0;const Zt=Ut,Jt=e=>{const t=e.storePreferencesData||{},r=e.shippingData?.logisticsInfo||[],n=0===r.length?"deliver":(()=>{const e=["pickup","retir","collect","recolha","loja"];return r.some(t=>{const r=(t.selectedSla||"").toLowerCase();return"pickup-in-point"===(t.selectedDeliveryChannel||"").toLowerCase()||e.some(e=>r.includes(e))})?"collect":"deliver"})(),i=(e.items||[]).map(e=>({quantity:e.quantity,price:{amount:(e.sellingPrice||0)+(e.tax||0),currency:t.currencyCode},product:{reference:e.id,categories:Object.values(e.productCategories||{}),name:e.skuName,image_url:e.imageUrl,sku:e.id,source:"vtex",price:{amount:e.price||0,currency:t.currencyCode},brand:e.additionalInfo?.brandName,product:{reference:e.productId,name:e.name,source:"vtex",categories:Object.values(e.productCategories||{}),brand:e.additionalInfo?.brandName}}}));return{reference:e.orderGroup||e.orderFormId,source:"vtex",delivery:n,items:i}},Gt=new Set,Wt=e=>`hellotext:vtex-checkout-started:${e}`,$t={initialize:e=>{Zt.initialize(e);const t=e=>{const t=(e=>{const t=e?.clientProfileData||{};return{id:t.email,email:t.email,first_name:t.firstName,last_name:t.lastName,phone:t.phone,document:t.document,source:"vtex"}})(e);(t.email||t.phone)&&Zt.identify(t.email||t.phone,t),async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=e?.orderFormId;if(!r||Gt.has(r)||(e=>{if(!e)return!1;try{return"1"===window.sessionStorage.getItem(Wt(e))}catch(e){return!1}})(r))return;const n={object_parameters:Jt(e),user_parameters:t};Gt.add(r);try{const e=await Zt.track("checkout.started",n);e?.succeeded&&(e=>{if(e)try{window.sessionStorage.setItem(Wt(e),"1")}catch(e){}})(r)}catch(e){}finally{Gt.delete(r)}}(e,t)};$(window).on("orderFormUpdated.vtex",(e,r)=>{t(r)}),window.vtexjs?.checkout&&vtexjs.checkout.getOrderForm().done(t)}};return t.default})()); \ No newline at end of file diff --git a/src/utils.js b/src/utils.js index 313eb98..e1dfac8 100644 --- a/src/utils.js +++ b/src/utils.js @@ -75,8 +75,7 @@ const extractOrderData = (orderForm) => { return { reference: orderForm.orderGroup || orderForm.orderFormId, - amount: orderForm.value || 0, - currency: storeData.currencyCode, + source: "vtex", delivery, items, }; From a26b8e2560de000f12b3ee387b728c4448631bbd Mon Sep 17 00:00:00 2001 From: rockwellll Date: Fri, 17 Apr 2026 09:55:02 +0300 Subject: [PATCH 2/4] update tests --- src/__tests__/confirmation.test.js | 3 +-- src/__tests__/funnel.test.js | 9 +++------ src/__tests__/utils.test.js | 3 +-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/__tests__/confirmation.test.js b/src/__tests__/confirmation.test.js index 5acc2e6..988c972 100644 --- a/src/__tests__/confirmation.test.js +++ b/src/__tests__/confirmation.test.js @@ -106,8 +106,7 @@ describe("confirmation.initialize", () => { }, object_parameters: { reference: "order-group-123", - amount: 109995000, - currency: "COP", + source: "vtex", delivery: "deliver", items: [ expect.objectContaining({ diff --git a/src/__tests__/funnel.test.js b/src/__tests__/funnel.test.js index 444cdc4..1af090a 100644 --- a/src/__tests__/funnel.test.js +++ b/src/__tests__/funnel.test.js @@ -132,8 +132,7 @@ describe("funnel.initialize", () => { }, object_parameters: { reference: "order-group-123", - amount: 109995000, - currency: "COP", + source: "vtex", delivery: "deliver", items: [ expect.objectContaining({ @@ -174,8 +173,7 @@ describe("funnel.initialize", () => { }, object_parameters: { reference: "order-group-123", - amount: 109995000, - currency: "COP", + source: "vtex", delivery: "deliver", items: [ expect.objectContaining({ @@ -255,8 +253,7 @@ describe("funnel.initialize", () => { }, object_parameters: { reference: "order-group-456", - amount: 109995000, - currency: "COP", + source: "vtex", delivery: "deliver", items: [ expect.objectContaining({ diff --git a/src/__tests__/utils.test.js b/src/__tests__/utils.test.js index 1de86d9..689f4f5 100644 --- a/src/__tests__/utils.test.js +++ b/src/__tests__/utils.test.js @@ -69,8 +69,7 @@ describe("extractOrderData", () => { expect(extractOrderData(orderForm)).toEqual({ reference: "order-group-123", - amount: 109995000, - currency: "COP", + source: "vtex", delivery: "deliver", items: [ { From 11afc4b470b541c7cb77f0cf6dba4764c97836ea Mon Sep 17 00:00:00 2001 From: rockwellll Date: Fri, 17 Apr 2026 09:55:09 +0300 Subject: [PATCH 3/4] 1.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f97a2c..4e4ebcc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hellotext/vtex-checkout", - "version": "1.0.3", + "version": "1.0.4", "description": "Hellotext SDK for VTEX Checkout", "unpkg": "dist/funnel.js", "author": "Hellotext", From 194fc20d93321974c32b77f7ec7e83a6b32443c8 Mon Sep 17 00:00:00 2001 From: rockwellll Date: Tue, 19 May 2026 15:12:22 +0300 Subject: [PATCH 4/4] Capture VTEX newsletter opt-in --- dist/confirmation.js | 2 +- dist/funnel.js | 2 +- src/__tests__/confirmation.test.js | 38 ++++++++++++++++++++++++++++++ src/__tests__/funnel.test.js | 27 +++++++++++++++++++++ src/__tests__/utils.test.js | 26 ++++++++++++++++++++ src/utils.js | 9 ++++++- 6 files changed, 101 insertions(+), 3 deletions(-) diff --git a/dist/confirmation.js b/dist/confirmation.js index 470dc12..a38a83a 100644 --- a/dist/confirmation.js +++ b/dist/confirmation.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hellotext=t():e.Hellotext=t()}(Object("undefined"!=typeof self?self:this),()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function r(e,t){for(var r=0;rZt});var i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"shouldShowSuccessMessage",get:function(){return this.successMessage}}],null&&r(t.prototype,null),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function o(e,t){for(var r=0;re.trim()):this._classes},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("classes must be an array or a string");this._classes=e}},{key:"triggerClasses",get:function(){return"string"==typeof this._triggerClasses?this._triggerClasses.split(",").map(e=>e.trim()):this._triggerClasses},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("triggerClasses must be an array or a string");this._triggerClasses=e}},{key:"id",get:function(){return this._id},set:function(e){this._id=e}},{key:"isSet",get:function(){return!!this._id}},{key:"style",get:function(){return this._style},set:function(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(e=>{var[t,r]=e;if(!["primaryColor","secondaryColor","typography"].includes(t))throw new Error("Invalid style property: ".concat(t));if("typography"!==t&&!this.isHexOrRgba(r))throw new Error("Invalid color value: ".concat(r," for ").concat(t,". Colors must be hex or rgb/a."))}),this._style=e}},{key:"behaviour",get:function(){return this._behaviour},set:function(e){if(!Object.values(m).includes(e))throw new Error("Invalid behaviour value: ".concat(e));this._behaviour=e}},{key:"strategy",get:function(){return this._strategy?this._strategy:"body"==this.container?b.FIXED:b.ABSOLUTE},set:function(e){if(e&&!Object.values(b).includes(e))throw new Error("Invalid strategy value: ".concat(e));this._strategy=e}},{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"isHexOrRgba",value:function(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}}],null&&v(t.prototype,null),r&&v(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function w(e,t){for(var r=0;r{var[t,r]=e;"forms"===t?this.forms=i.assign(r):"webchat"===t?this.webchat=g.assign(r):this[t]=r}),this}},{key:"locale",get:function(){return y.toString()},set:function(e){y.identifier=e}},{key:"endpoint",value:function(e){return"".concat(this.apiRoot,"/").concat(e)}}],null&&w(t.prototype,null),r&&w(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function j(e){var t="function"==typeof Map?new Map:void 0;return j=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return k(e,arguments,C(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),_(n,e)},j(e)}function k(e,t,r){return k=S()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&_(i,r.prototype),i},k.apply(null,arguments)}function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function _(e,t){return _=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},_(e,t)}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}P.apiRoot="https://api.hellotext.com/v1",P.actionCableUrl="wss://www.hellotext.com/cable",P.autoGenerateSession=!0,P.session=null,P.forms=i,P.webchat=g;var E=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_(e,t)}(o,e);var t,r,n,i=(r=o,n=S(),function(){var e,t=C(r);if(n){var i=C(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(t=i.call(this,"".concat(e," is not valid. Please provide a valid event name"))).name="InvalidEvent",t}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(j(Error));function T(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function L(e){for(var t=1;tt===e)}}],(r=[{key:"addSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers=L(L({},this.subscribers),{},{[t]:this.subscribers[t]?[...this.subscribers[t],r]:[r]})}},{key:"removeSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers[t]&&(this.subscribers[t]=this.subscribers[t].filter(e=>e!==r))}},{key:"dispatch",value:function(e,t){var r;null===(r=this.subscribers[e])||void 0===r||r.forEach(e=>{e(t)})}},{key:"listeners",get:function(){return 0!==Object.keys(this.subscribers).length}}])&&M(t.prototype,r),n&&M(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function I(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function R(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:{},t=yield fetch(this.endpoint,{method:"POST",headers:Ut.headers,body:JSON.stringify(le({session:Ut.session},e))});return new X(t.ok,t)},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){fe(o,r,i,a,u,"next",e)}function u(e){fe(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})}],null&&pe(t.prototype,null),r&&pe(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function he(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function de(e,t){for(var r=0;r{var[r,n]=e;t.searchParams.append("style[".concat(r,"]"),n)}),t.searchParams.append("placement",P.webchat.placement);var r=yield fetch(t,{method:"GET",headers:Ut.headers}),n=yield r.json();return Ut.business.data||(Ut.business.setData(n.business),Ut.business.setLocale(n.locale)),(new DOMParser).parseFromString(n.html,"text/html").querySelector("article")},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){he(o,r,i,a,u,"next",e)}function u(e){he(o,r,i,a,u,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})}],null&&de(t.prototype,null),r&&de(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();const ge=me;function we(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Oe(e,t){for(var r=0;r{var[t,r]=e;return r}));Be.set("hello_utm",JSON.stringify(n))}}var t,r;return t=e,(r=[{key:"current",get:function(){try{return JSON.parse(Be.get("hello_utm"))||{}}catch(e){return{}}}}])&&xe(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ae(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.utm=new De,this._url=t}var t,r,n;return t=e,n=[{key:"getRootDomain",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;try{if(!e){var t;if("undefined"==typeof window||null===(t=window.location)||void 0===t||!t.hostname)return null;e=window.location.hostname}var r=e.split(".");if(r.length<=1)return e;for(var n of["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"]){var i=n.split(".");if(r.slice(-i.length).join(".")===n&&r.length>i.length)return".".concat(r.slice(-(i.length+1)).join("."))}var o=r[r.length-1],a=r[r.length-2];return r.length>2&&2===o.length&&a.length<=3?".".concat(r.slice(-3).join(".")):".".concat(r.slice(-2).join("."))}catch(e){return null}}}],(r=[{key:"url",get:function(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}},{key:"title",get:function(){return document.title}},{key:"path",get:function(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}},{key:"utmParams",get:function(){return this.utm.current}},{key:"trackingData",get:function(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}},{key:"domain",get:function(){try{var t=this.url;if(!t)return null;var r=new URL(t).hostname;return e.getRootDomain(r)}catch(e){return null}}}])&&Ae(t.prototype,r),n&&Ae(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function qe(e,t){for(var r=0;r\n ".concat(Ut.business.locale.white_label.powered_by,'\n\n \n \n Hellotext\n \n \n \n \n ')}});var lt=0;function st(e){return"__private_"+lt+++"_"+e}var ft=st("findOrCreateComponent"),pt=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Object.defineProperty(this,ft,{value:yt}),this.data=t,this.element=r||document.querySelector('[data-hello-form="'.concat(this.id,'"]'))||document.createElement("form")}var t,r,n,i;return t=e,r=[{key:"mount",value:(n=function*(){var e,{ifCompleted:t=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t&&this.hasBeenCompleted)return null===(e=this.element)||void 0===e||e.remove(),Ut.eventEmitter.dispatch("form:completed",function(e){for(var t=1;t{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),Ut.business.features.white_label||this.element.prepend(rt.build())},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){ot(o,r,i,a,u,"next",e)}function u(e){ot(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"buildHeader",value:function(e){var t=ct(this,ft)[ft]("[data-form-header]","header");t.innerHTML=e.content,this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}},{key:"buildInputs",value:function(e){var t=ct(this,ft)[ft]("[data-form-inputs]","main");e.map(e=>Ye.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildButton",value:function(e){var t=ct(this,ft)[ft]("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildFooter",value:function(e){var t=ct(this,ft)[ft]("[data-form-footer]","footer");t.innerHTML=e.content,this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}},{key:"markAsCompleted",value:function(e){var t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem("hello-form-".concat(this.id),JSON.stringify(t)),Ut.eventEmitter.dispatch("form:completed",t)}},{key:"hasBeenCompleted",get:function(){return null!==localStorage.getItem("hello-form-".concat(this.id))}},{key:"id",get:function(){return this.data.id}},{key:"localeAuthKey",get:function(){var e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}},{key:"elementAttributes",get:function(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}}],r&&at(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function yt(e,t){var r=this.element.querySelector(e);if(r)return r.cloneNode(!0);var n=document.createElement(t);return n.setAttribute(e.replace("[","").replace("]",""),""),n}function vt(e){var t="function"==typeof Map?new Map:void 0;return vt=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return ht(e,arguments,mt(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),bt(n,e)},vt(e)}function ht(e,t,r){return ht=dt()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&bt(i,r.prototype),i},ht.apply(null,arguments)}function dt(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function bt(e,t){return bt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},bt(e,t)}function mt(e){return mt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},mt(e)}var gt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&bt(e,t)}(o,e);var t,r,n,i=(r=o,n=dt(),function(){var e,t=mt(r);if(n){var i=mt(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(e=i.call(this,"You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id")).name="NotInitializedError",e}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(vt(Error));function wt(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Ot(e,t){for(var r=0;r0&&this.collect()}},{key:"formMutationObserver",value:function(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}},{key:"collect",value:(n=function*(){if(Ut.notInitialized)throw new gt;if(!this.fetching){if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");var e=function(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}(this,St)[St];if(0!==e.length){var t=e.map(e=>ue.get(e).then(e=>e.json()));this.fetching=!0,yield Promise.all(t).then(e=>e.forEach(this.add)).then(()=>Ut.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),P.forms.autoMount&&this.forms.forEach(e=>e.mount())}}},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){wt(o,r,i,a,u,"next",e)}function u(e){wt(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"forEach",value:function(e){this.forms.forEach(e)}},{key:"map",value:function(e){return this.forms.map(e)}},{key:"add",value:function(e){this.includes(e.id)||(Ut.business.data||(Ut.business.setData(e.business),Ut.business.setLocale(y.toString())),Ut.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new pt(e)))}},{key:"getById",value:function(e){return this.forms.find(t=>t.id===e)}},{key:"getByIndex",value:function(e){return this.forms[e]}},{key:"includes",value:function(e){return this.forms.some(t=>t.id===e)}},{key:"excludes",value:function(e){return!this.includes(e)}},{key:"length",get:function(){return this.forms.length}}],r&&Ot(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ct(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}function Et(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Tt(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{};if(this.notInitialized)throw new gt;var r=Rt(Rt({},t&&t.headers||{}),this.headers),n=Rt(Rt({},At.identificationData),t.user_parameters||{}),i=t&&t.url?new Re(t.url):this.page,o=Rt(Rt({session:this.session,user_parameters:n,action:e},t),i.trackingData);return delete o.headers,yield _e.events.create({headers:r,body:o})}),function(e){return i.apply(this,arguments)})},{key:"identify",value:(n=Bt(function*(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(At.id===e)return new X(!0,{json:(t=Bt(function*(){}),function(){return t.apply(this,arguments)})});var n=yield _e.identifications.create(Rt({user_id:e},r));return n.succeeded&&At.remember(e,r.source),n}),function(e){return n.apply(this,arguments)})},{key:"forget",value:function(){At.forget()}},{key:"on",value:function(e,t){this.eventEmitter.addSubscriber(e,t)}},{key:"removeEventListener",value:function(e,t){this.eventEmitter.removeSubscriber(e,t)}},{key:"session",get:function(){return We.session}},{key:"isInitialized",get:function(){return void 0!==We.session}},{key:"notInitialized",get:function(){return!this.business||void 0===this.business.id}},{key:"headers",get:function(){if(this.notInitialized)throw new gt;return{Authorization:"Bearer ".concat(this.business.id),Accept:"application/json","Content-Type":"application/json"}}}],r&&Ft(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();zt.eventEmitter=new A,zt.forms=void 0,zt.business=void 0,zt.webchat=void 0;const Ut=zt,Zt={initialize:e=>{Ut.initialize(e),window.vtexjs?.checkout&&vtexjs.checkout.getOrderForm().done(e=>{const t=(e=>{const t=e?.clientProfileData||{};return{id:t.email,email:t.email,first_name:t.firstName,last_name:t.lastName,phone:t.phone,document:t.document,source:"vtex"}})(e),r=(e=>{const t=e.storePreferencesData||{},r=e.shippingData?.logisticsInfo||[],n=0===r.length?"deliver":(()=>{const e=["pickup","retir","collect","recolha","loja"];return r.some(t=>{const r=(t.selectedSla||"").toLowerCase();return"pickup-in-point"===(t.selectedDeliveryChannel||"").toLowerCase()||e.some(e=>r.includes(e))})?"collect":"deliver"})(),i=(e.items||[]).map(e=>({quantity:e.quantity,price:{amount:(e.sellingPrice||0)+(e.tax||0),currency:t.currencyCode},product:{reference:e.id,categories:Object.values(e.productCategories||{}),name:e.skuName,image_url:e.imageUrl,sku:e.id,source:"vtex",price:{amount:e.price||0,currency:t.currencyCode},brand:e.additionalInfo?.brandName,product:{reference:e.productId,name:e.name,source:"vtex",categories:Object.values(e.productCategories||{}),brand:e.additionalInfo?.brandName}}}));return{reference:e.orderGroup||e.orderFormId,source:"vtex",delivery:n,items:i}})(e);(t.email||t.phone)&&(Ut.identify(t.email||t.phone,t),Ut.track("order.placed",{user_parameters:t,object_parameters:r}))})}};return t.default})()); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hellotext=t():e.Hellotext=t()}(Object("undefined"!=typeof self?self:this),()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function r(e,t){for(var r=0;rZt});var i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"shouldShowSuccessMessage",get:function(){return this.successMessage}}],null&&r(t.prototype,null),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function o(e,t){for(var r=0;re.trim()):this._classes},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("classes must be an array or a string");this._classes=e}},{key:"triggerClasses",get:function(){return"string"==typeof this._triggerClasses?this._triggerClasses.split(",").map(e=>e.trim()):this._triggerClasses},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("triggerClasses must be an array or a string");this._triggerClasses=e}},{key:"id",get:function(){return this._id},set:function(e){this._id=e}},{key:"isSet",get:function(){return!!this._id}},{key:"style",get:function(){return this._style},set:function(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(e=>{var[t,r]=e;if(!["primaryColor","secondaryColor","typography"].includes(t))throw new Error("Invalid style property: ".concat(t));if("typography"!==t&&!this.isHexOrRgba(r))throw new Error("Invalid color value: ".concat(r," for ").concat(t,". Colors must be hex or rgb/a."))}),this._style=e}},{key:"behaviour",get:function(){return this._behaviour},set:function(e){if(!Object.values(m).includes(e))throw new Error("Invalid behaviour value: ".concat(e));this._behaviour=e}},{key:"strategy",get:function(){return this._strategy?this._strategy:"body"==this.container?b.FIXED:b.ABSOLUTE},set:function(e){if(e&&!Object.values(b).includes(e))throw new Error("Invalid strategy value: ".concat(e));this._strategy=e}},{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"isHexOrRgba",value:function(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}}],null&&v(t.prototype,null),r&&v(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function w(e,t){for(var r=0;r{var[t,r]=e;"forms"===t?this.forms=i.assign(r):"webchat"===t?this.webchat=g.assign(r):this[t]=r}),this}},{key:"locale",get:function(){return y.toString()},set:function(e){y.identifier=e}},{key:"endpoint",value:function(e){return"".concat(this.apiRoot,"/").concat(e)}}],null&&w(t.prototype,null),r&&w(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function j(e){var t="function"==typeof Map?new Map:void 0;return j=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return k(e,arguments,C(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),_(n,e)},j(e)}function k(e,t,r){return k=S()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&_(i,r.prototype),i},k.apply(null,arguments)}function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function _(e,t){return _=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},_(e,t)}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}P.apiRoot="https://api.hellotext.com/v1",P.actionCableUrl="wss://www.hellotext.com/cable",P.autoGenerateSession=!0,P.session=null,P.forms=i,P.webchat=g;var E=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_(e,t)}(o,e);var t,r,n,i=(r=o,n=S(),function(){var e,t=C(r);if(n){var i=C(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(t=i.call(this,"".concat(e," is not valid. Please provide a valid event name"))).name="InvalidEvent",t}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(j(Error));function T(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function L(e){for(var t=1;tt===e)}}],(r=[{key:"addSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers=L(L({},this.subscribers),{},{[t]:this.subscribers[t]?[...this.subscribers[t],r]:[r]})}},{key:"removeSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers[t]&&(this.subscribers[t]=this.subscribers[t].filter(e=>e!==r))}},{key:"dispatch",value:function(e,t){var r;null===(r=this.subscribers[e])||void 0===r||r.forEach(e=>{e(t)})}},{key:"listeners",get:function(){return 0!==Object.keys(this.subscribers).length}}])&&M(t.prototype,r),n&&M(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function I(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function R(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:{},t=yield fetch(this.endpoint,{method:"POST",headers:Ut.headers,body:JSON.stringify(le({session:Ut.session},e))});return new X(t.ok,t)},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){fe(o,r,i,a,u,"next",e)}function u(e){fe(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})}],null&&pe(t.prototype,null),r&&pe(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function he(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function de(e,t){for(var r=0;r{var[r,n]=e;t.searchParams.append("style[".concat(r,"]"),n)}),t.searchParams.append("placement",P.webchat.placement);var r=yield fetch(t,{method:"GET",headers:Ut.headers}),n=yield r.json();return Ut.business.data||(Ut.business.setData(n.business),Ut.business.setLocale(n.locale)),(new DOMParser).parseFromString(n.html,"text/html").querySelector("article")},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){he(o,r,i,a,u,"next",e)}function u(e){he(o,r,i,a,u,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})}],null&&de(t.prototype,null),r&&de(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();const ge=me;function we(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Oe(e,t){for(var r=0;r{var[t,r]=e;return r}));Be.set("hello_utm",JSON.stringify(n))}}var t,r;return t=e,(r=[{key:"current",get:function(){try{return JSON.parse(Be.get("hello_utm"))||{}}catch(e){return{}}}}])&&xe(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ae(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.utm=new De,this._url=t}var t,r,n;return t=e,n=[{key:"getRootDomain",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;try{if(!e){var t;if("undefined"==typeof window||null===(t=window.location)||void 0===t||!t.hostname)return null;e=window.location.hostname}var r=e.split(".");if(r.length<=1)return e;for(var n of["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"]){var i=n.split(".");if(r.slice(-i.length).join(".")===n&&r.length>i.length)return".".concat(r.slice(-(i.length+1)).join("."))}var o=r[r.length-1],a=r[r.length-2];return r.length>2&&2===o.length&&a.length<=3?".".concat(r.slice(-3).join(".")):".".concat(r.slice(-2).join("."))}catch(e){return null}}}],(r=[{key:"url",get:function(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}},{key:"title",get:function(){return document.title}},{key:"path",get:function(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}},{key:"utmParams",get:function(){return this.utm.current}},{key:"trackingData",get:function(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}},{key:"domain",get:function(){try{var t=this.url;if(!t)return null;var r=new URL(t).hostname;return e.getRootDomain(r)}catch(e){return null}}}])&&Ae(t.prototype,r),n&&Ae(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function qe(e,t){for(var r=0;r\n ".concat(Ut.business.locale.white_label.powered_by,'\n\n \n \n Hellotext\n \n \n \n \n ')}});var lt=0;function st(e){return"__private_"+lt+++"_"+e}var ft=st("findOrCreateComponent"),pt=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Object.defineProperty(this,ft,{value:yt}),this.data=t,this.element=r||document.querySelector('[data-hello-form="'.concat(this.id,'"]'))||document.createElement("form")}var t,r,n,i;return t=e,r=[{key:"mount",value:(n=function*(){var e,{ifCompleted:t=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t&&this.hasBeenCompleted)return null===(e=this.element)||void 0===e||e.remove(),Ut.eventEmitter.dispatch("form:completed",function(e){for(var t=1;t{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),Ut.business.features.white_label||this.element.prepend(rt.build())},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){ot(o,r,i,a,u,"next",e)}function u(e){ot(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"buildHeader",value:function(e){var t=ct(this,ft)[ft]("[data-form-header]","header");t.innerHTML=e.content,this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}},{key:"buildInputs",value:function(e){var t=ct(this,ft)[ft]("[data-form-inputs]","main");e.map(e=>Ye.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildButton",value:function(e){var t=ct(this,ft)[ft]("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildFooter",value:function(e){var t=ct(this,ft)[ft]("[data-form-footer]","footer");t.innerHTML=e.content,this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}},{key:"markAsCompleted",value:function(e){var t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem("hello-form-".concat(this.id),JSON.stringify(t)),Ut.eventEmitter.dispatch("form:completed",t)}},{key:"hasBeenCompleted",get:function(){return null!==localStorage.getItem("hello-form-".concat(this.id))}},{key:"id",get:function(){return this.data.id}},{key:"localeAuthKey",get:function(){var e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}},{key:"elementAttributes",get:function(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}}],r&&at(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function yt(e,t){var r=this.element.querySelector(e);if(r)return r.cloneNode(!0);var n=document.createElement(t);return n.setAttribute(e.replace("[","").replace("]",""),""),n}function vt(e){var t="function"==typeof Map?new Map:void 0;return vt=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return ht(e,arguments,mt(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),bt(n,e)},vt(e)}function ht(e,t,r){return ht=dt()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&bt(i,r.prototype),i},ht.apply(null,arguments)}function dt(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function bt(e,t){return bt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},bt(e,t)}function mt(e){return mt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},mt(e)}var gt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&bt(e,t)}(o,e);var t,r,n,i=(r=o,n=dt(),function(){var e,t=mt(r);if(n){var i=mt(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(e=i.call(this,"You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id")).name="NotInitializedError",e}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(vt(Error));function wt(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Ot(e,t){for(var r=0;r0&&this.collect()}},{key:"formMutationObserver",value:function(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}},{key:"collect",value:(n=function*(){if(Ut.notInitialized)throw new gt;if(!this.fetching){if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");var e=function(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}(this,St)[St];if(0!==e.length){var t=e.map(e=>ue.get(e).then(e=>e.json()));this.fetching=!0,yield Promise.all(t).then(e=>e.forEach(this.add)).then(()=>Ut.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),P.forms.autoMount&&this.forms.forEach(e=>e.mount())}}},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){wt(o,r,i,a,u,"next",e)}function u(e){wt(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"forEach",value:function(e){this.forms.forEach(e)}},{key:"map",value:function(e){return this.forms.map(e)}},{key:"add",value:function(e){this.includes(e.id)||(Ut.business.data||(Ut.business.setData(e.business),Ut.business.setLocale(y.toString())),Ut.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new pt(e)))}},{key:"getById",value:function(e){return this.forms.find(t=>t.id===e)}},{key:"getByIndex",value:function(e){return this.forms[e]}},{key:"includes",value:function(e){return this.forms.some(t=>t.id===e)}},{key:"excludes",value:function(e){return!this.includes(e)}},{key:"length",get:function(){return this.forms.length}}],r&&Ot(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ct(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}function Et(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Tt(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{};if(this.notInitialized)throw new gt;var r=Rt(Rt({},t&&t.headers||{}),this.headers),n=Rt(Rt({},At.identificationData),t.user_parameters||{}),i=t&&t.url?new Re(t.url):this.page,o=Rt(Rt({session:this.session,user_parameters:n,action:e},t),i.trackingData);return delete o.headers,yield _e.events.create({headers:r,body:o})}),function(e){return i.apply(this,arguments)})},{key:"identify",value:(n=Bt(function*(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(At.id===e)return new X(!0,{json:(t=Bt(function*(){}),function(){return t.apply(this,arguments)})});var n=yield _e.identifications.create(Rt({user_id:e},r));return n.succeeded&&At.remember(e,r.source),n}),function(e){return n.apply(this,arguments)})},{key:"forget",value:function(){At.forget()}},{key:"on",value:function(e,t){this.eventEmitter.addSubscriber(e,t)}},{key:"removeEventListener",value:function(e,t){this.eventEmitter.removeSubscriber(e,t)}},{key:"session",get:function(){return We.session}},{key:"isInitialized",get:function(){return void 0!==We.session}},{key:"notInitialized",get:function(){return!this.business||void 0===this.business.id}},{key:"headers",get:function(){if(this.notInitialized)throw new gt;return{Authorization:"Bearer ".concat(this.business.id),Accept:"application/json","Content-Type":"application/json"}}}],r&&Ft(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();zt.eventEmitter=new A,zt.forms=void 0,zt.business=void 0,zt.webchat=void 0;const Ut=zt,Zt={initialize:e=>{Ut.initialize(e),window.vtexjs?.checkout&&vtexjs.checkout.getOrderForm().done(e=>{const t=(e=>{const t=e?.clientProfileData||{},r=e?.clientPreferencesData||{},n={id:t.email,email:t.email,first_name:t.firstName,last_name:t.lastName,phone:t.phone,document:t.document,source:"vtex"};return!0===r.optinNewsLetter&&(n.subscription_state=!0),n})(e),r=(e=>{const t=e.storePreferencesData||{},r=e.shippingData?.logisticsInfo||[],n=0===r.length?"deliver":(()=>{const e=["pickup","retir","collect","recolha","loja"];return r.some(t=>{const r=(t.selectedSla||"").toLowerCase();return"pickup-in-point"===(t.selectedDeliveryChannel||"").toLowerCase()||e.some(e=>r.includes(e))})?"collect":"deliver"})(),i=(e.items||[]).map(e=>({quantity:e.quantity,price:{amount:(e.sellingPrice||0)+(e.tax||0),currency:t.currencyCode},product:{reference:e.id,categories:Object.values(e.productCategories||{}),name:e.skuName,image_url:e.imageUrl,sku:e.id,source:"vtex",price:{amount:e.price||0,currency:t.currencyCode},brand:e.additionalInfo?.brandName,product:{reference:e.productId,name:e.name,source:"vtex",categories:Object.values(e.productCategories||{}),brand:e.additionalInfo?.brandName}}}));return{reference:e.orderGroup||e.orderFormId,source:"vtex",delivery:n,items:i}})(e);(t.email||t.phone)&&(Ut.identify(t.email||t.phone,t),Ut.track("order.placed",{user_parameters:t,object_parameters:r}))})}};return t.default})()); \ No newline at end of file diff --git a/dist/funnel.js b/dist/funnel.js index 7afc4aa..3a6125a 100644 --- a/dist/funnel.js +++ b/dist/funnel.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hellotext=t():e.Hellotext=t()}(Object("undefined"!=typeof self?self:this),()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function r(e,t){for(var r=0;r$t});var i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"shouldShowSuccessMessage",get:function(){return this.successMessage}}],null&&r(t.prototype,null),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function o(e,t){for(var r=0;re.trim()):this._classes},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("classes must be an array or a string");this._classes=e}},{key:"triggerClasses",get:function(){return"string"==typeof this._triggerClasses?this._triggerClasses.split(",").map(e=>e.trim()):this._triggerClasses},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("triggerClasses must be an array or a string");this._triggerClasses=e}},{key:"id",get:function(){return this._id},set:function(e){this._id=e}},{key:"isSet",get:function(){return!!this._id}},{key:"style",get:function(){return this._style},set:function(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(e=>{var[t,r]=e;if(!["primaryColor","secondaryColor","typography"].includes(t))throw new Error("Invalid style property: ".concat(t));if("typography"!==t&&!this.isHexOrRgba(r))throw new Error("Invalid color value: ".concat(r," for ").concat(t,". Colors must be hex or rgb/a."))}),this._style=e}},{key:"behaviour",get:function(){return this._behaviour},set:function(e){if(!Object.values(m).includes(e))throw new Error("Invalid behaviour value: ".concat(e));this._behaviour=e}},{key:"strategy",get:function(){return this._strategy?this._strategy:"body"==this.container?b.FIXED:b.ABSOLUTE},set:function(e){if(e&&!Object.values(b).includes(e))throw new Error("Invalid strategy value: ".concat(e));this._strategy=e}},{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"isHexOrRgba",value:function(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}}],null&&v(t.prototype,null),r&&v(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function w(e,t){for(var r=0;r{var[t,r]=e;"forms"===t?this.forms=i.assign(r):"webchat"===t?this.webchat=g.assign(r):this[t]=r}),this}},{key:"locale",get:function(){return y.toString()},set:function(e){y.identifier=e}},{key:"endpoint",value:function(e){return"".concat(this.apiRoot,"/").concat(e)}}],null&&w(t.prototype,null),r&&w(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function j(e){var t="function"==typeof Map?new Map:void 0;return j=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return k(e,arguments,C(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),_(n,e)},j(e)}function k(e,t,r){return k=S()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&_(i,r.prototype),i},k.apply(null,arguments)}function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function _(e,t){return _=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},_(e,t)}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}P.apiRoot="https://api.hellotext.com/v1",P.actionCableUrl="wss://www.hellotext.com/cable",P.autoGenerateSession=!0,P.session=null,P.forms=i,P.webchat=g;var E=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_(e,t)}(o,e);var t,r,n,i=(r=o,n=S(),function(){var e,t=C(r);if(n){var i=C(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(t=i.call(this,"".concat(e," is not valid. Please provide a valid event name"))).name="InvalidEvent",t}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(j(Error));function T(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function x(e){for(var t=1;tt===e)}}],(r=[{key:"addSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers=x(x({},this.subscribers),{},{[t]:this.subscribers[t]?[...this.subscribers[t],r]:[r]})}},{key:"removeSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers[t]&&(this.subscribers[t]=this.subscribers[t].filter(e=>e!==r))}},{key:"dispatch",value:function(e,t){var r;null===(r=this.subscribers[e])||void 0===r||r.forEach(e=>{e(t)})}},{key:"listeners",get:function(){return 0!==Object.keys(this.subscribers).length}}])&&M(t.prototype,r),n&&M(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function I(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function R(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:{},t=yield fetch(this.endpoint,{method:"POST",headers:Zt.headers,body:JSON.stringify(se({session:Zt.session},e))});return new X(t.ok,t)},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){pe(o,r,i,a,u,"next",e)}function u(e){pe(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})}],null&&ye(t.prototype,null),r&&ye(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function he(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function be(e,t){for(var r=0;r{var[r,n]=e;t.searchParams.append("style[".concat(r,"]"),n)}),t.searchParams.append("placement",P.webchat.placement);var r=yield fetch(t,{method:"GET",headers:Zt.headers}),n=yield r.json();return Zt.business.data||(Zt.business.setData(n.business),Zt.business.setLocale(n.locale)),(new DOMParser).parseFromString(n.html,"text/html").querySelector("article")},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){he(o,r,i,a,u,"next",e)}function u(e){he(o,r,i,a,u,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})}],null&&be(t.prototype,null),r&&be(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();const we=ge;function Oe(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Pe(e,t){for(var r=0;r{var[t,r]=e;return r}));Be.set("hello_utm",JSON.stringify(n))}}var t,r;return t=e,(r=[{key:"current",get:function(){try{return JSON.parse(Be.get("hello_utm"))||{}}catch(e){return{}}}}])&&Me(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ie(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.utm=new Ae,this._url=t}var t,r,n;return t=e,n=[{key:"getRootDomain",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;try{if(!e){var t;if("undefined"==typeof window||null===(t=window.location)||void 0===t||!t.hostname)return null;e=window.location.hostname}var r=e.split(".");if(r.length<=1)return e;for(var n of["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"]){var i=n.split(".");if(r.slice(-i.length).join(".")===n&&r.length>i.length)return".".concat(r.slice(-(i.length+1)).join("."))}var o=r[r.length-1],a=r[r.length-2];return r.length>2&&2===o.length&&a.length<=3?".".concat(r.slice(-3).join(".")):".".concat(r.slice(-2).join("."))}catch(e){return null}}}],(r=[{key:"url",get:function(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}},{key:"title",get:function(){return document.title}},{key:"path",get:function(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}},{key:"utmParams",get:function(){return this.utm.current}},{key:"trackingData",get:function(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}},{key:"domain",get:function(){try{var t=this.url;if(!t)return null;var r=new URL(t).hostname;return e.getRootDomain(r)}catch(e){return null}}}])&&Ie(t.prototype,r),n&&Ie(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function He(e,t){for(var r=0;r\n ".concat(Zt.business.locale.white_label.powered_by,'\n\n \n \n Hellotext\n \n \n \n \n ')}});var st=0;function ft(e){return"__private_"+st+++"_"+e}var pt=ft("findOrCreateComponent"),yt=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Object.defineProperty(this,pt,{value:vt}),this.data=t,this.element=r||document.querySelector('[data-hello-form="'.concat(this.id,'"]'))||document.createElement("form")}var t,r,n,i;return t=e,r=[{key:"mount",value:(n=function*(){var e,{ifCompleted:t=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t&&this.hasBeenCompleted)return null===(e=this.element)||void 0===e||e.remove(),Zt.eventEmitter.dispatch("form:completed",function(e){for(var t=1;t{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),Zt.business.features.white_label||this.element.prepend(nt.build())},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){at(o,r,i,a,u,"next",e)}function u(e){at(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"buildHeader",value:function(e){var t=lt(this,pt)[pt]("[data-form-header]","header");t.innerHTML=e.content,this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}},{key:"buildInputs",value:function(e){var t=lt(this,pt)[pt]("[data-form-inputs]","main");e.map(e=>Ye.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildButton",value:function(e){var t=lt(this,pt)[pt]("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildFooter",value:function(e){var t=lt(this,pt)[pt]("[data-form-footer]","footer");t.innerHTML=e.content,this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}},{key:"markAsCompleted",value:function(e){var t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem("hello-form-".concat(this.id),JSON.stringify(t)),Zt.eventEmitter.dispatch("form:completed",t)}},{key:"hasBeenCompleted",get:function(){return null!==localStorage.getItem("hello-form-".concat(this.id))}},{key:"id",get:function(){return this.data.id}},{key:"localeAuthKey",get:function(){var e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}},{key:"elementAttributes",get:function(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}}],r&&ut(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function vt(e,t){var r=this.element.querySelector(e);if(r)return r.cloneNode(!0);var n=document.createElement(t);return n.setAttribute(e.replace("[","").replace("]",""),""),n}function dt(e){var t="function"==typeof Map?new Map:void 0;return dt=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return ht(e,arguments,gt(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),mt(n,e)},dt(e)}function ht(e,t,r){return ht=bt()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&mt(i,r.prototype),i},ht.apply(null,arguments)}function bt(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function mt(e,t){return mt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},mt(e,t)}function gt(e){return gt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},gt(e)}var wt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&mt(e,t)}(o,e);var t,r,n,i=(r=o,n=bt(),function(){var e,t=gt(r);if(n){var i=gt(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(e=i.call(this,"You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id")).name="NotInitializedError",e}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(dt(Error));function Ot(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Pt(e,t){for(var r=0;r0&&this.collect()}},{key:"formMutationObserver",value:function(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}},{key:"collect",value:(n=function*(){if(Zt.notInitialized)throw new wt;if(!this.fetching){if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");var e=function(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}(this,_t)[_t];if(0!==e.length){var t=e.map(e=>ce.get(e).then(e=>e.json()));this.fetching=!0,yield Promise.all(t).then(e=>e.forEach(this.add)).then(()=>Zt.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),P.forms.autoMount&&this.forms.forEach(e=>e.mount())}}},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){Ot(o,r,i,a,u,"next",e)}function u(e){Ot(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"forEach",value:function(e){this.forms.forEach(e)}},{key:"map",value:function(e){return this.forms.map(e)}},{key:"add",value:function(e){this.includes(e.id)||(Zt.business.data||(Zt.business.setData(e.business),Zt.business.setLocale(y.toString())),Zt.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new yt(e)))}},{key:"getById",value:function(e){return this.forms.find(t=>t.id===e)}},{key:"getByIndex",value:function(e){return this.forms[e]}},{key:"includes",value:function(e){return this.forms.some(t=>t.id===e)}},{key:"excludes",value:function(e){return!this.includes(e)}},{key:"length",get:function(){return this.forms.length}}],r&&Pt(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Et(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}function Tt(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function xt(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{};if(this.notInitialized)throw new wt;var r=qt(qt({},t&&t.headers||{}),this.headers),n=qt(qt({},It.identificationData),t.user_parameters||{}),i=t&&t.url?new qe(t.url):this.page,o=qt(qt({session:this.session,user_parameters:n,action:e},t),i.trackingData);return delete o.headers,yield Ce.events.create({headers:r,body:o})}),function(e){return i.apply(this,arguments)})},{key:"identify",value:(n=Bt(function*(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(It.id===e)return new X(!0,{json:(t=Bt(function*(){}),function(){return t.apply(this,arguments)})});var n=yield Ce.identifications.create(qt({user_id:e},r));return n.succeeded&&It.remember(e,r.source),n}),function(e){return n.apply(this,arguments)})},{key:"forget",value:function(){It.forget()}},{key:"on",value:function(e,t){this.eventEmitter.addSubscriber(e,t)}},{key:"removeEventListener",value:function(e,t){this.eventEmitter.removeSubscriber(e,t)}},{key:"session",get:function(){return $e.session}},{key:"isInitialized",get:function(){return void 0!==$e.session}},{key:"notInitialized",get:function(){return!this.business||void 0===this.business.id}},{key:"headers",get:function(){if(this.notInitialized)throw new wt;return{Authorization:"Bearer ".concat(this.business.id),Accept:"application/json","Content-Type":"application/json"}}}],r&&Nt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();Ut.eventEmitter=new A,Ut.forms=void 0,Ut.business=void 0,Ut.webchat=void 0;const Zt=Ut,Jt=e=>{const t=e.storePreferencesData||{},r=e.shippingData?.logisticsInfo||[],n=0===r.length?"deliver":(()=>{const e=["pickup","retir","collect","recolha","loja"];return r.some(t=>{const r=(t.selectedSla||"").toLowerCase();return"pickup-in-point"===(t.selectedDeliveryChannel||"").toLowerCase()||e.some(e=>r.includes(e))})?"collect":"deliver"})(),i=(e.items||[]).map(e=>({quantity:e.quantity,price:{amount:(e.sellingPrice||0)+(e.tax||0),currency:t.currencyCode},product:{reference:e.id,categories:Object.values(e.productCategories||{}),name:e.skuName,image_url:e.imageUrl,sku:e.id,source:"vtex",price:{amount:e.price||0,currency:t.currencyCode},brand:e.additionalInfo?.brandName,product:{reference:e.productId,name:e.name,source:"vtex",categories:Object.values(e.productCategories||{}),brand:e.additionalInfo?.brandName}}}));return{reference:e.orderGroup||e.orderFormId,source:"vtex",delivery:n,items:i}},Gt=new Set,Wt=e=>`hellotext:vtex-checkout-started:${e}`,$t={initialize:e=>{Zt.initialize(e);const t=e=>{const t=(e=>{const t=e?.clientProfileData||{};return{id:t.email,email:t.email,first_name:t.firstName,last_name:t.lastName,phone:t.phone,document:t.document,source:"vtex"}})(e);(t.email||t.phone)&&Zt.identify(t.email||t.phone,t),async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=e?.orderFormId;if(!r||Gt.has(r)||(e=>{if(!e)return!1;try{return"1"===window.sessionStorage.getItem(Wt(e))}catch(e){return!1}})(r))return;const n={object_parameters:Jt(e),user_parameters:t};Gt.add(r);try{const e=await Zt.track("checkout.started",n);e?.succeeded&&(e=>{if(e)try{window.sessionStorage.setItem(Wt(e),"1")}catch(e){}})(r)}catch(e){}finally{Gt.delete(r)}}(e,t)};$(window).on("orderFormUpdated.vtex",(e,r)=>{t(r)}),window.vtexjs?.checkout&&vtexjs.checkout.getOrderForm().done(t)}};return t.default})()); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hellotext=t():e.Hellotext=t()}(Object("undefined"!=typeof self?self:this),()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function r(e,t){for(var r=0;r$t});var i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}var t,n;return t=e,n=[{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"shouldShowSuccessMessage",get:function(){return this.successMessage}}],null&&r(t.prototype,null),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function o(e,t){for(var r=0;re.trim()):this._classes},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("classes must be an array or a string");this._classes=e}},{key:"triggerClasses",get:function(){return"string"==typeof this._triggerClasses?this._triggerClasses.split(",").map(e=>e.trim()):this._triggerClasses},set:function(e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("triggerClasses must be an array or a string");this._triggerClasses=e}},{key:"id",get:function(){return this._id},set:function(e){this._id=e}},{key:"isSet",get:function(){return!!this._id}},{key:"style",get:function(){return this._style},set:function(e){if("object"!=typeof e)throw new Error("Style must be an object");Object.entries(e).forEach(e=>{var[t,r]=e;if(!["primaryColor","secondaryColor","typography"].includes(t))throw new Error("Invalid style property: ".concat(t));if("typography"!==t&&!this.isHexOrRgba(r))throw new Error("Invalid color value: ".concat(r," for ").concat(t,". Colors must be hex or rgb/a."))}),this._style=e}},{key:"behaviour",get:function(){return this._behaviour},set:function(e){if(!Object.values(m).includes(e))throw new Error("Invalid behaviour value: ".concat(e));this._behaviour=e}},{key:"strategy",get:function(){return this._strategy?this._strategy:"body"==this.container?b.FIXED:b.ABSOLUTE},set:function(e){if(e&&!Object.values(b).includes(e))throw new Error("Invalid strategy value: ".concat(e));this._strategy=e}},{key:"assign",value:function(e){return e&&Object.entries(e).forEach(e=>{var[t,r]=e;this[t]=r}),this}},{key:"isHexOrRgba",value:function(e){return/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(e)||/^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(e)}}],null&&v(t.prototype,null),r&&v(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function w(e,t){for(var r=0;r{var[t,r]=e;"forms"===t?this.forms=i.assign(r):"webchat"===t?this.webchat=g.assign(r):this[t]=r}),this}},{key:"locale",get:function(){return y.toString()},set:function(e){y.identifier=e}},{key:"endpoint",value:function(e){return"".concat(this.apiRoot,"/").concat(e)}}],null&&w(t.prototype,null),r&&w(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function j(e){var t="function"==typeof Map?new Map:void 0;return j=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return k(e,arguments,C(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),_(n,e)},j(e)}function k(e,t,r){return k=S()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&_(i,r.prototype),i},k.apply(null,arguments)}function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function _(e,t){return _=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},_(e,t)}function C(e){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},C(e)}P.apiRoot="https://api.hellotext.com/v1",P.actionCableUrl="wss://www.hellotext.com/cable",P.autoGenerateSession=!0,P.session=null,P.forms=i,P.webchat=g;var E=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_(e,t)}(o,e);var t,r,n,i=(r=o,n=S(),function(){var e,t=C(r);if(n){var i=C(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(t=i.call(this,"".concat(e," is not valid. Please provide a valid event name"))).name="InvalidEvent",t}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(j(Error));function T(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function x(e){for(var t=1;tt===e)}}],(r=[{key:"addSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers=x(x({},this.subscribers),{},{[t]:this.subscribers[t]?[...this.subscribers[t],r]:[r]})}},{key:"removeSubscriber",value:function(t,r){if(e.invalid(t))throw new E(t);this.subscribers[t]&&(this.subscribers[t]=this.subscribers[t].filter(e=>e!==r))}},{key:"dispatch",value:function(e,t){var r;null===(r=this.subscribers[e])||void 0===r||r.forEach(e=>{e(t)})}},{key:"listeners",get:function(){return 0!==Object.keys(this.subscribers).length}}])&&M(t.prototype,r),n&&M(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function I(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function R(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:{},t=yield fetch(this.endpoint,{method:"POST",headers:Zt.headers,body:JSON.stringify(se({session:Zt.session},e))});return new X(t.ok,t)},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){pe(o,r,i,a,u,"next",e)}function u(e){pe(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})}],null&&ye(t.prototype,null),r&&ye(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function he(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function be(e,t){for(var r=0;r{var[r,n]=e;t.searchParams.append("style[".concat(r,"]"),n)}),t.searchParams.append("placement",P.webchat.placement);var r=yield fetch(t,{method:"GET",headers:Zt.headers}),n=yield r.json();return Zt.business.data||(Zt.business.setData(n.business),Zt.business.setLocale(n.locale)),(new DOMParser).parseFromString(n.html,"text/html").querySelector("article")},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){he(o,r,i,a,u,"next",e)}function u(e){he(o,r,i,a,u,"throw",e)}a(void 0)})},function(e){return i.apply(this,arguments)})}],null&&be(t.prototype,null),r&&be(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();const we=ge;function Oe(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Pe(e,t){for(var r=0;r{var[t,r]=e;return r}));Be.set("hello_utm",JSON.stringify(n))}}var t,r;return t=e,(r=[{key:"current",get:function(){try{return JSON.parse(Be.get("hello_utm"))||{}}catch(e){return{}}}}])&&Me(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Ie(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.utm=new Ae,this._url=t}var t,r,n;return t=e,n=[{key:"getRootDomain",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;try{if(!e){var t;if("undefined"==typeof window||null===(t=window.location)||void 0===t||!t.hostname)return null;e=window.location.hostname}var r=e.split(".");if(r.length<=1)return e;for(var n of["myshopify.com","vtexcommercestable.com.br","myvtex.com","wixsite.com"]){var i=n.split(".");if(r.slice(-i.length).join(".")===n&&r.length>i.length)return".".concat(r.slice(-(i.length+1)).join("."))}var o=r[r.length-1],a=r[r.length-2];return r.length>2&&2===o.length&&a.length<=3?".".concat(r.slice(-3).join(".")):".".concat(r.slice(-2).join("."))}catch(e){return null}}}],(r=[{key:"url",get:function(){return null!==this._url&&void 0!==this._url?this._url:window.location.href}},{key:"title",get:function(){return document.title}},{key:"path",get:function(){if(this._url)try{return new URL(this._url).pathname}catch(e){return"/"}return window.location.pathname}},{key:"utmParams",get:function(){return this.utm.current}},{key:"trackingData",get:function(){return{page:{url:this.url,title:this.title,path:this.path},utm_params:this.utmParams}}},{key:"domain",get:function(){try{var t=this.url;if(!t)return null;var r=new URL(t).hostname;return e.getRootDomain(r)}catch(e){return null}}}])&&Ie(t.prototype,r),n&&Ie(t,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();function He(e,t){for(var r=0;r\n ".concat(Zt.business.locale.white_label.powered_by,'\n\n \n \n Hellotext\n \n \n \n \n ')}});var st=0;function ft(e){return"__private_"+st+++"_"+e}var pt=ft("findOrCreateComponent"),yt=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Object.defineProperty(this,pt,{value:vt}),this.data=t,this.element=r||document.querySelector('[data-hello-form="'.concat(this.id,'"]'))||document.createElement("form")}var t,r,n,i;return t=e,r=[{key:"mount",value:(n=function*(){var e,{ifCompleted:t=!0}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(t&&this.hasBeenCompleted)return null===(e=this.element)||void 0===e||e.remove(),Zt.eventEmitter.dispatch("form:completed",function(e){for(var t=1;t{this.element.setAttribute(e.name,e.value)}),document.contains(this.element)||document.body.appendChild(this.element),Zt.business.features.white_label||this.element.prepend(nt.build())},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){at(o,r,i,a,u,"next",e)}function u(e){at(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"buildHeader",value:function(e){var t=lt(this,pt)[pt]("[data-form-header]","header");t.innerHTML=e.content,this.element.querySelector("[data-form-header]")?this.element.querySelector("[data-form-header]").replaceWith(t):this.element.prepend(t)}},{key:"buildInputs",value:function(e){var t=lt(this,pt)[pt]("[data-form-inputs]","main");e.map(e=>Ye.build(e)).forEach(e=>t.appendChild(e)),this.element.querySelector("[data-form-inputs]")?this.element.querySelector("[data-form-inputs]").replaceWith(t):this.element.querySelector("[data-form-header]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildButton",value:function(e){var t=lt(this,pt)[pt]("[data-form-button]","button");t.innerText=e.text,t.setAttribute("data-action","click->hellotext--form#submit"),t.setAttribute("data-hellotext--form-target","button"),this.element.querySelector("[data-form-button]")?this.element.querySelector("[data-form-button]").replaceWith(t):this.element.querySelector("[data-form-inputs]").insertAdjacentHTML("afterend",t.outerHTML)}},{key:"buildFooter",value:function(e){var t=lt(this,pt)[pt]("[data-form-footer]","footer");t.innerHTML=e.content,this.element.querySelector("[data-form-footer]")?this.element.querySelector("[data-form-footer]").replaceWith(t):this.element.appendChild(t)}},{key:"markAsCompleted",value:function(e){var t={state:"completed",id:this.id,data:e,completedAt:(new Date).getTime()};localStorage.setItem("hello-form-".concat(this.id),JSON.stringify(t)),Zt.eventEmitter.dispatch("form:completed",t)}},{key:"hasBeenCompleted",get:function(){return null!==localStorage.getItem("hello-form-".concat(this.id))}},{key:"id",get:function(){return this.data.id}},{key:"localeAuthKey",get:function(){var e=this.data.steps[0];return e.inputs.some(e=>"email"===e.kind)&&e.inputs.some(e=>"phone"===e.kind)?"phone_and_email":e.inputs.some(e=>"email"===e.kind)?"email":e.inputs.some(e=>"phone"===e.kind)?"phone":"none"}},{key:"elementAttributes",get:function(){return[{name:"data-controller",value:"hellotext--form"},{name:"data-hello-form",value:this.id},{name:"data-hellotext--form-data-value",value:JSON.stringify(this.data)}]}}],r&&ut(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function vt(e,t){var r=this.element.querySelector(e);if(r)return r.cloneNode(!0);var n=document.createElement(t);return n.setAttribute(e.replace("[","").replace("]",""),""),n}function dt(e){var t="function"==typeof Map?new Map:void 0;return dt=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return ht(e,arguments,gt(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),mt(n,e)},dt(e)}function ht(e,t,r){return ht=bt()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&mt(i,r.prototype),i},ht.apply(null,arguments)}function bt(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function mt(e,t){return mt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},mt(e,t)}function gt(e){return gt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},gt(e)}var wt=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&mt(e,t)}(o,e);var t,r,n,i=(r=o,n=bt(),function(){var e,t=gt(r);if(n){var i=gt(this).constructor;e=Reflect.construct(t,arguments,i)}else e=t.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,e)});function o(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(e=i.call(this,"You need to initialize before tracking events. Call Hellotext.initialize and pass your public business id")).name="NotInitializedError",e}return t=o,Object.defineProperty(t,"prototype",{writable:!1}),t}(dt(Error));function Ot(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function Pt(e,t){for(var r=0;r0&&this.collect()}},{key:"formMutationObserver",value:function(e){e.find(e=>"childList"===e.type&&e.addedNodes.length>0)&&Array.from(document.querySelectorAll("[data-hello-form]")).length>0&&this.collect()}},{key:"collect",value:(n=function*(){if(Zt.notInitialized)throw new wt;if(!this.fetching){if("undefined"==typeof document||!("querySelectorAll"in document))return console.warn("Document is not defined, collection is not possible. Please make sure to initialize the library after the document is loaded.");var e=function(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}(this,_t)[_t];if(0!==e.length){var t=e.map(e=>ce.get(e).then(e=>e.json()));this.fetching=!0,yield Promise.all(t).then(e=>e.forEach(this.add)).then(()=>Zt.eventEmitter.dispatch("forms:collected",this)).then(()=>this.fetching=!1),P.forms.autoMount&&this.forms.forEach(e=>e.mount())}}},i=function(){var e=this,t=arguments;return new Promise(function(r,i){var o=n.apply(e,t);function a(e){Ot(o,r,i,a,u,"next",e)}function u(e){Ot(o,r,i,a,u,"throw",e)}a(void 0)})},function(){return i.apply(this,arguments)})},{key:"forEach",value:function(e){this.forms.forEach(e)}},{key:"map",value:function(e){return this.forms.map(e)}},{key:"add",value:function(e){this.includes(e.id)||(Zt.business.data||(Zt.business.setData(e.business),Zt.business.setLocale(y.toString())),Zt.business.enabledWhitelist||console.warn("No whitelist has been configured. It is advised to whitelist the domain to avoid bots from submitting forms."),this.forms.push(new yt(e)))}},{key:"getById",value:function(e){return this.forms.find(t=>t.id===e)}},{key:"getByIndex",value:function(e){return this.forms[e]}},{key:"includes",value:function(e){return this.forms.some(t=>t.id===e)}},{key:"excludes",value:function(e){return!this.includes(e)}},{key:"length",get:function(){return this.forms.length}}],r&&Pt(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();function Et(){return Array.from(document.querySelectorAll("[data-hello-form]")).map(e=>e.dataset.helloForm).filter(this.excludes)}function Tt(e,t,r,n,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,i)}function xt(e,t){for(var r=0;r1&&void 0!==arguments[1]?arguments[1]:{};if(this.notInitialized)throw new wt;var r=qt(qt({},t&&t.headers||{}),this.headers),n=qt(qt({},It.identificationData),t.user_parameters||{}),i=t&&t.url?new qe(t.url):this.page,o=qt(qt({session:this.session,user_parameters:n,action:e},t),i.trackingData);return delete o.headers,yield Ce.events.create({headers:r,body:o})}),function(e){return i.apply(this,arguments)})},{key:"identify",value:(n=Bt(function*(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(It.id===e)return new X(!0,{json:(t=Bt(function*(){}),function(){return t.apply(this,arguments)})});var n=yield Ce.identifications.create(qt({user_id:e},r));return n.succeeded&&It.remember(e,r.source),n}),function(e){return n.apply(this,arguments)})},{key:"forget",value:function(){It.forget()}},{key:"on",value:function(e,t){this.eventEmitter.addSubscriber(e,t)}},{key:"removeEventListener",value:function(e,t){this.eventEmitter.removeSubscriber(e,t)}},{key:"session",get:function(){return $e.session}},{key:"isInitialized",get:function(){return void 0!==$e.session}},{key:"notInitialized",get:function(){return!this.business||void 0===this.business.id}},{key:"headers",get:function(){if(this.notInitialized)throw new wt;return{Authorization:"Bearer ".concat(this.business.id),Accept:"application/json","Content-Type":"application/json"}}}],r&&Nt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();Ut.eventEmitter=new A,Ut.forms=void 0,Ut.business=void 0,Ut.webchat=void 0;const Zt=Ut,Jt=e=>{const t=e.storePreferencesData||{},r=e.shippingData?.logisticsInfo||[],n=0===r.length?"deliver":(()=>{const e=["pickup","retir","collect","recolha","loja"];return r.some(t=>{const r=(t.selectedSla||"").toLowerCase();return"pickup-in-point"===(t.selectedDeliveryChannel||"").toLowerCase()||e.some(e=>r.includes(e))})?"collect":"deliver"})(),i=(e.items||[]).map(e=>({quantity:e.quantity,price:{amount:(e.sellingPrice||0)+(e.tax||0),currency:t.currencyCode},product:{reference:e.id,categories:Object.values(e.productCategories||{}),name:e.skuName,image_url:e.imageUrl,sku:e.id,source:"vtex",price:{amount:e.price||0,currency:t.currencyCode},brand:e.additionalInfo?.brandName,product:{reference:e.productId,name:e.name,source:"vtex",categories:Object.values(e.productCategories||{}),brand:e.additionalInfo?.brandName}}}));return{reference:e.orderGroup||e.orderFormId,source:"vtex",delivery:n,items:i}},Gt=new Set,Wt=e=>`hellotext:vtex-checkout-started:${e}`,$t={initialize:e=>{Zt.initialize(e);const t=e=>{const t=(e=>{const t=e?.clientProfileData||{},r=e?.clientPreferencesData||{},n={id:t.email,email:t.email,first_name:t.firstName,last_name:t.lastName,phone:t.phone,document:t.document,source:"vtex"};return!0===r.optinNewsLetter&&(n.subscription_state=!0),n})(e);(t.email||t.phone)&&Zt.identify(t.email||t.phone,t),async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=e?.orderFormId;if(!r||Gt.has(r)||(e=>{if(!e)return!1;try{return"1"===window.sessionStorage.getItem(Wt(e))}catch(e){return!1}})(r))return;const n={object_parameters:Jt(e),user_parameters:t};Gt.add(r);try{const e=await Zt.track("checkout.started",n);e?.succeeded&&(e=>{if(e)try{window.sessionStorage.setItem(Wt(e),"1")}catch(e){}})(r)}catch(e){}finally{Gt.delete(r)}}(e,t)};$(window).on("orderFormUpdated.vtex",(e,r)=>{t(r)}),window.vtexjs?.checkout&&vtexjs.checkout.getOrderForm().done(t)}};return t.default})()); \ No newline at end of file diff --git a/src/__tests__/confirmation.test.js b/src/__tests__/confirmation.test.js index 988c972..3af08f2 100644 --- a/src/__tests__/confirmation.test.js +++ b/src/__tests__/confirmation.test.js @@ -121,6 +121,44 @@ describe("confirmation.initialize", () => { }); }); + it("identifies newsletter opt-in from the current order form", () => { + const orderForm = createOrderForm(); + + orderForm.clientPreferencesData = { + optinNewsLetter: true, + }; + + getOrderFormMock = jest.fn(() => ({ + done: (callback) => callback(orderForm), + })); + global.window.vtexjs.checkout.getOrderForm = getOrderFormMock; + + confirmation.initialize("business-123"); + + const expectedUser = { + id: "test.user@example.com", + email: "test.user@example.com", + first_name: "Test", + last_name: "User", + phone: "+15555550123", + document: "TEST-DOC-12345", + source: "vtex", + subscription_state: true, + }; + + expect(Hellotext.identify).toHaveBeenCalledWith( + "test.user@example.com", + expectedUser, + ); + expect(Hellotext.track).toHaveBeenCalledWith("order.placed", { + user_parameters: expectedUser, + object_parameters: expect.objectContaining({ + reference: "order-group-123", + source: "vtex", + }), + }); + }); + it("only initializes Hellotext when VTEX checkout is unavailable", () => { delete global.window.vtexjs; delete global.vtexjs; diff --git a/src/__tests__/funnel.test.js b/src/__tests__/funnel.test.js index 1af090a..cda88ca 100644 --- a/src/__tests__/funnel.test.js +++ b/src/__tests__/funnel.test.js @@ -216,6 +216,33 @@ describe("funnel.initialize", () => { expect(Hellotext.track).not.toHaveBeenCalled(); }); + it("identifies newsletter opt-in changes when VTEX emits an order update event", async () => { + const updatedOrderForm = createOrderForm(); + + updatedOrderForm.clientPreferencesData = { + optinNewsLetter: true, + }; + + funnel.initialize("business-123"); + await flushAsyncWork(); + + Hellotext.identify.mockClear(); + Hellotext.track.mockClear(); + orderFormUpdatedHandler({}, updatedOrderForm); + + expect(Hellotext.identify).toHaveBeenCalledWith("test.user@example.com", { + id: "test.user@example.com", + email: "test.user@example.com", + first_name: "Test", + last_name: "User", + phone: "+15555550123", + document: "TEST-DOC-12345", + source: "vtex", + subscription_state: true, + }); + expect(Hellotext.track).not.toHaveBeenCalled(); + }); + it("tracks checkout started once per order form id", async () => { const updatedOrderForm = createOrderForm(); diff --git a/src/__tests__/utils.test.js b/src/__tests__/utils.test.js index 689f4f5..8e0e634 100644 --- a/src/__tests__/utils.test.js +++ b/src/__tests__/utils.test.js @@ -61,6 +61,32 @@ describe("extractUserData", () => { source: "vtex", }); }); + + it("maps VTEX newsletter opt-in into a Hellotext subscribe signal", () => { + const orderForm = createOrderForm(); + + orderForm.clientPreferencesData = { + optinNewsLetter: true, + }; + + expect(extractUserData(orderForm)).toEqual( + expect.objectContaining({ + subscription_state: true, + }), + ); + }); + + it("does not send a subscription state when VTEX newsletter opt-in is false", () => { + const orderForm = createOrderForm(); + + orderForm.clientPreferencesData = { + optinNewsLetter: false, + }; + + expect(extractUserData(orderForm)).not.toHaveProperty( + "subscription_state", + ); + }); }); describe("extractOrderData", () => { diff --git a/src/utils.js b/src/utils.js index e1dfac8..0cc4952 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,7 +1,8 @@ const extractUserData = (orderForm) => { const profile = orderForm?.clientProfileData || {}; + const preferences = orderForm?.clientPreferencesData || {}; - return { + const user = { id: profile.email, email: profile.email, first_name: profile.firstName, @@ -10,6 +11,12 @@ const extractUserData = (orderForm) => { document: profile.document, source: "vtex", }; + + if (preferences.optinNewsLetter === true) { + user.subscription_state = true; + } + + return user; }; const extractOrderData = (orderForm) => {