"use strict";(()=>{var m=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var M=(e,t,o)=>()=>{if(o)throw o[0];try{return e&&(t=e(e=0)),t}catch(r){throw o=[r],r}};var _=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},P=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of S(t))!R.call(e,i)&&i!==o&&m(e,i,{get:()=>t[i],enumerable:!(r=y(t,i))||r.enumerable});return e};var T=e=>P(m({},"__esModule",{value:!0}),e);var g={};_(g,{getReferrer:()=>A,parseReferrerData:()=>h});function U(e){let t=e.get("ref"),o=e.get("source"),r=e.get("utm_source"),i=e.get("utm_medium"),u=e.get("utm_term"),s=e.get("utm_campaign"),c=e.get("utm_content");return{source:t||o||r||null,medium:i||null,url:window.document.referrer||null,utmSource:r||null,utmMedium:i||null,utmTerm:u||null,utmCampaign:s||null,utmContent:c||null}}function h(e){let t=new URL(e||window.location.href),o=t.searchParams;return t.hash&&t.hash.includes("#/portal")&&(o=new URL(t.href.replace("/#/portal","")).searchParams),U(o)}function C(e){let{source:t,medium:o,url:r}=e,i=t||o||r||null;if(i)try{let u=new URL(i).hostname,s=window.location.hostname;if(u===s)return null}catch{return i}return i}function A(e){let t=h(e);return C(t)}var d=M(()=>{"use strict"});var b=(d(),T(g)),D=b.parseReferrerData,E=b.getReferrer,p="ghost-history",I=1440*60*1e3,w=15;(async function(){try{let e=window.sessionStorage,t=e.getItem(p),o=new Date().getTime(),r=[];if(t)try{r=JSON.parse(t)}catch(n){console.warn("[Member Attribution] Error while parsing history",n)}let i=r.findIndex(n=>{if(!n.time||typeof n.time!="number")return!1;let a=o-n.time;return!(isNaN(n.time)||a>I)});i>0?r.splice(0,i):i===-1&&(r=[]);let u;try{u=D(window.location.href)}catch(n){console.error("[Member Attribution] Parsing referrer failed",n),u={source:null,medium:null,url:null}}let s={referrerSource:u.source,referrerMedium:u.medium,utmSource:u.utmSource,utmMedium:u.utmMedium,utmCampaign:u.utmCampaign,utmTerm:u.utmTerm,utmContent:u.utmContent},c;try{c=E(window.location.href),!c&&u.url&&(c=u.url)}catch(n){console.error("[Member Attribution] Getting final referrer failed",n),c=u.url}try{let n=new URL(window.location.href),a=n.searchParams;a.get("attribution_id")&&a.get("attribution_type")&&(r.push({time:o,id:a.get("attribution_id"),type:a.get("attribution_type"),...s,referrerUrl:c}),a.delete("attribution_id"),a.delete("attribution_type"),n.search="?"+a.toString(),window.history.replaceState({},"",`${n.pathname}${n.search}${n.hash}`))}catch(n){console.error("[Member Attribution] Parsing attribution from querystring failed",n)}let l=window.location.pathname;if(r.length===0||r[r.length-1].path!==l)r.push({path:l,time:o,...s,referrerUrl:c});else if(r.length>0){let n=r[r.length-1];n.time=o,Object.entries(s).forEach(([a,f])=>{f&&(n[a]=f)}),c&&(n.referrerUrl=c)}r.length>w&&(r=r.slice(-w)),e.setItem(p,JSON.stringify(r))}catch(e){console.error("[Member Attribution] Failed with error",e)}})();})();