(function(){"use strict";const e="_rid_anm_id";const t=renta.writeKey;const n=renta.env??null;const o="Renta SDK is not supported in this environment";const r=renta.collectURL||"cdp.renta.im";let i=`https://${r}/collect/v3`;let a=true;let s=true;let c=null;let l=true;const u=["fbclid","gclid","gbraid","wbraid","ttclid","yclid","utm_source","utm_medium","utm_campaign","utm_content","utm_term"];function d(e,t){const n=new Date;n.setFullYear(n.getFullYear()+1);const o=window.location.hostname.split(".").slice(-2).join(".");try{document.cookie=`${encodeURIComponent(e)}=${encodeURIComponent(t)}; path=/; expires=${n.toUTCString()}; domain=${o}; Secure; SameSite=None`}catch(e){s=false;k("/e",{error_message:`Error setting cookie: ${e.message}`},1)}}function f(e){try{return document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)")?.pop()||null}catch(e){s=false;return null}}function p(e,t){try{const n=new URL(e);const o=n.searchParams.get(t);const r=`_rid_${t}_id`;if(o!==null){return o}const i=f(r);if(i!==null){return i}return null}catch(e){return null}}function w(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const t=Math.random()*16|0;const n=e==="x"?t:t&3|8;return n.toString(16)}))}function h(){return(new Date).toISOString()}function y(e){try{return localStorage.getItem(e)}catch(e){a=false;return null}}function m(e,t){try{localStorage.setItem(e,t)}catch(e){a=false;k("/e",{error_message:`${e.message}`},1)}}function g(e,t){if(e&&e.hasOwnProperty("context")&&e.context.hasOwnProperty("protocols")&&e.context.protocols.hasOwnProperty(t)){return e.context.protocols[t]}return null}function x(e,t=null){try{JSON.stringify(e);return true}catch(n){const o=t?` for event "${t}"`:"";console.error(`Renta SDK: invalid json object for properties ${o}:`,e);return false}}function _(e,t){if(e&&typeof e==="object"){if(x(e,t)){return g(e,"event_version")}else{const n=t?` for event "${t}"`:"";console.warn(`Renta SDK: Invalid JSON object for options${n}:`,e)}}}async function v(){let t=f(e);let n=y(e);if(t&&!n){m(e,t);return t}if(!t&&n){d(e,n);return n}if(!t&&!n){c=c||O();const t=await c;d(e,t);m(e,t);return t}return t}class S{constructor(e,t,n){this.eventType=e;this.payload=this.getBasePayload(t,n)}getBasePayload(e,o){const r={};u.forEach((e=>{const t=e+"_lc";r[t]=p(window.location.href,e)}));return{context:{page:{path:window.location.pathname,referrer:document.referrer,title:document.title,url:location.origin+location.pathname,location:location.href,hostname:location.origin},device:{deviceDocEncoding:document.characterSet,deviceScreenWidth:screen.width,deviceScreenHeight:screen.height,deviceViewPortWidth:window.visualViewport?window.visualViewport.width:Math.max(document.documentElement.clientWidth||0,window.innerWidth||0),deviceViewPortHeight:window.visualViewport?window.visualViewport.height:Math.max(document.documentElement.clientHeight||0,window.innerHeight||0),userAgent:navigator.userAgent},cookies:{ym:f("_ym_uid"),ga:f("_ga"),fbp:f("_fbp"),fbc:f("_fbc"),localStorageAccessible:a,cookiesAccessible:s},library:{name:"renta.js",version:renta.SNIPPET_VERSION},protocols:{environment:n,eventVersion:o||null},ads:r},timestamp:h(),messageId:w(),type:this.eventType,userId:y("rid_user_id"),groupId:y("rid_group_id"),anonymousId:e,writeKey:t}}}class $ extends S{constructor(e,t,n,o){super("identify",e,o);this.payload.properties=n||{};if(t){m("rid_user_id",t);this.payload.userId=t}}}class b extends S{constructor(e,t,n,o){super("group",e,o);this.payload.properties=n||{};if(t){m("rid_group_id",t);this.payload.groupId=t}}}class j extends S{constructor(e,t,n,o){super("track",e,o);this.payload.name=t||null;this.payload.properties=n||{}}}class P extends S{constructor(e,t,n,o){super("page",e,o);this.payload.name=t||null;this.payload.properties=n||{}}}renta.identify=async function(e,t,n){if(typeof e==="object"&&e!==null){t=e;e=undefined}if(t&&!x(t,"identify")){return}const o=await v();const r=_(n);const i=new $(o,e,t,r);if(l){await k("/i",i.payload)}};renta.group=async function(e,t,n){if(typeof e==="object"&&e!==null){t=e;e=undefined}if(t&&!x(t,"group")){return}const o=await v();const r=_(n);const i=new b(o,e,t,r);if(l){await k("/g",i.payload)}};renta.track=async function(e,t,n){if(typeof e==="object"&&e!==null){t=e;e=undefined}if(t&&!x(t,e)){return}const o=await v();const r=_(n,e);const i=new j(o,e,t,r);if(l){await k("/t",i.payload)}};renta.page=async function(e,t,n){if(typeof e==="object"&&e!==null){t=e;e=undefined}if(t&&!x(t,e)){return}const o=await v();const r=_(n,e);const i=new P(o,e,t,r);if(l){await k("/p",i.payload)}};async function k(e,t,n=4){const o=`${i}${e}`;const r="Renta SDK: error sending data to the server. ";t.sentAt=h();const a=3e3;async function s(){n--;if(n>0){console.warn(`${r} Retries left: ${n}.`);await new Promise((e=>setTimeout(e,a)))}else{console.error(`${r}`)}}while(n>0){try{const e=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t),credentials:"include"});if(e.ok){break}else{await s()}}catch(e){await s()}}}async function I(){const e=`${i}/${t}/settings`;try{if(window.fetch){const t=await fetch(e,{method:"GET",headers:{Accept:"application/json"},credentials:"include"});if(t.ok){const e=await t.json();if(e.hasOwnProperty("account_status")){l=e["account_status"]}if(e.hasOwnProperty("collect_url")){i=e["collect_url"]}}else{return l}if(t.ok){const e=await t.json();if(e.hasOwnProperty("account_status")){l=e["account_status"]}if(e.hasOwnProperty("collect_url")){i=e["collect_url"]}}else{if(t.status===403){const e=await t.text();console.error(`[Renta SDK] ${e}`);l=false;return l}else{return l}}}else{console.warn(o);return l}}catch(e){return l}return l}async function O(){const e=`${i}/${t}/rid`;try{if(window.fetch){const t=await fetch(e,{headers:{Accept:"application/json"}});if(t.ok){const e=await t.json();if(e.hasOwnProperty("rid")){return e["rid"]}}else{return w()}}else{console.warn(o)}}catch(e){return w()}}async function R(){if(t){renta.initialize=true;const e=await I();if(e){while(renta.length>0){let e=renta.shift();let t=e.shift();renta[t].apply(renta,e)}}else{console.error("Renta SDK: tracking was been suspended. Please contact support.")}}else{console.error("Renta SDK writeKey is not set. Please set it in the HTML snippet.")}}R();window.addEventListener("error",(function(e){const t={error_message:e.reason?e.reason.message:"Global error",error_code:e.reason?e.reason.stack:null};k("/e",t,0)}));window.addEventListener("unhandledrejection",(function(e){const t={error_message:e.reason?e.reason.message:"Unhandled rejection",error_code:e.reason?e.reason.stack:null};k("/e",t,0)}))})();