!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */function e(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{u(r.next(e))}catch(e){i(e)}}function s(e){try{u(r.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}u((r=r.apply(e,t||[])).next())}))}function t(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&o[3]>i[1])){a.label=i[1];break}if(6===i[0]&&o[1]>a.label){a.label=o[1],o=i;break}if(o&&o[2]>a.label){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var n,r=new Uint8Array(16);function o(){if(!n&&!(n="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return n(r)}var i=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function a(e){return"string"==typeof e&&i.test(e)}for(var s=[],u=0;256>u;++u)s.push((u+256).toString(16).substr(1));function c(e,t,n){var r=(e=e||{}).random||(e.rng||o)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var i=0;16>i;++i)t[n+i]=r[i];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(s[e[t+0]]+s[e[t+1]]+s[e[t+2]]+s[e[t+3]]+"-"+s[e[t+4]]+s[e[t+5]]+"-"+s[e[t+6]]+s[e[t+7]]+"-"+s[e[t+8]]+s[e[t+9]]+"-"+s[e[t+10]]+s[e[t+11]]+s[e[t+12]]+s[e[t+13]]+s[e[t+14]]+s[e[t+15]]).toLowerCase();if(!a(n))throw TypeError("Stringified UUID is invalid");return n}(r)}var l=function(){return{get:function(e){var t=("; "+document.cookie).split("; "+e+"=");if(2===t.length)return t.pop().split(";").shift()}}},d=function(e){return{get:function(t){return e.getItem(t)},set:function(t,n){e.setItem(t,n)},remove:function(t){e.removeItem(t)},clear:function(){e.clear()}}},p=function(){var e,t=document.cookie.split("; ").find((function(e){return e.includes("BOM-CART_ID")}));if(void 0!==t){var n=t.split("BOM-CART_ID=")[1];if(void 0!==n){var r=void 0;try{r=atob(n)}catch(e){r=n}e=r.split("/")[r.split("/").length-1].split("?")[0]}}return e},f=function(e){return e.includes("allbirds")?6048e5:864e5},m=function(){var e={};return window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi,(function(t,n,r){return e[n.toLowerCase()]=r,""})),e},g="peets-coffee.myshopify.com",v=function(e){return"wearebombas.com".split(",").includes(e)},y=function(e){return!!e&&(e.includes("/cart/add")||e.includes("/cart/change")||e.includes("/cart/update"))};function h(e,t,n,r){void 0===r&&(r=1e3);var o=t.map((function(t){return e.get(t)}));setInterval((function(){var r,i,a=t.map((function(t){return e.get(t)}));if(i=a,!(Array.isArray(r=o)&&Array.isArray(i)&&(null==r?void 0:r.length)===(null==i?void 0:i.length)&&(null==r?void 0:r.every((function(e,t){return e===(null==i?void 0:i[t])})))))try{n()}finally{o=a}}),r)}var b=function(e){try{return JSON.parse(e)}catch(e){return console.warn(e),{}}},w=function(n,r,o,i){return e(void 0,void 0,void 0,(function(){var e,a,s,u,c;return t(this,(function(t){switch(t.label){case 0:e=""+(i||"https://prod-consumer-app.integrations-itbl.co")+n,t.label=1;case 1:return t.trys.push([1,7,,8]),[4,fetch(e,r)];case 2:if(a=t.sent(),s=a.status,u=a.statusText,a.ok)return[3,3];throw Error("An error has occured when making request to "+e+". Response status is "+s+" "+u);case 3:return t.trys.push([3,5,,6]),[4,a.json()];case 4:return function(e){try{JSON.parse(JSON.stringify(e))}catch(e){return!1}return!0}(c=t.sent())&&"function"==typeof o&&o(c),[3,6];case 5:return t.sent(),[3,6];case 6:return[3,8];case 7:return t.sent(),[3,8];case 8:return[2]}}))}))},S=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,I=function(e){return S.test((e+"").toLowerCase())},T="login",k="logout",_="productView",C=function(e){return null==e},E=function(n,r,o){var i=o.currentUrl,a=o.customerId,s={updateSession:function(){var e=n.get("session_id"),t={marketingFields:s.getMarketingValues(),shop:g,createdAt:Date.now()};C(a)||a+""===n.get("customerId")||(n.set("customerId",a),t.customerId=a+""),C(e)||w("/sessions/"+e,{method:"PUT",body:JSON.stringify(t)})},createEvent:function(e){var t={type:e,source:g,sessionId:n.get("session_id"),payload:{url:i,marketingFields:s.getMarketingValues()}};w("/events/custom",{method:"POST",body:JSON.stringify(t)})},getMarketingValues:function(){for(var e=["iterableEmailCampaignId","iterableEndUserId","iterableMessageId","iterableTemplateId"],t={},n=e.length,o=0;n>o;o++)t[e[o]]=r.get(e[o]);return r.get("iterableTemplateIdTemp")&&(t.iterableTemplateId=r.get("iterableTemplateIdTemp")),r.get("iterableEmailCampaignIdTemp")&&(t.iterableEmailCampaignId=r.get("iterableEmailCampaignIdTemp")),t},logout:function(){s.createEvent(k),n.set("session_id",c()),s.checkCartToken()},login:function(r){return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return n.get("session_id")?[3,2]:(n.set("session_id",c()),[4,s.checkCartToken()]);case 1:t.sent(),t.label=2;case 2:return e={type:T,source:g,sessionId:n.get("session_id"),payload:{email:r,url:window.location.href}},w("/events/custom",{method:"POST",body:JSON.stringify(e)}),[2]}}))}))},setSessionAlias:function(){var e=n.get("session_id"),t=n.get("cart_token")||p()||r.get("cart");t&&(t!==r.get("cart")&&t!==n.get("cart_token")||(t=function(e){var t=decodeURIComponent(e),n=t.indexOf("?key=");return-1!==n?t.substring(0,n):t}(t)),w("/sessions/"+e+"/alias",{method:"POST",body:JSON.stringify({alias:t,shop:g})}))},checkCartToken:function(){return e(this,void 0,void 0,(function(){var r,o=this;return t(this,(function(i){switch(i.label){case 0:return v(g)?void 0===(r=p())?[3,2]:(n.set("cart_token",r),[4,s.setSessionAlias()]):[3,3];case 1:i.sent(),i.label=2;case 2:return[3,5];case 3:return[4,w("/cart.js",{method:"GET"},(function(r){return e(o,void 0,void 0,(function(){return t(this,(function(e){switch(e.label){case 0:return r.item_count>0?(n.set("cart_token",r.token),[4,s.setSessionAlias()]):[3,2];case 1:e.sent(),e.label=2;case 2:return[2]}}))}))}),"https://"+window.location.hostname)];case 4:i.sent(),i.label=5;case 5:return[2]}}))}))}};return s},A=function(){var n,r,o;console.log("Tracking script 1.0.15 - August 22, 2024 18:36:20");var i=null;"undefined"!=typeof customer_id?i=customer_id:(console.warn("Iterable Connector: customer_id is not defined."),i=null===(o=null===(r=null===(n=window.ShopifyAnalytics)||void 0===n?void 0:n.meta)||void 0===r?void 0:r.page)||void 0===o?void 0:o.customerId);var a=window.location.href,s=m(),u=s.iterable_campaign,p=/^campaign_\d*$/.test(s.utm_campaign)?(s.utm_campaign||"").split("_")[1]:"",v=s.iterable_template,w=s.utm_userid,S=new Date;S.setTime(S.getTime()+f(g));var T="expires="+S.toUTCString();v&&(document.cookie="iterableTemplateIdTemp="+v+"; path=/;"+T);var k=u||p;k&&(document.cookie="iterableEmailCampaignIdTemp="+k+"; path=/;"+T),w&&(document.cookie="iterableUserId="+w+"; path=/;"+T);var C=d(localStorage),A=l();C.get("session_id")||C.set("session_id",c());var q=E(C,A,{currentUrl:a,customerId:i});(A.get("cart")||A.get("BOM-CART_ID"))&&C.get("session_id")&&q.setSessionAlias(),q.updateSession();h(A,["iterableEmailCampaignId","iterableEmailCampaignIdTemp","iterableEndUserId","iterableMessageId","iterableTemplateId","iterableTemplateIdTemp"],q.updateSession),setTimeout((function(){var e,t=null===(e=null==a?void 0:a.split("?"))||void 0===e?void 0:e[0];(null==t?void 0:t.includes("/products/"))&&q.createEvent(_)}),1e3);var O=window.fetch;window.fetch=function(){for(var n=[],r=0;arguments.length>r;r++)n[r]=arguments[r];return e(void 0,void 0,void 0,(function(){var e,r,o,i,a,s,u,c;return t(this,(function(t){switch(t.label){case 0:return r=n[1],i=(null==(o="string"==typeof(e=n[0])?e:(null==e?void 0:e.url)||"")?void 0:o.includes("/identity/sign-in"))||(null==o?void 0:o.includes("/identity/create")),a="",i&&"string"==typeof(null==r?void 0:r.body)&&"object"==typeof(s=b((null==r?void 0:r.body)||"{}"))&&null!==s&&(a=s.email),[4,O(e,r)];case 1:return u=t.sent(),(c=u.ok)&&y(o)&&q.checkCartToken(),c&&i&&a&&I(a)&&q.login(a),c&&(null==o?void 0:o.includes("/identity/sign-out"))&&q.logout(),[2,u]}}))}))},XMLHttpRequest.prototype.realSend=XMLHttpRequest.prototype.send,XMLHttpRequest.prototype.send=function(e){this.addEventListener("load",(function(){y(this.responseURL)&&q.checkCartToken()}),!1),this.realSend(e)};var R=document.querySelector('a[href="/account/logout"]');R&&R.addEventListener("click",q.logout);var U=function(e){var t=e.target.querySelector("input#CustomerEmail")||e.target.querySelector("input#customer_email")||e.target.querySelector('input[name="customer[email]"]')||e.target.querySelector('input[type="email"]'),n=t?t.value:"";n&&I(n)&&q.login(n)};(function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;i>o;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))})([],document.querySelectorAll("form"),!0).forEach((function(e){var t=e.querySelector("input#CustomerEmail")||e.querySelector("input#customer_email")||e.querySelector('input[name="customer[email]"]')||e.querySelector('input[type="email"]'),n=e.querySelector("input#CustomerPassword")||e.querySelector("input#customer_password")||e.querySelector('input[name="customer[password]"]')||e.querySelector('input[type="password"]');t&&n&&e.addEventListener("submit",U)}))};"loading"!==document.readyState?A():document.onreadystatechange=function(){"interactive"===document.readyState&&A()}}));