UNPKG

ba-js-tracker

Version:

9 lines (8 loc) 25.1 kB
(function(v,O){typeof exports=="object"&&typeof module!="undefined"?O(exports):typeof define=="function"&&define.amd?define(["exports"],O):(v=typeof globalThis!="undefined"?globalThis:v||self,O(v.baJsTracker={}))})(this,function(v){"use strict";var ar=Object.defineProperty,ir=Object.defineProperties;var dr=Object.getOwnPropertyDescriptors;var de=Object.getOwnPropertySymbols;var $e=Object.prototype.hasOwnProperty,xe=Object.prototype.propertyIsEnumerable;var Ce=(v,O,_)=>O in v?ar(v,O,{enumerable:!0,configurable:!0,writable:!0,value:_}):v[O]=_,M=(v,O)=>{for(var _ in O||(O={}))$e.call(O,_)&&Ce(v,_,O[_]);if(de)for(var _ of de(O))xe.call(O,_)&&Ce(v,_,O[_]);return v},H=(v,O)=>ir(v,dr(O));var Z=(v,O)=>{var _={};for(var j in v)$e.call(v,j)&&O.indexOf(j)<0&&(_[j]=v[j]);if(v!=null&&de)for(var j of de(v))O.indexOf(j)<0&&xe.call(v,j)&&(_[j]=v[j]);return _};var ne=(v,O,_)=>new Promise((j,Q)=>{var oe=T=>{try{z(_.next(T))}catch(X){Q(X)}},se=T=>{try{z(_.throw(T))}catch(X){Q(X)}},z=T=>T.done?j(T.value):Promise.resolve(T.value).then(oe,se);z((_=_.apply(v,O)).next())});var O={exports:{}};/*! * JavaScript Cookie v2.2.1 * https://github.com/js-cookie/js-cookie * * Copyright 2006, 2015 Klaus Hartl & Fagner Brack * Released under the MIT license */(function(e,r){(function(t){var c;if(e.exports=t(),c=!0,!c){var d=window.Cookies,u=window.Cookies=t();u.noConflict=function(){return window.Cookies=d,u}}})(function(){function t(){for(var u=0,g={};u<arguments.length;u++){var h=arguments[u];for(var b in h)g[b]=h[b]}return g}function c(u){return u.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}function d(u){function g(){}function h(y,m,p){if(typeof document!="undefined"){p=t({path:"/"},g.defaults,p),typeof p.expires=="number"&&(p.expires=new Date(new Date*1+p.expires*864e5)),p.expires=p.expires?p.expires.toUTCString():"";try{var E=JSON.stringify(m);/^[\{\[]/.test(E)&&(m=E)}catch(F){}m=u.write?u.write(m,y):encodeURIComponent(String(m)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),y=encodeURIComponent(String(y)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var I="";for(var A in p)!p[A]||(I+="; "+A,p[A]!==!0&&(I+="="+p[A].split(";")[0]));return document.cookie=y+"="+m+I}}function b(y,m){if(typeof document!="undefined"){for(var p={},E=document.cookie?document.cookie.split("; "):[],I=0;I<E.length;I++){var A=E[I].split("="),F=A.slice(1).join("=");!m&&F.charAt(0)==='"'&&(F=F.slice(1,-1));try{var B=c(A[0]);if(F=(u.read||u)(F,B)||c(F),m)try{F=JSON.parse(F)}catch(Y){}if(p[B]=F,y===B)break}catch(Y){}}return y?p[y]:p}}return g.set=h,g.get=function(y){return b(y,!1)},g.getJSON=function(y){return b(y,!0)},g.remove=function(y,m){h(y,"",t(m,{expires:-1}))},g.defaults={},g.withConverter=d,g}return d(function(){})})})(O);var _=O.exports,j={exports:{}},Q=typeof crypto!="undefined"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto!="undefined"&&typeof window.msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto);if(Q){var oe=new Uint8Array(16);j.exports=function(){return Q(oe),oe}}else{var se=new Array(16);j.exports=function(){for(var r=0,t;r<16;r++)(r&3)===0&&(t=Math.random()*4294967296),se[r]=t>>>((r&3)<<3)&255;return se}}for(var z=[],T=0;T<256;++T)z[T]=(T+256).toString(16).substr(1);function X(e,r){var t=r||0,c=z;return[c[e[t++]],c[e[t++]],c[e[t++]],c[e[t++]],"-",c[e[t++]],c[e[t++]],"-",c[e[t++]],c[e[t++]],"-",c[e[t++]],c[e[t++]],"-",c[e[t++]],c[e[t++]],c[e[t++]],c[e[t++]],c[e[t++]],c[e[t++]]].join("")}var je=X,Ie=j.exports,Fe=je;function Pe(e,r,t){var c=r&&t||0;typeof e=="string"&&(r=e==="binary"?new Array(16):null,e=null),e=e||{};var d=e.random||(e.rng||Ie)();if(d[6]=d[6]&15|64,d[8]=d[8]&63|128,r)for(var u=0;u<16;++u)r[c+u]=d[u];return r||Fe(d)}var Re=Pe,K={},Ue=e=>encodeURIComponent(e).replace(/[!'()*]/g,r=>`%${r.charCodeAt(0).toString(16).toUpperCase()}`),me="%[a-f0-9]{2}",he=new RegExp(me,"gi"),pe=new RegExp("("+me+")+","gi");function fe(e,r){try{return decodeURIComponent(e.join(""))}catch(d){}if(e.length===1)return e;r=r||1;var t=e.slice(0,r),c=e.slice(r);return Array.prototype.concat.call([],fe(t),fe(c))}function Me(e){try{return decodeURIComponent(e)}catch(c){for(var r=e.match(he),t=1;t<r.length;t++)e=fe(r,t).join(""),r=e.match(he);return e}}function Te(e){for(var r={"%FE%FF":"\uFFFD\uFFFD","%FF%FE":"\uFFFD\uFFFD"},t=pe.exec(e);t;){try{r[t[0]]=decodeURIComponent(t[0])}catch(h){var c=Me(t[0]);c!==t[0]&&(r[t[0]]=c)}t=pe.exec(e)}r["%C2"]="\uFFFD";for(var d=Object.keys(r),u=0;u<d.length;u++){var g=d[u];e=e.replace(new RegExp(g,"g"),r[g])}return e}var Ne=function(e){if(typeof e!="string")throw new TypeError("Expected `encodedURI` to be of type `string`, got `"+typeof e+"`");try{return e=e.replace(/\+/g," "),decodeURIComponent(e)}catch(r){return Te(e)}},Le=(e,r)=>{if(!(typeof e=="string"&&typeof r=="string"))throw new TypeError("Expected the arguments to be of type `string`");if(r==="")return[e];const t=e.indexOf(r);return t===-1?[e]:[e.slice(0,t),e.slice(t+r.length)]},Ge=function(e,r){for(var t={},c=Object.keys(e),d=Array.isArray(r),u=0;u<c.length;u++){var g=c[u],h=e[g];(d?r.indexOf(g)!==-1:r(g,h,e))&&(t[g]=h)}return t};(function(e){const r=Ue,t=Ne,c=Le,d=Ge,u=s=>s==null,g=Symbol("encodeFragmentIdentifier");function h(s){switch(s.arrayFormat){case"index":return i=>(n,o)=>{const a=n.length;return o===void 0||s.skipNull&&o===null||s.skipEmptyString&&o===""?n:o===null?[...n,[m(i,s),"[",a,"]"].join("")]:[...n,[m(i,s),"[",m(a,s),"]=",m(o,s)].join("")]};case"bracket":return i=>(n,o)=>o===void 0||s.skipNull&&o===null||s.skipEmptyString&&o===""?n:o===null?[...n,[m(i,s),"[]"].join("")]:[...n,[m(i,s),"[]=",m(o,s)].join("")];case"colon-list-separator":return i=>(n,o)=>o===void 0||s.skipNull&&o===null||s.skipEmptyString&&o===""?n:o===null?[...n,[m(i,s),":list="].join("")]:[...n,[m(i,s),":list=",m(o,s)].join("")];case"comma":case"separator":case"bracket-separator":{const i=s.arrayFormat==="bracket-separator"?"[]=":"=";return n=>(o,a)=>a===void 0||s.skipNull&&a===null||s.skipEmptyString&&a===""?o:(a=a===null?"":a,o.length===0?[[m(n,s),i,m(a,s)].join("")]:[[o,m(a,s)].join(s.arrayFormatSeparator)])}default:return i=>(n,o)=>o===void 0||s.skipNull&&o===null||s.skipEmptyString&&o===""?n:o===null?[...n,m(i,s)]:[...n,[m(i,s),"=",m(o,s)].join("")]}}function b(s){let i;switch(s.arrayFormat){case"index":return(n,o,a)=>{if(i=/\[(\d*)\]$/.exec(n),n=n.replace(/\[\d*\]$/,""),!i){a[n]=o;return}a[n]===void 0&&(a[n]={}),a[n][i[1]]=o};case"bracket":return(n,o,a)=>{if(i=/(\[\])$/.exec(n),n=n.replace(/\[\]$/,""),!i){a[n]=o;return}if(a[n]===void 0){a[n]=[o];return}a[n]=[].concat(a[n],o)};case"colon-list-separator":return(n,o,a)=>{if(i=/(:list)$/.exec(n),n=n.replace(/:list$/,""),!i){a[n]=o;return}if(a[n]===void 0){a[n]=[o];return}a[n]=[].concat(a[n],o)};case"comma":case"separator":return(n,o,a)=>{const l=typeof o=="string"&&o.includes(s.arrayFormatSeparator),f=typeof o=="string"&&!l&&p(o,s).includes(s.arrayFormatSeparator);o=f?p(o,s):o;const w=l||f?o.split(s.arrayFormatSeparator).map(S=>p(S,s)):o===null?o:p(o,s);a[n]=w};case"bracket-separator":return(n,o,a)=>{const l=/(\[\])$/.test(n);if(n=n.replace(/\[\]$/,""),!l){a[n]=o&&p(o,s);return}const f=o===null?[]:o.split(s.arrayFormatSeparator).map(w=>p(w,s));if(a[n]===void 0){a[n]=f;return}a[n]=[].concat(a[n],f)};default:return(n,o,a)=>{if(a[n]===void 0){a[n]=o;return}a[n]=[].concat(a[n],o)}}}function y(s){if(typeof s!="string"||s.length!==1)throw new TypeError("arrayFormatSeparator must be single character string")}function m(s,i){return i.encode?i.strict?r(s):encodeURIComponent(s):s}function p(s,i){return i.decode?t(s):s}function E(s){return Array.isArray(s)?s.sort():typeof s=="object"?E(Object.keys(s)).sort((i,n)=>Number(i)-Number(n)).map(i=>s[i]):s}function I(s){const i=s.indexOf("#");return i!==-1&&(s=s.slice(0,i)),s}function A(s){let i="";const n=s.indexOf("#");return n!==-1&&(i=s.slice(n)),i}function F(s){s=I(s);const i=s.indexOf("?");return i===-1?"":s.slice(i+1)}function B(s,i){return i.parseNumbers&&!Number.isNaN(Number(s))&&typeof s=="string"&&s.trim()!==""?s=Number(s):i.parseBooleans&&s!==null&&(s.toLowerCase()==="true"||s.toLowerCase()==="false")&&(s=s.toLowerCase()==="true"),s}function Y(s,i){i=Object.assign({decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1},i),y(i.arrayFormatSeparator);const n=b(i),o=Object.create(null);if(typeof s!="string"||(s=s.trim().replace(/^[?#&]/,""),!s))return o;for(const a of s.split("&")){if(a==="")continue;let[l,f]=c(i.decode?a.replace(/\+/g," "):a,"=");f=f===void 0?null:["comma","separator","bracket-separator"].includes(i.arrayFormat)?f:p(f,i),n(p(l,i),f,o)}for(const a of Object.keys(o)){const l=o[a];if(typeof l=="object"&&l!==null)for(const f of Object.keys(l))l[f]=B(l[f],i);else o[a]=B(l,i)}return i.sort===!1?o:(i.sort===!0?Object.keys(o).sort():Object.keys(o).sort(i.sort)).reduce((a,l)=>{const f=o[l];return Boolean(f)&&typeof f=="object"&&!Array.isArray(f)?a[l]=E(f):a[l]=f,a},Object.create(null))}e.extract=F,e.parse=Y,e.stringify=(s,i)=>{if(!s)return"";i=Object.assign({encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:","},i),y(i.arrayFormatSeparator);const n=f=>i.skipNull&&u(s[f])||i.skipEmptyString&&s[f]==="",o=h(i),a={};for(const f of Object.keys(s))n(f)||(a[f]=s[f]);const l=Object.keys(a);return i.sort!==!1&&l.sort(i.sort),l.map(f=>{const w=s[f];return w===void 0?"":w===null?m(f,i):Array.isArray(w)?w.length===0&&i.arrayFormat==="bracket-separator"?m(f,i)+"[]":w.reduce(o(f),[]).join("&"):m(f,i)+"="+m(w,i)}).filter(f=>f.length>0).join("&")},e.parseUrl=(s,i)=>{i=Object.assign({decode:!0},i);const[n,o]=c(s,"#");return Object.assign({url:n.split("?")[0]||"",query:Y(F(s),i)},i&&i.parseFragmentIdentifier&&o?{fragmentIdentifier:p(o,i)}:{})},e.stringifyUrl=(s,i)=>{i=Object.assign({encode:!0,strict:!0,[g]:!0},i);const n=I(s.url).split("?")[0]||"",o=e.extract(s.url),a=e.parse(o,{sort:!1}),l=Object.assign(a,s.query);let f=e.stringify(l,i);f&&(f=`?${f}`);let w=A(s.url);return s.fragmentIdentifier&&(w=`#${i[g]?m(s.fragmentIdentifier,i):s.fragmentIdentifier}`),`${n}${f}${w}`},e.pick=(s,i,n)=>{n=Object.assign({parseFragmentIdentifier:!0,[g]:!1},n);const{url:o,query:a,fragmentIdentifier:l}=e.parseUrl(s,n);return e.stringifyUrl({url:o,query:d(a,i),fragmentIdentifier:l},n)},e.exclude=(s,i,n)=>{const o=Array.isArray(i)?a=>!i.includes(a):(a,l)=>!i(a,l);return e.pick(s,o,n)}})(K);var Ve=function(r){return qe(r)&&!ke(r)};function qe(e){return!!e&&typeof e=="object"}function ke(e){var r=Object.prototype.toString.call(e);return r==="[object RegExp]"||r==="[object Date]"||Je(e)}var De=typeof Symbol=="function"&&Symbol.for,Be=De?Symbol.for("react.element"):60103;function Je(e){return e.$$typeof===Be}function He(e){return Array.isArray(e)?[]:{}}function ee(e,r){return r.clone!==!1&&r.isMergeableObject(e)?W(He(e),e,r):e}function ze(e,r,t){return e.concat(r).map(function(c){return ee(c,t)})}function Ke(e,r){if(!r.customMerge)return W;var t=r.customMerge(e);return typeof t=="function"?t:W}function We(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(r){return e.propertyIsEnumerable(r)}):[]}function ye(e){return Object.keys(e).concat(We(e))}function we(e,r){try{return r in e}catch(t){return!1}}function Ye(e,r){return we(e,r)&&!(Object.hasOwnProperty.call(e,r)&&Object.propertyIsEnumerable.call(e,r))}function Ze(e,r,t){var c={};return t.isMergeableObject(e)&&ye(e).forEach(function(d){c[d]=ee(e[d],t)}),ye(r).forEach(function(d){Ye(e,d)||(we(e,d)&&t.isMergeableObject(r[d])?c[d]=Ke(d,t)(e[d],r[d],t):c[d]=ee(r[d],t))}),c}function W(e,r,t){t=t||{},t.arrayMerge=t.arrayMerge||ze,t.isMergeableObject=t.isMergeableObject||Ve,t.cloneUnlessOtherwiseSpecified=ee;var c=Array.isArray(r),d=Array.isArray(e),u=c===d;return u?c?t.arrayMerge(e,r,t):Ze(e,r,t):ee(r,t)}W.all=function(r,t){if(!Array.isArray(r))throw new Error("first argument should be an array");return r.reduce(function(c,d){return W(c,d,t)},{})};var Qe=W,ue=Qe;function le(e={},r){const t={};if(typeof r=="function")for(const c in e){const d=e[c];r(d,c)&&(t[c]=d)}return t}const Xe="https://yofu4i8sfe.execute-api.eu-west-1.amazonaws.com",{hostname:q}=window.location||{};/^mbe-test2\./.test(q)||/^mbe-livetest\./.test(q)||/^mbe-qatesting\./.test(q)||/^static-qatesting\./.test(q)||/^demo\./.test(q)||/^mbe-demo\./.test(q)||/^static\./.test(q)||/^localhost\b/.test(q)||/^(\d+\.)+\b/.test(q);const er=`${Xe}`;var rr=()=>({event:(e={})=>{var I;const{baAnalyticsEndPoint:r,baAnalyticsEndPointOrig:t}=((I=e.trackers)==null?void 0:I.BookassistAnalytics)||{},c=`${er}/prod`,d=le(window&&window.navigator||{},A=>typeof A!="function"&&!!A);d.date=new Date().toString();const{availHeight:u,availLeft:g,availTop:h,availWidth:b,colorDepth:y,height:m,pixelDepth:p,width:E}=window.screen;return fetch(`${r||c}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({Record:{Data:ue.all([e,{trackers:{BookassistAnalytics:{baAnalyticsEndPointOrig:t||c}}},{query:Ae(),session:Se(),referrer:document.referrer,cookie:document.cookie,client:d,screen:{availHeight:u,availLeft:g,availTop:h,availWidth:b,colorDepth:y,height:m,pixelDepth:p,width:E}}]),Tab:" ",NewLine:` `}})}).catch(A=>{console.error(A)})}}),ve=function(){let e;function r(t){window.dataLayer=window.dataLayer||[];function c(){dataLayer.push(arguments)}const d=_.get("cookie-consent"),u=d==="15"?"granted":"denied";c("consent","default",{ad_storage:u,ad_user_data:u,ad_personalization:u,analytics_storage:u}),c("js",new Date);const{clientId:g,gsessionId:h}=K.parse(window.location.search);t.forEach(y=>{const{trackingId:m,sendPageView:p}=y;c("config",m,H(M(M(M({cookie_flags:"SameSite=None; Secure"},typeof p=="boolean"&&{send_page_view:p}),g&&{client_id:g}),h&&m.startsWith("G-")&&{session_id:h}),{url_passthrough:!0}))}),window.gtag=c;const b=function(){let y=d,m=u;return function(){const p=_.get("cookie-consent");if(p!==y){const E=p==="15"?"granted":"denied";E!==m&&(c("consent","update",{ad_storage:E,ad_user_data:E,ad_personalization:E,analytics_storage:E}),m=E),y=p}}}();return setInterval(b,1e3),new Promise((y,m)=>{setTimeout(()=>{m(new Error("loadGtag timeout"))},5e3);const p=document.createElement("script");p.src=`https://www.googletagmanager.com/gtag/js?id=${t[0].trackingId}`,document.head.insertBefore(p,document.head.firstChild),p.addEventListener("load",y),p.addEventListener("error",()=>{m(new Error("gtag failed to load."))})})}return function(t){return e||(e=new Promise((c,d)=>ne(this,null,function*(){try{yield r(t),c()}catch(u){d(u)}}))),e}}();class _e{constructor(r){let t;r.measurementIds?t=r.measurementIds.filter(c=>/^(?!UA-)/.test(c.id)).map(c=>H(M({},c),{name:c.owner,trackingId:c.id})):t=Object.values(r),this.accounts=t,this.loadGtag=ve(t).catch(c=>console.error(c))}getLoadGtag(){return this.loadGtag}getTrackers(){return this.accounts}gtag(...r){return ne(this,null,function*(){try{yield ve(this.accounts),window.gtag(...r)}catch(t){console.error(t)}})}config(r,t){this.gtag("config",r,t)}consent(r,t){this.gtag("consent",r,t)}get(r,t){return new Promise((c,d)=>{setTimeout(()=>{d(new Error("gtag get() timeout"))},5e3),this.gtag("get",r,t,c)}).catch(c=>{console.error(c)})}set(r){this.gtag("set",r)}event(r,t){const u=t,{send_to:c}=u,d=Z(u,["send_to"]);return new Promise((g,h)=>{setTimeout(()=>{h(new Error("gtag event() timeout"))},5e3),this.gtag("event",r,H(M({send_to:c||this.getTrackers().map(b=>b.trackingId)},d),{event_callback:g}))}).catch(g=>{console.error(g)})}}var tr=({accounts:e})=>{const r=new _e(e),t=({request:c={}})=>{const{page:d}=c,u={};return d&&(u.page_path=d),r.event("page_view",u)};return{event:c=>{try{const{event:{type:d}}=c;return d==="pageView"?t(c):Promise.resolve()}catch(d){return Promise.reject(d)}}}},nr=({accounts:e})=>{const r=new _e(e),t=r.getTrackers(),c=({request:n={},context:o={},event:a})=>{const{page:l}=n,{hotel:f,client:w}=o,S={};if(l&&f){let C,$;try{({pathname:C,search:$}=new URL(l,window.location.origin))}catch(P){({pathname:C,search:$}=window.location)}w==="v15"&&(C=`/${a.pathname}`);const R=K.parse($);let N=`?hotel_id=${f.hotelId}&guide_id=${f.guideId}&`;R&&(["cgs","price_group","promo_code","voucher_code","date_in","date_out","nn","adults","children","user_language","user_currency","service_model","bp","from_page","action","ref","version","client-version","err"].forEach(x=>{R[x]&&(N+=`${x}=${R[x]}&`)}),N=N.slice(0,-1)),S.page_path=`${C}${N}`}return r.event("page_view",S)},d=(n,o,a)=>{if(/^(room|extraBed)$/.test(n))return`${o}/Rooms/${a}`;if(n==="mealPlan")return`${o}/Mealplans/Mealplans`;if(n==="addon")return`${o}/Addons/${a}`},u=(n,{context:{hotel:o}})=>{const a=l=>{const f={mealPlan:"bam",addon:"baa",extraBed:"bae",default:"bar"};return f[l]||f.default};return n.map(({id:l,type:f,name:w,variationGroupName:S,addonGroupName:C,position:$,price:R,quantity:N,priceGroupName:P,priceGroupId:x,dynamicDiscountName:U="No dynamic discount",promoCode:k})=>{let L,G;return P&&x.length>0&&(L=x.concat().sort((V,re)=>+V-+re).join(","),G=P),le({item_id:`${a(f)}_${l}_${o.hotelId}_${o.guideId}`,item_name:w,affiliation:o.name,coupon:k,index:$,item_brand:S,item_category:d(f,o.name,S||C),item_category2:U,item_list_id:L,item_list_name:G,price:R,quantity:N},V=>typeof V!="undefined")})},g=n=>{const{rooms:{impressions:o=[]}}=n,a=[];let l=[];return u(o,n).forEach((f,w)=>{l.push(f),(w>0&&w%10===9||w+1===o.length)&&(a.push(r.event("view_item",{items:[...l]})),l=[])}),Promise.all(a)},h=(n,o)=>{const{addons:a,mealPlans:l,rooms:f,extraBeds:w}=n,S=[];return[f,l,a,w].forEach(({cart:C})=>{u(C.filter($=>!!$[o]),n).forEach($=>{S.push($)})}),S},b=n=>{const{request:{hotelCurrency:o},purchase:{revenue:a}}=n,l=h(n,"addProduct"),f=[];return l.length>0&&f.push(r.event("add_to_cart",{items:l,currency:o,value:a})),Promise.all(f)},y=n=>{const{request:{hotelCurrency:o},purchase:{revenue:a}}=n,l=h(n,"removeProduct"),f=[];return l.length>0&&f.push(r.event("remove_from_cart",{items:l,currency:o,value:a})),Promise.all(f)},m=n=>{const{addons:o,mealPlans:a,rooms:l,extraBeds:f,request:{hotelCurrency:w},purchase:{revenue:S}}=n,C=[],$=[],R=[];return[l,a,o,f].forEach(({cart:N})=>{u(N.map(P=>{const L=P,{priceGroupName:x,priceGroupId:U}=L,k=Z(L,["priceGroupName","priceGroupId"]);return x&&U&&$.push(...U),k}),n).forEach(P=>{R.push(P)})}),R.length>0&&C.push(r.event("begin_checkout",{items:R,currency:w,value:S})),Promise.all(C)},p=n=>{const{addons:o,mealPlans:a,rooms:l,extraBeds:f,payment:{paymentType:w,paymentOption:S},request:{hotelCurrency:C},purchase:{revenue:$}}=n,R=[],N=[],P=[];if([l,a,o,f].forEach(({cart:x})=>{u(x.map(U=>{const V=U,{priceGroupName:k,priceGroupId:L}=V,G=Z(V,["priceGroupName","priceGroupId"]);return k&&L&&N.push(...L),G}),n).forEach(U=>{P.push(U)})}),P.length>0){let x=w.replace(/_/g," ");S&&(x=`${x} (${S})`);const U=(l.cart.find(k=>!!k.promoCode)||{}).promoCode;R.push(r.event("add_payment_info",H(M({items:P,payment_type:x},U&&{coupon:U}),{currency:C,value:$})))}return Promise.all(R)},E=n=>{const{addons:o,mealPlans:a,extraBeds:l,rooms:f,context:{client:w,hotel:{name:S,hotelId:C,guideId:$}},request:{arrivalDate:R,hotelCurrency:N,lengthOfStay:P},purchase:{bookingReference:x,revenue:U},payment:{paymentType:k}}=n,L=[];let G=[],V;const re=[];if([f,a,o,l].forEach(({cart:ce})=>{u(ce.map(te=>{const J=te,{priceGroupName:ae,priceGroupId:ie}=J,D=Z(J,["priceGroupName","priceGroupId"]);return ae&&ie&&(V=ae.replace(/\s*\([{0-9},]+\)$/,""),G.push(...ie)),D}),n).forEach(te=>{re.push(te)})}),re.length>0){G=G.filter((D,J,ge)=>ge.indexOf(D)===J),G.length>1&&(G.sort((D,J)=>+D-+J),V="Mixed");const ce=(f.cart.find(D=>!!D.promoCode)||{}).promoCode;L.push(r.event("purchase",H(M({items:re,currency:N,transaction_id:`bar_${C}_${$}_${x}`,affiliation:`${S} - ${k} - ${w}`,item_list_id:G.join(","),item_list_name:V},ce&&{coupon:ce}),{value:U})));const te="selected",ae=R,ie=P;t.forEach(({name:D,trackingId:J})=>{const ge=D==="BA"?"Confirmed booking":`Confirmed booking (${C}_${$})`;L.push(r.event(te,{event_category:ge,event_label:ae,event_value:ie,send_to:J}))})}return Promise.all(L)},I=n=>{const{context:{hotel:{hotelId:o,guideId:a}},request:{hotelCurrency:l},purchase:{bookingReference:f,revenue:w}}=n;[].push(r.event("refund",{transaction_id:`bar_${o}_${a}_${f}`,currency:l,value:w}))},A=["ExtraBedNotSet","FormValidationError","InvalidPromoCode","InvalidVoucher","PricesUpdated","UnexpectedError"],F=["AddressLink","HomeLink","MapLink","SeeEmail","SeePhone"],B=new RegExp(`^(${A.join("|")})$`),Y=new RegExp(`^(${F.join("|")})$`),s=n=>{const{event:{key:o}}=n;let a,l;const f=o.replace(/([a-z])([A-Z])/g,"$1 $2");return Y.test(o)?(a="Mobile BE interaction",l=`Onclick events - ${window.location.pathname}`):B.test(o)&&(a="Mobile BE system messages",l=`System messages - ${window.location.pathname}`),a&&l&&f?r.event(l,{event_category:a,event_label:f}):Promise.resolve()},i=n=>{const S=n,{eventAction:o,eventCategory:a,eventLabel:l,eventValue:f}=S,w=Z(S,["eventAction","eventCategory","eventLabel","eventValue"]);return r.event(o,M(M(M(M({},a&&{event_category:a}),l&&{event_label:l}),f&&{event_value:f}),w))};return{event:n=>{try{const{event:{type:o,key:a,fieldsObject:l}}=n;if(o==="pageView")return c(n);if(o==="technical"){if(a==="chooseProduct")return g(n);if(a==="addProduct")return b(n);if(a==="removeProduct")return y(n);if(a==="checkout")return m(n);if(a==="payment")return p(n);if(a==="confirmation")return E(n);if(a==="cancellation")return I(n)}else{if(o==="userInteraction")return s(n);if(o==="gaEvent")return i(l)}return Promise.resolve()}catch(o){return Promise.reject(o)}},gtagLoaded:r.getLoadGtag()}};const be={BookassistAnalytics:rr,GoogleAnalytics:nr,Pulse:tr};var Ee=(e,r)=>typeof be[e]=="function"&&be[e](H(M({},r),{tracker:e}));const Oe=()=>{try{let e=0,{domain:r}=document;const t=r.split("."),c=`_gd${new Date().getTime()}`;for(;e<t.length-1&&document.cookie.indexOf(`${c}=${c}`)===-1;)r=t.slice(-1-++e).join("."),document.cookie=`${c}=${c};domain=${r};`;return document.cookie=`${c}=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain=${r};`,r}catch(e){return}},Se=()=>{let e,r;const{bas:t}=K.parse(window.location.search);if(t)try{({uuidCS:e,uuidCU:r}=JSON.parse(decodeURIComponent(atob(t))))}catch(d){console.error(d)}(!e||!r)&&(e=_.get("bassist-session-uuid")||Re(),r=_.get("bassist-user-uuid")||e);const c=Oe();return _.set("bassist-session-uuid",e,{domain:c,path:"/",secure:!0,sameSite:"none"}),_.set("bassist-user-uuid",r,{domain:c,path:"/",expires:730,secure:!0,sameSite:"none"}),{uuidCS:e,uuidCU:r}},Ae=()=>{const{href:e,pathname:r,search:t}=window.location,c=K.parse(t);return{href:e,path:r,query:K.stringify(c),params:c}},or=()=>{var e,r;return{date:new Date().toString(),cookies:_.get(),BA:{extraParams:(e=window.BA)==null?void 0:e.extraParams,rrDoc:(r=window.BA)==null?void 0:r.rrDoc}}},sr=function(){let r;return function(){return ne(this,null,function*(){return r||(r=fetch(new Request("https://www.googletagmanager.com/gtag/js",{method:"HEAD",mode:"no-cors"})).then(()=>!1).catch(()=>!0)),r})}}(),cr=(e={})=>{const t=Object.entries(ue({BookassistAnalytics:{}},e.trackers||{})),c=t.map(([d,u])=>Ee(d,u));return{event:(...d)=>ne(this,null,function*(){const u=structuredClone(d);try{const g=yield sr(),h=ue.all([...u,{client:{adblock:g,fingerprint:{id:Math.random().toString(20).substr(2,5)},cookie:document.cookie}}]),b=[],{whitelist:y}=h.event||{};return c.forEach((m,p)=>{if(typeof m.event=="function"&&(!y||y.find(E=>E===t[p][0]))){const E=m.event(h);E&&typeof E.then=="function"&&b.push(E)}}),Promise.all(b)}catch(g){console.error(g)}}),addTrackers:d=>{const u=Object.entries(le(d,(g,h)=>!Object.prototype.hasOwnProperty.call(Object.fromEntries(t),h)));u.length>0&&(t.push(...u),c.push(...u.map(([g,h])=>Ee(g,h))))},removeTrackers:(...d)=>{d.forEach(u=>{const g=t.findIndex(([h])=>h===u);g>-1&&(t.splice(g,1),c.splice(g,1))})},getTrackers:()=>t.map(d=>d[0]),getMeasurementIds:()=>{const d=t==null?void 0:t.find(y=>y[0]==="GoogleAnalytics"),{accounts:u}=(d==null?void 0:d[1])||{},{BA:g,hotel:h,measurementIds:b}=u||{};return b?b.map(y=>y.id):g||h?[g,h].filter(y=>!!y).map(y=>y.trackingId):[]},getClientId:d=>{if(d){const u=t.findIndex(([h])=>h==="GoogleAnalytics"),g=c[u];if(g)return g.gtagLoaded.then(()=>new Promise((h,b)=>{setTimeout(()=>{b(new Error("getClientId timeout"))},2e3),typeof window.gtag=="function"&&d?window.gtag("get",d,"client_id",h):typeof window.ga=="function"&&window.ga(y=>{h(y.get("clientId"))})})).catch(h=>{console.error(h)})}return Promise.resolve()},getGSessionId:d=>{if(d){const u=t.findIndex(([h])=>h==="GoogleAnalytics"),g=c[u];if(g)return g.gtagLoaded.then(()=>new Promise((h,b)=>{setTimeout(()=>{b(new Error("getGSessionId timeout"))},2e3),typeof window.gtag=="function"&&d&&window.gtag("get",d,"session_id",h)})).catch(h=>{console.error(h)})}return Promise.resolve()},_trackers:c,_trackerConfigs:t}};v.default=cr,v.getClientData=or,v.getDomain=Oe,v.getRequestData=Ae,v.getSession=Se,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});