!function(){"use strict";var i={cookieName:"firebox_attribution",maxCampaigns:20,attributionWindow:30,init:function(){document.addEventListener("FireBoxAfterOpenTrackView",this.trackImpression.bind(this)),document.addEventListener("FireBoxConversion",this.trackConversion.bind(this))},trackImpression:function(i){var n,t,e;i.detail&&i.detail.instance&&(t=(n=i.detail.instance).id,e=n.box_log_id||null,this.addCampaignToCookie(t,e,"impression"))},trackConversion:function(i){var n,t,e;i.detail&&i.detail.instance&&(t=(n=i.detail.instance).id,e=n.box_log_id||null,this.addCampaignToCookie(t,e,"conversion"))},addCampaignToCookie:function(n,i,t){var e=this.getCampaignsFromCookie(),o=Date.now(),a=e.find(function(i){return i.box_id===n});a?(a.last_seen=o,i&&0<i&&(a.log_id=i),"conversion"===t&&(a.has_conversion=!0)):e.push({box_id:n,log_id:i||0,first_seen:o,last_seen:o,has_conversion:"conversion"===t}),e.length>this.maxCampaigns&&(e.sort(function(i,n){return n.last_seen-i.last_seen}),e.splice(this.maxCampaigns));var s=o-24*this.attributionWindow*60*60*1e3,r=e.filter(function(i){return i.last_seen>s});this.setCampaignsCookie(r)},getCampaignsFromCookie:function(){var i=this.getCookie(this.cookieName);if(!i)return[];try{return JSON.parse(decodeURIComponent(i))}catch(i){return[]}},setCampaignsCookie:function(i){var n=encodeURIComponent(JSON.stringify(i)),t=new Date;t.setDate(t.getDate()+this.attributionWindow),document.cookie=this.cookieName+"="+n+"; expires="+t.toUTCString()+"; path=/; SameSite=Lax"},getCookie:function(i){for(var n=i+"=",t=document.cookie.split(";"),e=0;e<t.length;e++){for(var o=t[e];" "===o.charAt(0);)o=o.substring(1,o.length);if(0===o.indexOf(n))return o.substring(n.length,o.length)}return null},getTrackedCampaigns:function(){return this.getCampaignsFromCookie()}};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",i.init.bind(i)):i.init(),window.FireBoxRevenueAttribution=i}();

