!function(){"use strict";const e="_rid_anm_id",t=renta.writeKey,n=renta.env??null,o="Renta SDK is not supported in this environment";let r=`https://${renta.collectURL||"cdp.renta.im"}/collect/v2`,a=!0,i=!0,c=null,s=!0;function l(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){i=!1,$("/e",{error_message:`Error setting cookie: ${e.message}`},1)}}function u(e){try{return document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)")?.pop()||null}catch(e){return i=!1,null}}function d(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))}function p(){return(new Date).toISOString()}function w(e){try{return localStorage.getItem(e)}catch(e){return a=!1,null}}function f(e,t){try{localStorage.setItem(e,t)}catch(e){a=!1,$("/e",{error_message:`${e.message}`},1)}}function h(e,t=null){try{return JSON.stringify(e),!0}catch(n){const o=t?` for event "${t}"`:"";return console.error(`Renta SDK: invalid json object for properties ${o}:`,e),!1}}function y(e,t){if(e&&"object"==typeof e){if(h(e,t))return function(e,t){return e&&e.hasOwnProperty("context")&&e.context.hasOwnProperty("protocols")&&e.context.protocols.hasOwnProperty(t)?e.context.protocols[t]:null}(e,"event_version");{const n=t?` for event "${t}"`:"";console.warn(`Renta SDK: Invalid JSON object for options${n}:`,e)}}}async function g(){let n=u(e),a=w(e);if(n&&!a)return f(e,n),n;if(!n&&a)return l(e,a),a;if(!n&&!a){c=c||async function(){const e=`${r}/${t}/rid`;try{if(window.fetch){const t=await fetch(e,{headers:{Accept:"application/json"}});if(!t.ok)return d();{const e=await t.json();if(e.hasOwnProperty("rid"))return e.rid}}else console.warn(o)}catch(e){return d()}}();const n=await c;return l(e,n),f(e,n),n}return n}class m{constructor(e,t,n){this.eventType=e,this.payload=this.getBasePayload(t,n)}getBasePayload(e,o){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:u("_ym_uid"),ga:u("_ga"),fbp:u("_fbp"),fbc:u("_fbc"),localStorageAccessible:a,cookiesAccessible:i},library:{name:"renta.js",version:renta.SNIPPET_VERSION},protocols:{environment:n,eventVersion:o||null}},timestamp:p(),messageId:d(),type:this.eventType,userId:w("rid_user_id"),groupId:w("rid_group_id"),anonymousId:e,writeKey:t}}}class x extends m{constructor(e,t,n,o){super("identify",e,o),this.payload.properties=n||{},t&&(f("rid_user_id",t),this.payload.userId=t)}}class v extends m{constructor(e,t,n,o){super("group",e,o),this.payload.properties=n||{},t&&(f("rid_group_id",t),this.payload.groupId=t)}}class _ extends m{constructor(e,t,n,o){super("track",e,o),this.payload.name=t||null,this.payload.properties=n||{}}}class S extends m{constructor(e,t,n,o){super("page",e,o),this.payload.name=t||null,this.payload.properties=n||{}}}async function $(e,t,n=4){const o=`${r}${e}`,a="Renta SDK: error sending data to the server. ";t.sentAt=p();async function i(){--n>0?(console.warn(`${a} Retries left: ${n}.`),await new Promise((e=>setTimeout(e,3e3)))):console.error(`${a}`)}for(;n>0;)try{if((await fetch(o,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t),credentials:"include"})).ok)break;await i()}catch(e){await i()}}async function j(){const e=`${r}/${t}/settings`;try{if(!window.fetch)return console.warn(o),s;{const t=await fetch(e,{method:"GET",headers:{Accept:"application/json"},credentials:"include"});if(!t.ok)return s;{const e=await t.json();e.hasOwnProperty("account_status")&&(s=e.account_status),e.hasOwnProperty("collect_url")&&(r=e.collect_url)}if(!t.ok){if(403===t.status){const e=await t.text();return console.error(`[Renta SDK] ${e}`),s=!1,s}return s}{const e=await t.json();e.hasOwnProperty("account_status")&&(s=e.account_status),e.hasOwnProperty("collect_url")&&(r=e.collect_url)}}}catch(e){return s}return s}renta.identify=async function(e,t,n){if("object"==typeof e&&null!==e&&(t=e,e=void 0),t&&!h(t,"identify"))return;const o=await g(),r=y(n),a=new x(o,e,t,r);s&&await $("/i",a.payload)},renta.group=async function(e,t,n){if("object"==typeof e&&null!==e&&(t=e,e=void 0),t&&!h(t,"group"))return;const o=await g(),r=y(n),a=new v(o,e,t,r);s&&await $("/g",a.payload)},renta.track=async function(e,t,n){if("object"==typeof e&&null!==e&&(t=e,e=void 0),t&&!h(t,e))return;const o=await g(),r=y(n,e),a=new _(o,e,t,r);s&&await $("/t",a.payload)},renta.page=async function(e,t,n){if("object"==typeof e&&null!==e&&(t=e,e=void 0),t&&!h(t,e))return;const o=await g(),r=y(n,e),a=new S(o,e,t,r);s&&await $("/p",a.payload)},async function(){if(t){renta.initialize=!0;if(await j())for(;renta.length>0;){let e=renta.shift(),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.")}(),window.addEventListener("error",(function(e){$("/e",{error_message:e.reason?e.reason.message:"Global error",error_code:e.reason?e.reason.stack:null},0)})),window.addEventListener("unhandledrejection",(function(e){$("/e",{error_message:e.reason?e.reason.message:"Unhandled rejection",error_code:e.reason?e.reason.stack:null},0)}))}();