芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/thefirstcookout.com/assets/amzn.js
/* Use of this pixel is subject to the Amazon ad specs and policies at http://www.amazon.com/b/?&node=7253015011. Version number: 6, Changeset: Adding in phone number support for setUserData */ this.amzn=this.amzn||{},this.amzn.js=function(){"use strict";var e={nameLength:256,valueLength:1e3,eventNameLengthWarning:"Event name is longer than 256 characters.",parameterNameLengthWarning:"Length of parameter name exceeds 256 characters.",parameterValueLengthWarning:"Length of parameter value exceeds 1000 characters.",parameterKeyLengthWarning:"Length of parameter key exceeds 256 characters.",AIP_TOKEN_COOKIE_NAME:"aatToken",AIP_TOKEN_URL_QUERY_PARAM_NAME:"amznToken",NO_CONSENT_COOKIE_NAME:"AMZN-NoCookieConsent"};const t=e;function n(e){this.endpoints=e,this.region="NA",this.stage="PROD",this.tags={},this.tcfv2={}}n.prototype.addTag=function(e,t){const n=null==t?e:t;this.tags[n]=e},n.prototype.getTagIds=function(e){const{tags:t}=this;return e.map((function(e){return t[e]||e}))},n.prototype.trackEvent=function(e,t,n){this.trackEventWithTags(e,t,n,Object.keys(this.tags))},n.prototype.trackEventWithTags=function(e,n,o,r){const s=this.getPixelEndpoint(this.region),{tcfv2:a}=this,i=n||{};e?s?(o&&(i.ts=o),this.getTagIds(r).forEach((n=>{!function(e,n,o,r,s){const a=document.createElement("iframe");let i=`${e}?pid=${n}&event=${o}`;const c=["gdpr","gdpr_pd","gdpr_consent"],h=[];if(o.length>t.nameLength&&h.push(`${t.eventNameLengthWarning}, ${o}`),Array.isArray(r)?(r.forEach((function(e){Object.keys(e)[0].length>t.nameLength&&h.push(`${t.parameterNameLengthWarning}, ${Object.keys(e)[0]}`),e[Object.keys(e)[0]].length>t.valueLength&&h.push(`${t.parameterValueLengthWarning}, ${e[Object.keys(e)[0]]}`)})),i+=`&items=${encodeURI(JSON.stringify(r))}`):r&&Object.keys(r)&&Object.keys(r).filter((function(e){return!c.includes(e)})).forEach((function(e){let n;e.length>t.nameLength&&h.push(`${t.parameterNameLengthWarning}, ${e}`),n=r[e],n||""===n?(n.length>t.valueLength?h.push(`${t.parameterValueLengthWarning}, ${n}`):Object.keys(n)&&Object.keys(n)[0]&&Object.keys(n).forEach((function(e){e.length>t.nameLength&&h.push(`${t.parameterKeyLengthWarning}, ${e}`),n[e].length>t.valueLength&&h.push(`${t.parameterValueLengthWarning}, ${n[e]}`)})),"object"==typeof n&&(n=encodeURI(JSON.stringify(n))),i+=`&${e}=${n}`):console.warn(`Key ${e} has no value`)})),h.length>0)return console.warn(`Event has ${h.length} validation errors.`),console.warn(h),!1;if(s&&c.forEach((function(e){s[e]&&(i+=`&${e}=${s[e]}`)})),document.cookie.indexOf(t.AIP_TOKEN_COOKIE_NAME)>=0){const e=document.cookie.split(";").find((e=>e.trim().startsWith(`${t.AIP_TOKEN_COOKIE_NAME}=`)));if(void 0!==e){const n=e.substring(e.indexOf("=")+1);i+=`&${t.AIP_TOKEN_URL_QUERY_PARAM_NAME}=${n}`}}a.style.display="none",a.setAttribute("src",i),a.setAttribute("id",`tag_fire_${n}_${o}`),document.body.appendChild(a)}(s,n,e,i,a[n])}))):console.warn("No valid endpoint."):console.warn("No event specified.")},n.prototype.trackPixel=function(e,t,n){const o=this;let r;const s={};let a=t||"";a=a.split("?"),r=a.length>1?a[1]:a[0],r=r.split("&"),r.forEach((function(e){const t=e.split("=");let n,r;t.length<=1||("ex-fargs"===t[0]?(n=o.parsePixelArgs(t[1],"&"),s.fargs_id=n.id,s.fargs_type=n.type):"ex-hargs"===t[0]&&(r=o.parsePixelArgs(t[1],";"),s.hargs_c=r.c,s.hargs_p=r.p))})),this.validatePixelData(s),Object.keys(s).forEach((function(e){s[e]||delete s[e]})),this.trackEvent(e,s,n)},n.prototype.addTcfv2=function(e){this.addTcfv2WithTags(e,Object.keys(this.tags))},n.prototype.addTcfv2WithTags=function(e,t){const{tcfv2:n}=this;this.getTagIds(t).forEach((function(t){n[t]=e}))},n.prototype.getPixelEndpoint=function(e){const t=this.endpoints[e.toUpperCase()];return""===t||null==t?(console.warn("Endpoint does not exist, please check your region configuration!"),null):t},n.prototype.parsePixelArgs=function(e,t){let n=decodeURIComponent(e);const o={};return n=n.replace(/\?/g,""),n.split(t).forEach((function(e){const t=e.split("=");if(t.length>1){const[e,n]=t;o[e]=n}})),o},n.prototype.validatePixelData=function(e){const t=e.hargs_c&&e.hargs_p,n=e.fargs_id&&e.fargs_type;t||n||console.warn("Invalid arguments for a trackPixel event, please check your implementation!")},n.prototype.setRegion=function(e){this.region=e},n.prototype.setStage=function(e){this.stage=e};var o=n;function r(e,t,n){this.eventTracker=e,this.setUserDataHandler=t,this.aatEventsQueue=[],this.isSetUserDataInProcess=!1}r.prototype.proccessCommandQueue=function(e){const t=this;(e||[]).forEach((function(e){t.proccessCommand(e[0],e[1])}))},r.prototype.proccessCommand=function(e,t=(new Date).getTime()){const n=Array.prototype.slice.call(e),o=e[0];switch(o.toUpperCase()){case"TRACKEVENT":this.trackEvent(n,t);break;case"TRACKPIXEL":this.trackPixel(n,t);break;case"PIXEL":case"WITHTAG":this.withTag(n,t);break;case"ADDPIXEL":case"ADDTAG":this.addTag(n);break;case"ADDTCFV2":this.addTcfv2(n);break;case"SETREGION":this.setRegion(n);break;case"SETSTAGE":this.setStage(n);break;case"SETUSERDATA":this.setUserData(n);break;default:console.warn(`Unsupported tag command "${o}"`)}},r.prototype.setUserData=async function(e){this.isSetUserDataInProcess=!0,this.setUserDataHandler.setUserData(e).then((()=>{this.isSetUserDataInProcess=!1,this.processAatEventsQueue()}))},r.prototype.processAatEventsQueue=function(){if(this.aatEventsQueue.length)for(;this.aatEventsQueue.length;)try{const{argumentArray:e,timestamp:t,tagLabel:n}=this.aatEventsQueue.pop();this.trackEvent(e,t,n)}catch(e){console.warn(e)}},r.prototype.trackEvent=function(e,t,n){if(this.isSetUserDataInProcess)return void this.aatEventsQueue.unshift({argumentArray:e,timestamp:t,tagLabel:n});const o=e[1],r=e[2];void 0!==n?this.eventTracker.trackEventWithTags(o,r,t,[n]):this.eventTracker.trackEvent(o,r,t)},r.prototype.trackPixel=function(e,t){this.eventTracker.trackPixel("__pixel__",e[1],t)},r.prototype.withTag=function(e,t){const n=e[1],o=e[2]||"";switch(o.toUpperCase()){case"TRACKEVENT":this.trackEvent(e.slice(2),t,n);break;case"ADDTCFV2":this.addTcfv2(e.slice(2),n);break;default:console.warn(`Unsupported command "${o}" used after "withTag" command`)}},r.prototype.addTag=function(e){const t=e[2],n=e[1];this.eventTracker.addTag(n,t)},r.prototype.addTcfv2=function(e,t){const n=e[1];void 0!==t?this.eventTracker.addTcfv2WithTags(n,[t]):this.eventTracker.addTcfv2(n)},r.prototype.setRegion=function(e){const t=e[1].toUpperCase();this.eventTracker.setRegion(t)},r.prototype.setStage=function(e){const t=e[1].toUpperCase();this.eventTracker.setStage(t)},r.prototype.listen=function(){this.eventListener.init()};var s=r;const a=e,i="AIPToken",c="cookieExpiry",h={method:"POST",mode:"cors",cache:"no-cache",credentials:"omit",headers:{"Content-Type":"application/json"},redirect:"follow",referrerPolicy:"no-referrer-when-downgrade"};function p(){}p.prototype.formatRequestBody=function(e){const t={};if(null!==e.gdpr&&(t.gdpr=e.gdpr.enabled?1:0,null!==e.gdpr.consent&&(t.gdprConsent=e.gdpr.consent)),null===e.hashedRecords)throw Error("hashedRecords array is null");if(0===e.hashedRecords.length)throw Error("hashedRecords array is empty");return t.hashedRecords=e.hashedRecords,null!==e.ttl&&(t.ttl=e.ttl),t},p.prototype.requestToken=async function(e){const t={...h,body:JSON.stringify(e)},n=await fetch("https://tk.amazon-adsystem.com/envelope",t);if(n.ok){return await n.json()}const o=await n.text();throw Error(o)},p.prototype.isCookiePresent=function(e){return void 0!==document.cookie.split(";").find((t=>t.trim().startsWith(`${e}=`)))},p.prototype.writeCookie=function(e,t,n){const o=new Date(n).toUTCString();document.cookie=`${e}=${t}; expires=${o}; SameSite=Strict; secure=true;`},p.prototype.renewToken=async function(e){if(!this.isCookiePresent(a.AIP_TOKEN_COOKIE_NAME)&&!this.isCookiePresent(a.NO_CONSENT_COOKIE_NAME))try{const t=this.formatRequestBody(e),n=await this.requestToken(t);return""===n[i]?this.writeCookie(a.NO_CONSENT_COOKIE_NAME,n[i],n[c]):this.writeCookie(a.AIP_TOKEN_COOKIE_NAME,n[i],n[c]),n}catch(e){console.error(e)}return"no-op"},p.prototype.deleteToken=async function(){this.isCookiePresent(a.AIP_TOKEN_COOKIE_NAME)&&this.writeCookie(a.AIP_TOKEN_COOKIE_NAME,"0",1),this.isCookiePresent(a.NO_CONSENT_COOKIE_NAME)&&this.writeCookie(a.NO_CONSENT_COOKIE_NAME,"0",1)},p.prototype.updateToken=async function(e){return await this.deleteToken(),this.renewToken(e)};var u=p;function d(e){this.tokenHandler=e}async function l(e){const t=(new TextEncoder).encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map((e=>e.toString(16).padStart(2,"0"))).join("")}function g(e){return null!=e&&"string"==typeof e&&e.length>0}d.prototype.setUserData=async function(e){const t={gdpr:{enabled:!1,consent:""},hashedRecords:[],ttl:9600},n=e[1];n.gdpr&&(t.gdpr=n.gdpr),n.ttl&&(t.ttl=n.ttl);const o=/\b[A-Fa-f0-9]{64}\b/;if(g(n.email)){const e={type:"email",record:""};n.email=n.email.trim().toLowerCase(),o.test(n.email)?e.record=n.email:await l(n.email).then((t=>{e.record=t})),t.hashedRecords.push(e)}if(g(n.phonenumber)){const e={type:"phonenumber",record:""};o.test(n.phonenumber)?e.record=n.phonenumber:await l(function(e){let t=e.replace(/[^\d+]+/g,"");return t=t.replace(/^00/,"+"),t.match(/^1/)&&(t=`+${t}`),t.match(/^\+/)||(t=`+1${t}`),t=t.replace(/^\+/,""),t}(n.phonenumber)).then((t=>{e.record=t})),t.hashedRecords.push(e)}return t.hashedRecords.length>0?this.tokenHandler.updateToken(t):"no-op"};const f=o,m=s,y=u,E=d,k={NA:"https://s.amazon-adsystem.com/iu3",EU:"https://aax-eu.amazon-adsystem.com/s/iu3",FE:"https://aax-fe.amazon-adsystem.com/s/iu3"};return function(){const e=new f(k),t=new y,n=new E(t);let o=new m(e,n);window.amzn&&window.amzn.q&&o.proccessCommandQueue(window.amzn.q),window.amzn=function(...e){o.proccessCommand(e)},window.renewToken=async function(e){return t.renewToken(e)},window.updateToken=async function(e){return t.updateToken(e)},window.deleteToken=async function(){return t.deleteToken()}}(),{}}();