/* Use of this pixel is subject to the Amazon ad specs and policies at http://www.amazon.com/b/?&node=7253015011 */ !function(){"use strict";const t="amznToken";function e(t){this.endpoints=t,this.region="NA",this.stage="PROD",this.tags={},this.tcfv2={}}e.prototype.addTag=function(t,e){var o=null==e?t:e;this.tags[o]=t},e.prototype.getTagIds=function(t){var e=this.tags;return t.map((function(t){return e[t]||t}))},e.prototype.trackEvent=function(t,e,o){this.trackEventWithTags(t,e,o,Object.keys(this.tags))},e.prototype.trackEventWithTags=function(e,o,n,i){var s=this.getPixelEndpoint(this.region,this.stage),a=this.tcfv2;o=o||{},e?s?(n&&(o.ts=n),this.getTagIds(i).forEach((function(n){!function(e,o,n,i,s){var a=document.createElement("iframe"),r=e+"?pid="+o+"&event="+n,c=["gdpr","gdpr_pd","gdpr_consent"];if(Array.isArray(i)?r+="&items="+encodeURI(JSON.stringify(i)):i&&Object.keys(i)&&Object.keys(i).filter((function(t){return!c.includes(t)})).forEach((function(t){var e;(e=i[t])?("object"==typeof e&&(e=encodeURI(JSON.stringify(e))),r+="&"+t+"="+e):console.warn("Key "+t+" has no value")})),s&&c.forEach((function(t){s[t]&&(r+="&"+t+"="+s[t])})),document.cookie.indexOf(t)>=0){const e=document.cookie.split(";").find(e=>e.trim().startsWith(t+"="));if(void 0!==e){const o=e.substring(e.indexOf("=")+1);r+="&"+t+"="+o}}a.style.display="none",a.setAttribute("src",r),a.setAttribute("id","tag_fire_"+o+"_"+n),document.body.appendChild(a)}(s,n,e,o,a[n])}))):console.warn("No valid endpoint."):console.warn("No event specified.")},e.prototype.trackPixel=function(t,e,o){var n=this,i={};((e=(e=e||"").split("?")).length>1?e[1]:e[0]).split("&").forEach((function(t){var e,o,s=t.split("=");s.length<=1||("ex-fargs"===s[0]?(e=n.parsePixelArgs(s[1],"&"),i.fargs_id=e.id,i.fargs_type=e.type):"ex-hargs"===s[0]&&(o=n.parsePixelArgs(s[1],";"),i.hargs_c=o.c,i.hargs_p=o.p))})),this.validatePixelData(i),Object.keys(i).forEach((function(t){i[t]||delete i[t]})),this.trackEvent(t,i,o)},e.prototype.addTcfv2=function(t){this.addTcfv2WithTags(t,Object.keys(this.tags))},e.prototype.addTcfv2WithTags=function(t,e){var o=this.tcfv2;this.getTagIds(e).forEach((function(e){o[e]=t}))},e.prototype.getPixelEndpoint=function(t,e){var o,n=this.endpoints[t];return""===n||null==n?(console.warn("Endpoint does not exist, please check your region configuration!"),null):""===(o=n[e])||null==o?(console.warn("Endpoint does not exist, please check your stage configuration!"),null):o},e.prototype.parsePixelArgs=function(t,e){var o=decodeURIComponent(t),n={};return(o=o.replace(/\?/g,"")).split(e).forEach((function(t){(t=t.split("=")).length>1&&(n[t[0]]=t[1])})),n},e.prototype.validatePixelData=function(t){var e=t.hargs_c&&t.hargs_p,o=t.fargs_id&&t.fargs_type;e||o||console.warn("Invalid arguments for a trackPixel event, please check your implementation!")},e.prototype.setRegion=function(t){this.region=t},e.prototype.setStage=function(t){this.stage=t};var o=e;function n(t){this.eventTracker=t}n.prototype.proccessCommandQueue=function(t){var e=this;(t||[]).forEach((function(t){e.proccessCommand(t[0],t[1])}))},n.prototype.proccessCommand=function(t,e){var o=Array.prototype.slice.call(t),n=t[0];switch(e=e||(new Date).getTime(),n.toUpperCase()){case"TRACKEVENT":this.trackEvent(o,e);break;case"TRACKPIXEL":this.trackPixel(o,e);break;case"PIXEL":case"WITHTAG":this.withTag(o,e);break;case"ADDPIXEL":case"ADDTAG":this.addTag(o);break;case"ADDTCFV2":this.addTcfv2(o);break;case"SETREGION":this.setRegion(o);break;case"SETSTAGE":this.setStage(o);break;default:console.warn('Unsupported tag command "'+n+'"')}},n.prototype.trackEvent=function(t,e,o){var n=t[1],i=t[2];void 0!==o?this.eventTracker.trackEventWithTags(n,i,e,[o]):this.eventTracker.trackEvent(n,i,e)},n.prototype.trackPixel=function(t,e){this.eventTracker.trackPixel("__pixel__",t[1],e)},n.prototype.withTag=function(t,e){var o=t[1],n=t[2]||"";switch(n.toUpperCase()){case"TRACKEVENT":this.trackEvent(t.slice(2),e,o);break;case"ADDTCFV2":this.addTcfv2(t.slice(2),o);break;default:console.warn('Unsupported command "'+n+'" used after "withTag" command')}},n.prototype.addTag=function(t){var e=t[2],o=t[1];this.eventTracker.addTag(o,e)},n.prototype.addTcfv2=function(t,e){var o=t[1];void 0!==e?this.eventTracker.addTcfv2WithTags(o,[e]):this.eventTracker.addTcfv2(o)},n.prototype.setRegion=function(t){var e=t[1].toUpperCase();this.eventTracker.setRegion(e)},n.prototype.setStage=function(t){var e=t[1].toUpperCase();this.eventTracker.setStage(e)};var i=n;const s={method:"POST",mode:"cors",cache:"no-cache",credentials:"omit",headers:{"Content-Type":"application/json"},redirect:"follow",referrerPolicy:"no-referrer-when-downgrade"};function a(){}a.prototype.formatRequestBody=function(t){const e={};return null!==t.gdpr&&(e.gdpr=t.gdpr.enabled?1:0,null!==t.gdpr.consent&&(e.gdprConsent=t.gdpr.consent)),e.hashedRecords=t.hashedRecords,null!==t.ttl&&(e.ttl=t.ttl),e},a.prototype.requestToken=async function(t){const e={...s,body:JSON.stringify(t)},o=await fetch("https://tk.amazon-adsystem.com/envelope",e);if(o.ok){return await o.json()}const n=await o.text();throw Error(n)},a.prototype.isCookiePresent=function(t){return void 0!==document.cookie.split(";").find(e=>e.trim().startsWith(t+"="))},a.prototype.writeCookie=function(t,e,o){const n=new Date(o).toUTCString();document.cookie=`${t}=${e}; expires=${n}; SameSite=Strict; secure=true;`},a.prototype.renewToken=async function(t){if(!this.isCookiePresent("amznToken")&&!this.isCookiePresent("AMZN-NoCookieConsent"))try{const e=this.formatRequestBody(t),o=await this.requestToken(e);""===o.AIPToken?this.writeCookie("AMZN-NoCookieConsent",o.AIPToken,o.cookieExpiry):this.writeCookie("amznToken",o.AIPToken,o.cookieExpiry)}catch(t){console.error(t)}},a.prototype.deleteToken=async function(){this.isCookiePresent("amznToken")&&this.writeCookie("amznToken","0",1),this.isCookiePresent("AMZN-NoCookieConsent")&&this.writeCookie("AMZN-NoCookieConsent","0",1)},a.prototype.updateToken=async function(t){await this.deleteToken(),await this.renewToken(t)};var r=a;r.TOKEN_COOKIE_NAME="amznToken",r.NO_CONSENT_COOKIE_NAME="AMZN-NoCookieConsent";var c,p,d;c=new o({NA:{TEST:"__pixelEndpoint__",BETA:"https://s-beta.amazon-adsystem.com/iu3",GAMMA:"https://s-preprod.amazon-adsystem.com/iu3",PROD:"https://s.amazon-adsystem.com/iu3"},EU:{BETA:"",GAMMA:"",PROD:"https://aax-eu.amazon-adsystem.com/s/iu3"}}),p=new i(c),d=new r,window.amzn&&window.amzn.q&&p.proccessCommandQueue(window.amzn.q),window.amzn=function(){p.proccessCommand(arguments)},window.renewToken=function(t){d.renewToken(t)},window.updateToken=function(t){d.updateToken(t)},window.deleteToken=function(){d.deleteToken()}}();