(()=>{"use strict";function e(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)e[n]=t[n]}return e}var r=function r(t,n){function a(r,a,o){if("undefined"!=typeof document){"number"==typeof(o=e({},n,o)).expires&&(o.expires=new Date(Date.now()+864e5*o.expires)),o.expires&&(o.expires=o.expires.toUTCString()),r=encodeURIComponent(r).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var i="";for(var c in o)o[c]&&(i+="; "+c,!0!==o[c]&&(i+="="+o[c].split(";")[0]));return document.cookie=r+"="+t.write(a,r)+i}}return Object.create({set:a,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],n={},a=0;a<r.length;a++){var o=r[a].split("="),i=o.slice(1).join("=");try{var c=decodeURIComponent(o[0]);if(n[c]=t.read(i,c),e===c)break}catch(e){}}return e?n[e]:n}},remove:function(r,t){a(r,"",e({},t,{expires:-1}))},withAttributes:function(t){return r(this.converter,e({},this.attributes,t))},withConverter:function(t){return r(e({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(n)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});document.addEventListener("DOMContentLoaded",()=>{if(r.get(rewardswpTrackingVars.visitIdCookieName)&&r.get(rewardswpTrackingVars.advocateIdCookieName))return;const e=new URLSearchParams(window.location.search).get(rewardswpTrackingVars.referralSlug);e&&n(e)});const t=(e,t)=>{r.set(e,t,{expires:rewardswpTrackingVars.cookieExpiration,path:rewardswpTrackingVars.cookiePath,domain:rewardswpTrackingVars.cookieDomain})},n=async e=>{try{const r=new FormData;r.append("action","rewardswp_track_visit"),r.append("referral_code",e),r.append("referrer_url",document.referrer??""),r.append("landing_url",document.URL??""),r.append("_ajax_nonce",rewardswpTrackingVars.nonce);const n=await fetch(rewardswpTrackingVars.ajaxUrl,{method:"POST",credentials:"same-origin",body:r});if(!n.ok)throw new Error(`Failed to create visit. HTTP error! Status: ${n.status}`);const a=await n.json();a.event_id&&t(rewardswpTrackingVars.visitIdCookieName,a.event_id),a.advocate_id&&t(rewardswpTrackingVars.advocateIdCookieName,a.advocate_id)}catch(e){console.log("Request failed",e)}}})();