window.bslst_init = function(){ //set global configuration variables var user_cookie = "client_bslstuid"; var session_cookie = "client_bslstsid"; var advertiser_cookie = "client_bslstaid"; var match_cookie = "client_bslstmatch"; var session_expire_minutes = 30; var cookie_domain = window.location.hostname.split(/\./).slice(-2).join('.'); var cookie_secure = ";secure"; var cookie_samesite = "lax"; var cookie_separator = "-"; var user_cookie_prefix = "B"; var user_expire_days = 540; var shop_id_value = "16649"; //set default new session to false window.bslst_session_start = false; window.match_event_send = false; //support function to retrieve cookie values window.bslst_getcookie = function(name) { var value = "; " + document.cookie; var parts = value.split("; " + name + "="); if (parts.length == 2) return parts.pop().split(";").shift(); } //support function to set cookie values according to configuration variables window.bslst_setcookie = function(cname, cvalue, exdays, path, domain){ var d = new Date(); d.setTime(d.getTime() + (exdays*24*60*60*1000)); var expires = "expires="+ d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=" + path + ";domain=" + domain + cookie_secure + ";samesite=" + cookie_samesite; } //set an bslstsid if none is available window.bslst_setbslstsid = function(){ var session_id = Math.floor(100000000 + Math.random() * 900000000).toString(); var session_expire = new Date().setTime(new Date().getTime() + (session_expire_minutes*60*1000)).toString(); var session_cookie_value = session_id + cookie_separator + session_expire; var session_expire_days = session_expire_minutes / 60 / 24; window.bslst_setcookie(session_cookie, session_cookie_value, session_expire_days, "/", cookie_domain); window.bslst_session_start = true; return session_id; } //set an bslstsid if none is available window.bslst_setbslstuid = function(){ var user_id = Math.floor(100000000 + Math.random() * 900000000).toString() + "." + new Date().getTime().toString(); var user_expire = new Date().setTime(new Date().getTime() + (user_expire_days * 24 * 60 * 60 * 1000)).toString(); var user_cookie_value = user_cookie_prefix + user_id + cookie_separator + user_expire; window.bslst_setcookie(user_cookie, user_cookie_value, user_expire_days, "/", cookie_domain); return user_id; } //check if an bslstuid exists window.bslst_checkbslstuid = function(){ if(window.bslst_getcookie(user_cookie)!==undefined){ var user_input = window.bslst_getcookie(user_cookie); var user_id = user_input.split(cookie_separator)[0]; var user_expire = parseInt(user_input.split(cookie_separator)[1]); //user cookie expired, create new user id if(user_expire!==undefined && new Date(user_expire) < new Date()){ return window.bslst_setbslstuid(); } //user not expired, refresh user expiration time else if (user_expire!==undefined && new Date(user_expire) > new Date()){ var updated_user_cookie_value = user_id + cookie_separator + new Date().setTime(new Date().getTime() + (user_expire_days*24*60*60*1000)).toString(); window.bslst_setcookie(user_cookie, updated_user_cookie_value, user_expire_days, "/", cookie_domain); return user_id; } else{ return window.bslst_setbslstuid(); } } else{ return window.bslst_setbslstuid(); } } //check if an bslstuid exists window.bslst_checkbslstsid = function(){ if(window.bslst_getcookie(session_cookie)!==undefined){ var session_input = window.bslst_getcookie(session_cookie); var session_id = session_input.split(cookie_separator)[0]; var session_expire = parseInt(session_input.split(cookie_separator)[1]); //session cookie expired, create new session id if(session_expire!==undefined && new Date(session_expire) < new Date()){ return window.bslst_setbslstsid(); } //session not expired, refresh cookie expiration time else if (session_expire!==undefined && new Date(session_expire) > new Date()){ var updated_session_cookie_value = session_id + cookie_separator + new Date().setTime(new Date().getTime() + (session_expire_minutes*60*1000)).toString(); window.bslst_setcookie(session_cookie, updated_session_cookie_value, (session_expire_minutes / 60 / 24), "/", cookie_domain); return session_id; } else{ return window.bslst_setbslstsid(); } } else{ return window.bslst_setbslstsid(); } } //this is the event function window.bslst_event = function(advertiser_id, event_name, context, ecommerce){ //get core objects var bslst_core_context = context || {}; var bslst_ecommerce = ecommerce || {}; var _ga = bslst_getcookie("_ga") || ""; if(_ga.length > 0){ bslst_core_context["ga_cid"] = _ga } //base object to be send with every event var default_event_endpoint = "https://ct.beslist.nl/ct_event"; var event_data = { "client_bslst_eid": bslst_checkbslstsid() + cookie_separator + Math.floor(100000000 + Math.random() * 900000000).toString(), "client_bslst_sid": bslst_checkbslstsid(), "client_bslst_uid": bslst_checkbslstuid(), "client_bslst_aid": advertiser_id, "event": event_name || "not_provided", "timestamp": new Date().getTime(), "screen_height": screen.height || "", "screen_width": screen.width || "", "user_agent": navigator.userAgent || "", "language": navigator.language || "", "context": bslst_core_context, "location": { "referrer": document.referrer, "host": window.location.host, "path": window.location.pathname, "query": window.location.search }, "ecommerce": bslst_ecommerce, }; //adding to location nested object var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", default_event_endpoint, true); xmlhttp.setRequestHeader("Content-Type", "application/json"); xmlhttp.send(JSON.stringify(event_data)); // Update the advertiser cookie window.bslst_setcookie(advertiser_cookie, advertiser_id, user_expire_days, "/", cookie_domain); } // Make a backup for the bslst_advertiser_event window.bslst_advertiser_event = window.bslst_event; // Helper function to access cookies on the current domain. (Shop domain in this context) window.bslst_get_external_cookie = function(name) { var value = "; " + document.cookie; var parts = value.split("; " + name + "="); if (parts.length == 2) { return parts.pop().split(";").shift(); } } // The function below is used to send cross site events to the beslist tracking server. window.bslst_match_event = function(){ if(typeof(window.fetch)==="function"){ // Create the base event object (uid, sid, eid etc. are calculated serverside ). var event_data = { "client_bslst_eid": bslst_checkbslstsid() + cookie_separator + Math.floor(100000000 + Math.random() * 900000000).toString(), "client_bslst_sid": bslst_checkbslstsid(), "client_bslst_uid": bslst_checkbslstuid(), "client_bslst_aid": shop_id_value, "event": "match_event", "timestamp": new Date().getTime(), "screen_height": screen.height || "", "screen_width": screen.width || "", "user_agent": navigator.userAgent || "", "language": navigator.language || "", "location": { "referrer": document.referrer, "host": window.location.host, "path": window.location.pathname, "query": window.location.search } } // Send the event to the tracking server. window.fetch("https://ct.beslist.nl/ct_event", { method: 'POST', credentials: 'include', mode: 'no-cors', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(event_data) }); // After the match event is send, set a match cookie to prevent this event from triggering multiple times per session var match_cookie_value = "true" + cookie_separator + new Date().setTime(new Date().getTime() + (session_expire_minutes*60*1000)).toString(); window.bslst_setcookie(match_cookie, match_cookie_value , (session_expire_minutes / 60 / 24), "/", cookie_domain); } } // check if match cookie is set and not expired if(window.bslst_getcookie(match_cookie) !== undefined ){ var match_cookie_input = window.bslst_getcookie(match_cookie) var match_cookie_value = match_cookie_input.split(cookie_separator)[0]; var match_cookie_expire = parseInt(match_cookie_input.split(cookie_separator)[1]); //match cookie not expired, no need for additional match event if (match_cookie_expire!==undefined && new Date(match_cookie_expire) > new Date()){ window.match_event_send = true; } } }; window.bslst_init(); // if match cookie is not set, send cookie match event //(function(){ // if(window.match_event_send === false){ // window.bslst_match_event(); // window.match_event_send = true; // } //})(); //Set the new session recognition logic in a self executing function (function(){ // check if the advertiser id is already available in the cookies var shop_id_value = "16649"; var advertiser_id = window.bslst_getcookie("client_bslstaid") || shop_id_value; // Keep a list of session start reasons. var session_start_reasons = []; // check if a session id is already present if(window.bslst_session_start === true){ window.bslst_session_start = false; session_start_reasons.push("no session id"); //console.log("no session id"); } // check if referrer is similar to the hostname if(document.referrer.indexOf(location.protocol + "//" + location.host) === -1 || document.referrer === ""){ session_start_reasons.push("new referrer"); //console.log("new referrer"); } // check if utm_* param is present in the search queries if(window.location.search.indexOf("utm_") > -1){ session_start_reasons.push("utm detected"); //console.log("utm detected"); } // check if trackingparameter is present in search queries if(window.location.search.indexOf("clientUuid") > -1){ session_start_reasons.push("new uuid detected"); //console.log("new uuid detected"); } // check if trackingparameter is present in search queries else if(window.location.search.indexOf("bl3nlclid") > -1){ session_start_reasons.push("new bl3nlclid detected"); //console.log("new bl3nlclid detected"); } // If we have a reason for a new session, send the event and the match event. if (session_start_reasons.length > 0) { window.bslst_match_event(); window.bslst_event(advertiser_id, "session_start", { "shop_session_start_reasons": session_start_reasons.join("|") }); } })();