@mate-academy/sourcebuster 1.4.1 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,11 @@ var sbjs = {
14
14
 
15
15
  module.exports = sbjs;
16
16
 
17
+ // Dispatch event when sbjs is available for event-based waiting
18
+ if (typeof window !== 'undefined' && typeof CustomEvent !== 'undefined') {
19
+ window.dispatchEvent(new CustomEvent('sbjs:loaded'));
20
+ }
21
+
17
22
  },{"./init":6}],2:[function(_dereq_,module,exports){
18
23
  "use strict";
19
24
 
@@ -754,6 +759,9 @@ module.exports = function(prefs) {
754
759
  }
755
760
 
756
761
  function setClickIdsToCookies() {
762
+ // 30 days in minutes for affiliate cookies (SD, KS)
763
+ var affiliateLifetime = 30 * 24 * 60;
764
+
757
765
  var gclid = get_param.gclid || '';
758
766
  var gbraid = get_param.gbraid || '';
759
767
  var wbraid = get_param.wbraid || '';
@@ -763,32 +771,46 @@ module.exports = function(prefs) {
763
771
  // if utm_source = "sd" -> utm_term param is used
764
772
  var sdclid = get_param.utm_source === 'sd' ? get_param.utm_term || '' : '';
765
773
 
774
+ // Kyivstar click ID
775
+ var ksclid = get_param.ks_click_id || '';
776
+
766
777
  if (gbraid !== '') {
767
778
  cookies.destroy('_mate-sdclid', domain, isolate);
779
+ cookies.destroy('_mate-ksclid', domain, isolate);
768
780
  cookies.set('_mate-gbraid', gbraid, lifetime, domain, isolate);
769
781
  }
770
782
 
771
783
  if (wbraid !== '') {
772
784
  cookies.destroy('_mate-sdclid', domain, isolate);
785
+ cookies.destroy('_mate-ksclid', domain, isolate);
773
786
  cookies.set('_mate-wbraid', wbraid, lifetime, domain, isolate);
774
787
  }
775
788
  if (gclid !== '') {
776
789
  cookies.destroy('_mate-sdclid', domain, isolate);
790
+ cookies.destroy('_mate-ksclid', domain, isolate);
777
791
  cookies.set('_mate-gclid', gclid, lifetime, domain, isolate);
778
792
  }
779
793
 
780
794
  if (fbclid !== '') {
781
795
  cookies.destroy('_mate-sdclid', domain, isolate);
796
+ cookies.destroy('_mate-ksclid', domain, isolate);
782
797
  cookies.set('_mate-fbclid', fbclid, lifetime, domain, isolate);
783
798
  }
784
799
 
785
800
  if (ttclid !== '') {
786
801
  cookies.destroy('_mate-sdclid', domain, isolate);
802
+ cookies.destroy('_mate-ksclid', domain, isolate);
787
803
  cookies.set('_mate-ttclid', ttclid, lifetime, domain, isolate);
788
804
  }
789
805
 
790
806
  if (sdclid !== '') {
791
- cookies.set('_mate-sdclid', sdclid, lifetime, domain, isolate);
807
+ cookies.destroy('_mate-ksclid', domain, isolate);
808
+ cookies.set('_mate-sdclid', sdclid, affiliateLifetime, domain, isolate);
809
+ }
810
+
811
+ if (ksclid !== '') {
812
+ cookies.destroy('_mate-sdclid', domain, isolate);
813
+ cookies.set('_mate-ksclid', ksclid, affiliateLifetime, domain, isolate);
792
814
  }
793
815
  }
794
816
 
@@ -1,2 +1,2 @@
1
- /** @mate-academy/sourcebuster v1.4.1 **/
2
- !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.sbjs=e()}}(function(){return function e(t,r,n){function i(s,o){if(!r[s]){if(!t[s]){var c="function"==typeof require&&require;if(!o&&c)return c(s,!0);if(a)return a(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var d=r[s]={exports:{}};t[s][0].call(d.exports,function(e){var r=t[s][1][e];return i(r?r:e)},d,d.exports,e,t,r,n)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(e,t,r){"use strict";var n=e("./init"),i={init:function(e){this.get=n(e),e&&e.callback&&"function"==typeof e.callback&&e.callback(this.get)}};t.exports=i},{"./init":6}],2:[function(e,t,r){"use strict";var n=e("./terms"),i=e("./helpers/utils"),a={containers:{current:"sbjs_current",current_extra:"sbjs_current_add",first:"sbjs_first",first_extra:"sbjs_first_add",session:"sbjs_session",udata:"sbjs_udata",promocode:"sbjs_promo"},service:{migrations:"sbjs_migrations"},delimiter:"|||",aliases:{main:{type:"typ",source:"src",medium:"mdm",campaign:"cmp",content:"cnt",term:"trm",account_id:"ac_id",campaign_id:"cmp_id",ad_group_id:"adg_id",ad_id:"ad_id",term_id:"trm_id"},extra:{fire_date:"fd",entrance_point:"ep",referer:"rf"},session:{pages_seen:"pgs",current_page:"cpg",session_id:"sid"},udata:{visits:"vst",ip:"uip",agent:"uag"},promo:"code"},pack:{main:function(e){return a.aliases.main.type+"="+e.type+a.delimiter+a.aliases.main.source+"="+e.source+a.delimiter+a.aliases.main.medium+"="+e.medium+a.delimiter+a.aliases.main.campaign+"="+e.campaign+a.delimiter+a.aliases.main.content+"="+e.content+a.delimiter+a.aliases.main.term+"="+e.term+a.delimiter+a.aliases.main.account_id+"="+e.account_id+a.delimiter+a.aliases.main.campaign_id+"="+e.campaign_id+a.delimiter+a.aliases.main.ad_group_id+"="+e.ad_group_id+a.delimiter+a.aliases.main.ad_id+"="+e.ad_id+a.delimiter+a.aliases.main.term_id+"="+e.term_id},unpack:function(e){var t={},r=e.split("|||");return r.forEach(function(e){var r=e.split("="),n=r[0],i=r[1];t[n]=i}),t},extra:function(e){return a.aliases.extra.fire_date+"="+i.setDate(new Date,e)+a.delimiter+a.aliases.extra.entrance_point+"="+document.location.href+a.delimiter+a.aliases.extra.referer+"="+(document.referrer||n.none)},user:function(e,t){return a.aliases.udata.visits+"="+e+a.delimiter+a.aliases.udata.ip+"="+t+a.delimiter+a.aliases.udata.agent+"="+navigator.userAgent},session:function(e,t){var r=a.aliases.session.pages_seen+"="+e+a.delimiter+a.aliases.session.current_page+"="+document.location.href;return t?r+a.delimiter+a.aliases.session.session_id+"="+t:r},promo:function(e){return a.aliases.promo+"="+i.setLeadingZeroToInt(i.randomInt(e.min,e.max),e.max.toString().length)}}};t.exports=a},{"./helpers/utils":5,"./terms":9}],3:[function(e,t,r){"use strict";var n=e("../data").delimiter;t.exports={encodeData:function(e){return encodeURIComponent(e).replace(/\!/g,"%21").replace(/\~/g,"%7E").replace(/\*/g,"%2A").replace(/\'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")},decodeData:function(e){try{return decodeURIComponent(e).replace(/\%21/g,"!").replace(/\%7E/g,"~").replace(/\%2A/g,"*").replace(/\%27/g,"'").replace(/\%28/g,"(").replace(/\%29/g,")")}catch(t){try{return unescape(e)}catch(r){return""}}},set:function(e,t,r,n,i){var a,s;if(r){var o=new Date;o.setTime(o.getTime()+60*r*1e3),a="; expires="+o.toGMTString()}else a="";s=n&&!i?";domain=."+n:"",document.cookie=this.encodeData(e)+"="+this.encodeData(t)+a+s+"; path=/"},get:function(e){for(var t=this.encodeData(e)+"=",r=document.cookie.split(";"),n=0;n<r.length;n++){for(var i=r[n];" "===i.charAt(0);)i=i.substring(1,i.length);if(0===i.indexOf(t))return this.decodeData(i.substring(t.length,i.length))}return null},destroy:function(e,t,r){this.set(e,"",-1,t,r)},parse:function(e){var t=[],r={};if("string"==typeof e)t.push(e);else for(var i in e)e.hasOwnProperty(i)&&t.push(e[i]);for(var a=0;a<t.length;a++){var s;r[this.unsbjs(t[a])]={},s=this.get(t[a])?this.get(t[a]).split(n):[];for(var o=0;o<s.length;o++){var c=s[o].split("="),u=c.splice(0,1);u.push(c.join("=")),r[this.unsbjs(t[a])][u[0]]=this.decodeData(u[1])}}return r},unsbjs:function(e){return e.replace("sbjs_","")}}},{"../data":2}],4:[function(e,t,r){"use strict";t.exports={parse:function(e){for(var t=this.parseOptions,r=t.parser[t.strictMode?"strict":"loose"].exec(e),n={},i=14;i--;)n[t.key[i]]=r[i]||"";return n[t.q.name]={},n[t.key[12]].replace(t.q.parser,function(e,r,i){r&&(n[t.q.name][r]=i)}),n},parseOptions:{strictMode:!1,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}},getParam:function(e){for(var t={},r=e?e:window.location.search.substring(1),n=r.split("&"),i=0;i<n.length;i++){var a=n[i].split("=");if("undefined"==typeof t[a[0]])t[a[0]]=a[1];else if("string"==typeof t[a[0]]){var s=[t[a[0]],a[1]];t[a[0]]=s}else t[a[0]].push(a[1])}return t},getHost:function(e){return this.parse(e).host.replace("www.","")}}},{}],5:[function(e,t,r){"use strict";t.exports={escapeRegexp:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},setDate:function(e,t){var r=e.getTimezoneOffset()/60,n=e.getHours(),i=t||0===t?t:-r;e.setHours(n+r+i);var a=e.getFullYear(),s=this.setLeadingZeroToInt(e.getMonth()+1,2),o=this.setLeadingZeroToInt(e.getDate(),2),c=this.setLeadingZeroToInt(e.getHours(),2),u=this.setLeadingZeroToInt(e.getMinutes(),2),d=this.setLeadingZeroToInt(e.getSeconds(),2);return a+"-"+s+"-"+o+" "+c+":"+u+":"+d},setLeadingZeroToInt:function(e,t){for(var r=e+"";r.length<t;)r="0"+r;return r},randomInt:function(e,t){return Math.floor(Math.random()*(t-e+1))+e}}},{}],6:[function(e,t,r){"use strict";var n=e("./data"),i=e("./terms"),a=e("./helpers/cookies"),s=e("./helpers/uri"),o=e("./helpers/utils"),c=e("./params"),u=e("./migrations");t.exports=function(e){function t(){var e,t,s,o="undefined"!=typeof v.utm_source||"undefined"!=typeof v.utm_medium||"undefined"!=typeof v.utm_campaign||"undefined"!=typeof v.utm_content||"undefined"!=typeof v.utm_term||"undefined"!=typeof v.utm_ac_id||"undefined"!=typeof v.utm_id||"undefined"!=typeof v.utm_ad_group_id||"undefined"!=typeof v.utm_ad_id||"undefined"!=typeof v.utm_term_id||"undefined"!=typeof v.gclid||"undefined"!=typeof v.yclid||"undefined"!=typeof v[y.campaign_param]||"undefined"!=typeof v[y.term_param]||"undefined"!=typeof v[y.content_param],c=a.parse(n.containers),u=c[a.unsbjs(n.containers.current)],p=f(i.traffic.organic),m=!1;if(h(),o)_(),e=d(i.traffic.utm),t=u,s=n.pack.unpack(e),m=r(t,s);else if(p)_(),e=d(i.traffic.organic),t=u,s=n.pack.unpack(e),m=r(t,s);else if(!a.get(n.containers.session)&&f(i.traffic.referral))_(),e=d(i.traffic.referral),m=!0;else{if(a.get(n.containers.first)||a.get(n.containers.current))return{data:a.get(n.containers.current),is_utm_changed:m};_(),e=d(i.traffic.typein),m=!0}return{data:e,is_utm_changed:m}}function r(e,t){return e[n.aliases.main.type]!==t[n.aliases.main.type]||e[n.aliases.main.source]!==t[n.aliases.main.source]||e[n.aliases.main.medium]!==t[n.aliases.main.medium]||e[n.aliases.main.campaign]!==t[n.aliases.main.campaign]||e[n.aliases.main.content]!==t[n.aliases.main.content]||e[n.aliases.main.term]!==t[n.aliases.main.term]}function d(e){switch(e){case i.traffic.utm:w="undefined"!=typeof v.utm_type?v.utm_type:i.traffic.utm,q="undefined"!=typeof v.utm_source?v.utm_source:"undefined"!=typeof v.gclid?"google":"undefined"!=typeof v.yclid?"yandex":i.none,I="undefined"!=typeof v.utm_medium?v.utm_medium:"undefined"!=typeof v.gclid?"cpc":"undefined"!=typeof v.yclid?"cpc":i.none,j="undefined"!=typeof v.utm_campaign?v.utm_campaign:"undefined"!=typeof v[y.campaign_param]?v[y.campaign_param]:"undefined"!=typeof v.gclid?"google_cpc":"undefined"!=typeof v.yclid?"yandex_cpc":i.none,R="undefined"!=typeof v.utm_content?v.utm_content:"undefined"!=typeof v[y.content_param]?v[y.content_param]:i.none,D="undefined"!=typeof v.utm_term?v.utm_term:"undefined"!=typeof v[y.term_param]?v[y.term_param]:p()||i.none,H="undefined"!=typeof v.utm_ac_id?v.utm_ac_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,T="undefined"!=typeof v.utm_id?v.utm_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,E="undefined"!=typeof v.utm_ad_group_id?v.utm_ad_group_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,O="undefined"!=typeof v.utm_ad_id?v.utm_ad_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,$="undefined"!=typeof v.utm_term_id?v.utm_term_id:"undefined"!=typeof v.gclid?"google_cpc":i.none;break;case i.traffic.organic:w=i.traffic.organic,q=q||s.getHost(document.referrer),I=i.referer.organic,j=i.none,R=i.none,D=i.none,H=i.none,T=i.none,E=i.none,O=i.none,$=i.none;break;case i.traffic.referral:w=i.traffic.referral,q=q||s.getHost(document.referrer),I=I||i.referer.referral,j=i.none,R=s.parse(document.referrer).path,D=i.none,H=i.none,T=i.none,E=i.none,O=i.none,$=i.none;break;case i.traffic.typein:w=i.traffic.typein,q=y.typein_attributes.source,I=y.typein_attributes.medium,j=i.none,R=i.none,D=i.none,H=i.none,T=i.none,E=i.none,O=i.none,$=i.none;break;default:w=i.oops,q=i.oops,I=i.oops,j=i.oops,R=i.oops,D=i.oops,H=i.oops,T=i.oops,E=i.oops,O=i.oops,$=i.oops}var t={type:w,source:q,medium:I,campaign:j,content:R,term:D,account_id:H,campaign_id:T,ad_group_id:E,ad_id:O,term_id:$};return n.pack.main(t)}function p(){var e=document.referrer;if(v.utm_term)return v.utm_term;if(!(e&&s.parse(e).host&&s.parse(e).host.match(/^(?:.*\.)?yandex\..{2,9}$/i)))return!1;try{return s.getParam(s.parse(document.referrer).query).text}catch(t){return!1}}function f(e){var t=document.referrer;switch(e){case i.traffic.organic:return!!t&&m(t)&&l(t);case i.traffic.referral:return!!t&&m(t)&&g(t);default:return!1}}function m(e){if(y.domain){if(x)return s.getHost(e)!==s.getHost(b);var t=new RegExp("^(?:.*\\.)?"+o.escapeRegexp(b)+"$","i");return!s.getHost(e).match(t)}return s.getHost(e)!==s.getHost(document.location.href)}function l(e){var t="yandex",r="text",n="google",i=new RegExp("^(?:.*\\.)?"+o.escapeRegexp(t)+"\\..{2,9}$"),a=new RegExp(".*"+o.escapeRegexp(r)+"=.*"),c=new RegExp("^(?:www\\.)?"+o.escapeRegexp(n)+"\\..{2,9}$");if(s.parse(e).query&&s.parse(e).host.match(i)&&s.parse(e).query.match(a))return q=t,!0;if(s.parse(e).host.match(c))return q=n,!0;if(!s.parse(e).query)return!1;for(var u=0;u<y.organics.length;u++){if(s.parse(e).host.match(new RegExp("^(?:.*\\.)?"+o.escapeRegexp(y.organics[u].host)+"$","i"))&&s.parse(e).query.match(new RegExp(".*"+o.escapeRegexp(y.organics[u].param)+"=.*","i")))return q=y.organics[u].display||y.organics[u].host,!0;if(u+1===y.organics.length)return!1}}function g(e){if(!(y.referrals.length>0))return q=s.getHost(e),!0;for(var t=0;t<y.referrals.length;t++){if(s.parse(e).host.match(new RegExp("^(?:.*\\.)?"+o.escapeRegexp(y.referrals[t].host)+"$","i")))return q=y.referrals[t].display||y.referrals[t].host,I=y.referrals[t].medium||i.referer.referral,!0;if(t+1===y.referrals.length)return q=s.getHost(e),!0}}function _(){a.set(n.containers.current_extra,n.pack.extra(y.timezone_offset),k,b,x),a.get(n.containers.first_extra)||a.set(n.containers.first_extra,n.pack.extra(y.timezone_offset),k,b,x)}function h(){var e=v.gclid||"",t=v.gbraid||"",r=v.wbraid||"",n=v.fbclid||"",i=v.ttclid||"",s="sd"===v.utm_source?v.utm_term||"":"";""!==t&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-gbraid",t,k,b,x)),""!==r&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-wbraid",r,k,b,x)),""!==e&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-gclid",e,k,b,x)),""!==n&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-fbclid",n,k,b,x)),""!==i&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-ttclid",i,k,b,x)),""!==s&&a.set("_mate-sdclid",s,k,b,x)}var y=c.fetch(e),v=s.getParam(),b=y.domain.host,x=y.domain.isolate,k=y.lifetime;u.go(k,b,x);var w,q,I,j,R,D,H,T,E,O,$;return function(){var e=t();a.set(n.containers.current,e.data,k,b,x),a.get(n.containers.first)||a.set(n.containers.first,a.get(n.containers.current),k,b,x);var r,i;a.get(n.containers.udata)?(r=parseInt(a.parse(n.containers.udata)[a.unsbjs(n.containers.udata)][n.aliases.udata.visits])||1,r=a.get(n.containers.session)?r:r+1,i=n.pack.user(r,y.user_ip)):(r=1,i=n.pack.user(r,y.user_ip)),a.set(n.containers.udata,i,k,b,x);var s,o;a.get(n.containers.session)?(s=parseInt(a.parse(n.containers.session)[a.unsbjs(n.containers.session)][n.aliases.session.pages_seen])||1,s+=1):s=1,a.get(n.containers.session)&&!e.is_utm_changed||(o=(new Date).getTime()),a.set(n.containers.session,n.pack.session(s,o),y.session_length,b,x),y.promocode&&!a.get(n.containers.promocode)&&a.set(n.containers.promocode,n.pack.promo(y.promocode),k,b,x)}(),a.parse(n.containers)}},{"./data":2,"./helpers/cookies":3,"./helpers/uri":4,"./helpers/utils":5,"./migrations":7,"./params":8,"./terms":9}],7:[function(e,t,r){"use strict";var n=e("./data"),i=e("./helpers/cookies");t.exports={go:function(e,t,r){var a,s=this.migrations,o={l:e,d:t,i:r};if(i.get(n.containers.first)||i.get(n.service.migrations)){if(!i.get(n.service.migrations))for(a=0;a<s.length;a++)s[a].go(s[a].id,o)}else{var c=[];for(a=0;a<s.length;a++)c.push(s[a].id);var u="";for(a=0;a<c.length;a++)u+=c[a]+"=1",a<c.length-1&&(u+=n.delimiter);i.set(n.service.migrations,u,o.l,o.d,o.i)}},migrations:[{id:"1418474375998",version:"1.0.0-beta",go:function(e,t){var r=e+"=1",a=e+"=0",s=function(e,t,r){return t||r?e:n.delimiter};try{var o=[];for(var c in n.containers)n.containers.hasOwnProperty(c)&&o.push(n.containers[c]);for(var u=0;u<o.length;u++)if(i.get(o[u])){var d=i.get(o[u]).replace(/(\|)?\|(\|)?/g,s);i.destroy(o[u],t.d,t.i),i.destroy(o[u],t.d,!t.i),i.set(o[u],d,t.l,t.d,t.i)}i.get(n.containers.session)&&i.set(n.containers.session,n.pack.session(0),t.l,t.d,t.i),i.set(n.service.migrations,r,t.l,t.d,t.i)}catch(p){i.set(n.service.migrations,a,t.l,t.d,t.i)}}}]}},{"./data":2,"./helpers/cookies":3}],8:[function(e,t,r){"use strict";var n=e("./terms"),i=e("./helpers/uri");t.exports={fetch:function(e){var t=e||{},r={};if(r.lifetime=this.validate.checkFloat(t.lifetime)||6,r.lifetime=parseInt(30*r.lifetime*24*60),r.session_length=this.validate.checkInt(t.session_length)||30,r.timezone_offset=this.validate.checkInt(t.timezone_offset),r.campaign_param=t.campaign_param||!1,r.term_param=t.term_param||!1,r.content_param=t.content_param||!1,r.user_ip=t.user_ip||n.none,t.promocode?(r.promocode={},r.promocode.min=parseInt(t.promocode.min)||1e5,r.promocode.max=parseInt(t.promocode.max)||999999):r.promocode=!1,t.typein_attributes&&t.typein_attributes.source&&t.typein_attributes.medium?(r.typein_attributes={},r.typein_attributes.source=t.typein_attributes.source,r.typein_attributes.medium=t.typein_attributes.medium):r.typein_attributes={source:"(direct)",medium:"(none)"},t.domain&&this.validate.isString(t.domain)?r.domain={host:t.domain,isolate:!1}:t.domain&&t.domain.host?r.domain=t.domain:r.domain={host:i.getHost(document.location.hostname),isolate:!1},r.referrals=[],t.referrals&&t.referrals.length>0)for(var a=0;a<t.referrals.length;a++)t.referrals[a].host&&r.referrals.push(t.referrals[a]);if(r.organics=[],t.organics&&t.organics.length>0)for(var s=0;s<t.organics.length;s++)t.organics[s].host&&t.organics[s].param&&r.organics.push(t.organics[s]);return r.organics.push({host:"bing.com",param:"q",display:"bing"}),r.organics.push({host:"yahoo.com",param:"p",display:"yahoo"}),r.organics.push({host:"about.com",param:"q",display:"about"}),r.organics.push({host:"aol.com",param:"q",display:"aol"}),r.organics.push({host:"ask.com",param:"q",display:"ask"}),r.organics.push({host:"globososo.com",param:"q",display:"globo"}),r.organics.push({host:"go.mail.ru",param:"q",display:"go.mail.ru"}),r.organics.push({host:"rambler.ru",param:"query",display:"rambler"}),r.organics.push({host:"tut.by",param:"query",display:"tut.by"}),r.referrals.push({host:"t.co",display:"twitter.com"}),r.referrals.push({host:"plus.url.google.com",display:"plus.google.com"}),r},validate:{checkFloat:function(e){return!(!e||!this.isNumeric(parseFloat(e)))&&parseFloat(e)},checkInt:function(e){return!(!e||!this.isNumeric(parseInt(e)))&&parseInt(e)},isNumeric:function(e){return!isNaN(e)},isString:function(e){return"[object String]"===Object.prototype.toString.call(e)}}}},{"./helpers/uri":4,"./terms":9}],9:[function(e,t,r){"use strict";t.exports={traffic:{utm:"utm",organic:"organic",referral:"referral",typein:"typein"},referer:{referral:"referral",organic:"organic",social:"social"},none:"(none)",oops:"(Houston, we have a problem)"}},{}]},{},[1])(1)});
1
+ /** @mate-academy/sourcebuster v1.5.1 **/
2
+ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.sbjs=e()}}(function(){return function e(t,r,n){function i(s,o){if(!r[s]){if(!t[s]){var c="function"==typeof require&&require;if(!o&&c)return c(s,!0);if(a)return a(s,!0);var d=new Error("Cannot find module '"+s+"'");throw d.code="MODULE_NOT_FOUND",d}var u=r[s]={exports:{}};t[s][0].call(u.exports,function(e){var r=t[s][1][e];return i(r?r:e)},u,u.exports,e,t,r,n)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(e,t,r){"use strict";var n=e("./init"),i={init:function(e){this.get=n(e),e&&e.callback&&"function"==typeof e.callback&&e.callback(this.get)}};t.exports=i,"undefined"!=typeof window&&"undefined"!=typeof CustomEvent&&window.dispatchEvent(new CustomEvent("sbjs:loaded"))},{"./init":6}],2:[function(e,t,r){"use strict";var n=e("./terms"),i=e("./helpers/utils"),a={containers:{current:"sbjs_current",current_extra:"sbjs_current_add",first:"sbjs_first",first_extra:"sbjs_first_add",session:"sbjs_session",udata:"sbjs_udata",promocode:"sbjs_promo"},service:{migrations:"sbjs_migrations"},delimiter:"|||",aliases:{main:{type:"typ",source:"src",medium:"mdm",campaign:"cmp",content:"cnt",term:"trm",account_id:"ac_id",campaign_id:"cmp_id",ad_group_id:"adg_id",ad_id:"ad_id",term_id:"trm_id"},extra:{fire_date:"fd",entrance_point:"ep",referer:"rf"},session:{pages_seen:"pgs",current_page:"cpg",session_id:"sid"},udata:{visits:"vst",ip:"uip",agent:"uag"},promo:"code"},pack:{main:function(e){return a.aliases.main.type+"="+e.type+a.delimiter+a.aliases.main.source+"="+e.source+a.delimiter+a.aliases.main.medium+"="+e.medium+a.delimiter+a.aliases.main.campaign+"="+e.campaign+a.delimiter+a.aliases.main.content+"="+e.content+a.delimiter+a.aliases.main.term+"="+e.term+a.delimiter+a.aliases.main.account_id+"="+e.account_id+a.delimiter+a.aliases.main.campaign_id+"="+e.campaign_id+a.delimiter+a.aliases.main.ad_group_id+"="+e.ad_group_id+a.delimiter+a.aliases.main.ad_id+"="+e.ad_id+a.delimiter+a.aliases.main.term_id+"="+e.term_id},unpack:function(e){var t={},r=e.split("|||");return r.forEach(function(e){var r=e.split("="),n=r[0],i=r[1];t[n]=i}),t},extra:function(e){return a.aliases.extra.fire_date+"="+i.setDate(new Date,e)+a.delimiter+a.aliases.extra.entrance_point+"="+document.location.href+a.delimiter+a.aliases.extra.referer+"="+(document.referrer||n.none)},user:function(e,t){return a.aliases.udata.visits+"="+e+a.delimiter+a.aliases.udata.ip+"="+t+a.delimiter+a.aliases.udata.agent+"="+navigator.userAgent},session:function(e,t){var r=a.aliases.session.pages_seen+"="+e+a.delimiter+a.aliases.session.current_page+"="+document.location.href;return t?r+a.delimiter+a.aliases.session.session_id+"="+t:r},promo:function(e){return a.aliases.promo+"="+i.setLeadingZeroToInt(i.randomInt(e.min,e.max),e.max.toString().length)}}};t.exports=a},{"./helpers/utils":5,"./terms":9}],3:[function(e,t,r){"use strict";var n=e("../data").delimiter;t.exports={encodeData:function(e){return encodeURIComponent(e).replace(/\!/g,"%21").replace(/\~/g,"%7E").replace(/\*/g,"%2A").replace(/\'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")},decodeData:function(e){try{return decodeURIComponent(e).replace(/\%21/g,"!").replace(/\%7E/g,"~").replace(/\%2A/g,"*").replace(/\%27/g,"'").replace(/\%28/g,"(").replace(/\%29/g,")")}catch(t){try{return unescape(e)}catch(r){return""}}},set:function(e,t,r,n,i){var a,s;if(r){var o=new Date;o.setTime(o.getTime()+60*r*1e3),a="; expires="+o.toGMTString()}else a="";s=n&&!i?";domain=."+n:"",document.cookie=this.encodeData(e)+"="+this.encodeData(t)+a+s+"; path=/"},get:function(e){for(var t=this.encodeData(e)+"=",r=document.cookie.split(";"),n=0;n<r.length;n++){for(var i=r[n];" "===i.charAt(0);)i=i.substring(1,i.length);if(0===i.indexOf(t))return this.decodeData(i.substring(t.length,i.length))}return null},destroy:function(e,t,r){this.set(e,"",-1,t,r)},parse:function(e){var t=[],r={};if("string"==typeof e)t.push(e);else for(var i in e)e.hasOwnProperty(i)&&t.push(e[i]);for(var a=0;a<t.length;a++){var s;r[this.unsbjs(t[a])]={},s=this.get(t[a])?this.get(t[a]).split(n):[];for(var o=0;o<s.length;o++){var c=s[o].split("="),d=c.splice(0,1);d.push(c.join("=")),r[this.unsbjs(t[a])][d[0]]=this.decodeData(d[1])}}return r},unsbjs:function(e){return e.replace("sbjs_","")}}},{"../data":2}],4:[function(e,t,r){"use strict";t.exports={parse:function(e){for(var t=this.parseOptions,r=t.parser[t.strictMode?"strict":"loose"].exec(e),n={},i=14;i--;)n[t.key[i]]=r[i]||"";return n[t.q.name]={},n[t.key[12]].replace(t.q.parser,function(e,r,i){r&&(n[t.q.name][r]=i)}),n},parseOptions:{strictMode:!1,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}},getParam:function(e){for(var t={},r=e?e:window.location.search.substring(1),n=r.split("&"),i=0;i<n.length;i++){var a=n[i].split("=");if("undefined"==typeof t[a[0]])t[a[0]]=a[1];else if("string"==typeof t[a[0]]){var s=[t[a[0]],a[1]];t[a[0]]=s}else t[a[0]].push(a[1])}return t},getHost:function(e){return this.parse(e).host.replace("www.","")}}},{}],5:[function(e,t,r){"use strict";t.exports={escapeRegexp:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},setDate:function(e,t){var r=e.getTimezoneOffset()/60,n=e.getHours(),i=t||0===t?t:-r;e.setHours(n+r+i);var a=e.getFullYear(),s=this.setLeadingZeroToInt(e.getMonth()+1,2),o=this.setLeadingZeroToInt(e.getDate(),2),c=this.setLeadingZeroToInt(e.getHours(),2),d=this.setLeadingZeroToInt(e.getMinutes(),2),u=this.setLeadingZeroToInt(e.getSeconds(),2);return a+"-"+s+"-"+o+" "+c+":"+d+":"+u},setLeadingZeroToInt:function(e,t){for(var r=e+"";r.length<t;)r="0"+r;return r},randomInt:function(e,t){return Math.floor(Math.random()*(t-e+1))+e}}},{}],6:[function(e,t,r){"use strict";var n=e("./data"),i=e("./terms"),a=e("./helpers/cookies"),s=e("./helpers/uri"),o=e("./helpers/utils"),c=e("./params"),d=e("./migrations");t.exports=function(e){function t(){var e,t,s,o="undefined"!=typeof v.utm_source||"undefined"!=typeof v.utm_medium||"undefined"!=typeof v.utm_campaign||"undefined"!=typeof v.utm_content||"undefined"!=typeof v.utm_term||"undefined"!=typeof v.utm_ac_id||"undefined"!=typeof v.utm_id||"undefined"!=typeof v.utm_ad_group_id||"undefined"!=typeof v.utm_ad_id||"undefined"!=typeof v.utm_term_id||"undefined"!=typeof v.gclid||"undefined"!=typeof v.yclid||"undefined"!=typeof v[y.campaign_param]||"undefined"!=typeof v[y.term_param]||"undefined"!=typeof v[y.content_param],c=a.parse(n.containers),d=c[a.unsbjs(n.containers.current)],p=m(i.traffic.organic),f=!1;if(h(),o)_(),e=u(i.traffic.utm),t=d,s=n.pack.unpack(e),f=r(t,s);else if(p)_(),e=u(i.traffic.organic),t=d,s=n.pack.unpack(e),f=r(t,s);else if(!a.get(n.containers.session)&&m(i.traffic.referral))_(),e=u(i.traffic.referral),f=!0;else{if(a.get(n.containers.first)||a.get(n.containers.current))return{data:a.get(n.containers.current),is_utm_changed:f};_(),e=u(i.traffic.typein),f=!0}return{data:e,is_utm_changed:f}}function r(e,t){return e[n.aliases.main.type]!==t[n.aliases.main.type]||e[n.aliases.main.source]!==t[n.aliases.main.source]||e[n.aliases.main.medium]!==t[n.aliases.main.medium]||e[n.aliases.main.campaign]!==t[n.aliases.main.campaign]||e[n.aliases.main.content]!==t[n.aliases.main.content]||e[n.aliases.main.term]!==t[n.aliases.main.term]}function u(e){switch(e){case i.traffic.utm:w="undefined"!=typeof v.utm_type?v.utm_type:i.traffic.utm,q="undefined"!=typeof v.utm_source?v.utm_source:"undefined"!=typeof v.gclid?"google":"undefined"!=typeof v.yclid?"yandex":i.none,I="undefined"!=typeof v.utm_medium?v.utm_medium:"undefined"!=typeof v.gclid?"cpc":"undefined"!=typeof v.yclid?"cpc":i.none,j="undefined"!=typeof v.utm_campaign?v.utm_campaign:"undefined"!=typeof v[y.campaign_param]?v[y.campaign_param]:"undefined"!=typeof v.gclid?"google_cpc":"undefined"!=typeof v.yclid?"yandex_cpc":i.none,R="undefined"!=typeof v.utm_content?v.utm_content:"undefined"!=typeof v[y.content_param]?v[y.content_param]:i.none,D="undefined"!=typeof v.utm_term?v.utm_term:"undefined"!=typeof v[y.term_param]?v[y.term_param]:p()||i.none,E="undefined"!=typeof v.utm_ac_id?v.utm_ac_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,H="undefined"!=typeof v.utm_id?v.utm_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,T="undefined"!=typeof v.utm_ad_group_id?v.utm_ad_group_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,O="undefined"!=typeof v.utm_ad_id?v.utm_ad_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,$="undefined"!=typeof v.utm_term_id?v.utm_term_id:"undefined"!=typeof v.gclid?"google_cpc":i.none;break;case i.traffic.organic:w=i.traffic.organic,q=q||s.getHost(document.referrer),I=i.referer.organic,j=i.none,R=i.none,D=i.none,E=i.none,H=i.none,T=i.none,O=i.none,$=i.none;break;case i.traffic.referral:w=i.traffic.referral,q=q||s.getHost(document.referrer),I=I||i.referer.referral,j=i.none,R=s.parse(document.referrer).path,D=i.none,E=i.none,H=i.none,T=i.none,O=i.none,$=i.none;break;case i.traffic.typein:w=i.traffic.typein,q=y.typein_attributes.source,I=y.typein_attributes.medium,j=i.none,R=i.none,D=i.none,E=i.none,H=i.none,T=i.none,O=i.none,$=i.none;break;default:w=i.oops,q=i.oops,I=i.oops,j=i.oops,R=i.oops,D=i.oops,E=i.oops,H=i.oops,T=i.oops,O=i.oops,$=i.oops}var t={type:w,source:q,medium:I,campaign:j,content:R,term:D,account_id:E,campaign_id:H,ad_group_id:T,ad_id:O,term_id:$};return n.pack.main(t)}function p(){var e=document.referrer;if(v.utm_term)return v.utm_term;if(!(e&&s.parse(e).host&&s.parse(e).host.match(/^(?:.*\.)?yandex\..{2,9}$/i)))return!1;try{return s.getParam(s.parse(document.referrer).query).text}catch(t){return!1}}function m(e){var t=document.referrer;switch(e){case i.traffic.organic:return!!t&&f(t)&&l(t);case i.traffic.referral:return!!t&&f(t)&&g(t);default:return!1}}function f(e){if(y.domain){if(x)return s.getHost(e)!==s.getHost(b);var t=new RegExp("^(?:.*\\.)?"+o.escapeRegexp(b)+"$","i");return!s.getHost(e).match(t)}return s.getHost(e)!==s.getHost(document.location.href)}function l(e){var t="yandex",r="text",n="google",i=new RegExp("^(?:.*\\.)?"+o.escapeRegexp(t)+"\\..{2,9}$"),a=new RegExp(".*"+o.escapeRegexp(r)+"=.*"),c=new RegExp("^(?:www\\.)?"+o.escapeRegexp(n)+"\\..{2,9}$");if(s.parse(e).query&&s.parse(e).host.match(i)&&s.parse(e).query.match(a))return q=t,!0;if(s.parse(e).host.match(c))return q=n,!0;if(!s.parse(e).query)return!1;for(var d=0;d<y.organics.length;d++){if(s.parse(e).host.match(new RegExp("^(?:.*\\.)?"+o.escapeRegexp(y.organics[d].host)+"$","i"))&&s.parse(e).query.match(new RegExp(".*"+o.escapeRegexp(y.organics[d].param)+"=.*","i")))return q=y.organics[d].display||y.organics[d].host,!0;if(d+1===y.organics.length)return!1}}function g(e){if(!(y.referrals.length>0))return q=s.getHost(e),!0;for(var t=0;t<y.referrals.length;t++){if(s.parse(e).host.match(new RegExp("^(?:.*\\.)?"+o.escapeRegexp(y.referrals[t].host)+"$","i")))return q=y.referrals[t].display||y.referrals[t].host,I=y.referrals[t].medium||i.referer.referral,!0;if(t+1===y.referrals.length)return q=s.getHost(e),!0}}function _(){a.set(n.containers.current_extra,n.pack.extra(y.timezone_offset),k,b,x),a.get(n.containers.first_extra)||a.set(n.containers.first_extra,n.pack.extra(y.timezone_offset),k,b,x)}function h(){var e=43200,t=v.gclid||"",r=v.gbraid||"",n=v.wbraid||"",i=v.fbclid||"",s=v.ttclid||"",o="sd"===v.utm_source?v.utm_term||"":"",c=v.ks_click_id||"";""!==r&&(a.destroy("_mate-sdclid",b,x),a.destroy("_mate-ksclid",b,x),a.set("_mate-gbraid",r,k,b,x)),""!==n&&(a.destroy("_mate-sdclid",b,x),a.destroy("_mate-ksclid",b,x),a.set("_mate-wbraid",n,k,b,x)),""!==t&&(a.destroy("_mate-sdclid",b,x),a.destroy("_mate-ksclid",b,x),a.set("_mate-gclid",t,k,b,x)),""!==i&&(a.destroy("_mate-sdclid",b,x),a.destroy("_mate-ksclid",b,x),a.set("_mate-fbclid",i,k,b,x)),""!==s&&(a.destroy("_mate-sdclid",b,x),a.destroy("_mate-ksclid",b,x),a.set("_mate-ttclid",s,k,b,x)),""!==o&&(a.destroy("_mate-ksclid",b,x),a.set("_mate-sdclid",o,e,b,x)),""!==c&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-ksclid",c,e,b,x))}var y=c.fetch(e),v=s.getParam(),b=y.domain.host,x=y.domain.isolate,k=y.lifetime;d.go(k,b,x);var w,q,I,j,R,D,E,H,T,O,$;return function(){var e=t();a.set(n.containers.current,e.data,k,b,x),a.get(n.containers.first)||a.set(n.containers.first,a.get(n.containers.current),k,b,x);var r,i;a.get(n.containers.udata)?(r=parseInt(a.parse(n.containers.udata)[a.unsbjs(n.containers.udata)][n.aliases.udata.visits])||1,r=a.get(n.containers.session)?r:r+1,i=n.pack.user(r,y.user_ip)):(r=1,i=n.pack.user(r,y.user_ip)),a.set(n.containers.udata,i,k,b,x);var s,o;a.get(n.containers.session)?(s=parseInt(a.parse(n.containers.session)[a.unsbjs(n.containers.session)][n.aliases.session.pages_seen])||1,s+=1):s=1,a.get(n.containers.session)&&!e.is_utm_changed||(o=(new Date).getTime()),a.set(n.containers.session,n.pack.session(s,o),y.session_length,b,x),y.promocode&&!a.get(n.containers.promocode)&&a.set(n.containers.promocode,n.pack.promo(y.promocode),k,b,x)}(),a.parse(n.containers)}},{"./data":2,"./helpers/cookies":3,"./helpers/uri":4,"./helpers/utils":5,"./migrations":7,"./params":8,"./terms":9}],7:[function(e,t,r){"use strict";var n=e("./data"),i=e("./helpers/cookies");t.exports={go:function(e,t,r){var a,s=this.migrations,o={l:e,d:t,i:r};if(i.get(n.containers.first)||i.get(n.service.migrations)){if(!i.get(n.service.migrations))for(a=0;a<s.length;a++)s[a].go(s[a].id,o)}else{var c=[];for(a=0;a<s.length;a++)c.push(s[a].id);var d="";for(a=0;a<c.length;a++)d+=c[a]+"=1",a<c.length-1&&(d+=n.delimiter);i.set(n.service.migrations,d,o.l,o.d,o.i)}},migrations:[{id:"1418474375998",version:"1.0.0-beta",go:function(e,t){var r=e+"=1",a=e+"=0",s=function(e,t,r){return t||r?e:n.delimiter};try{var o=[];for(var c in n.containers)n.containers.hasOwnProperty(c)&&o.push(n.containers[c]);for(var d=0;d<o.length;d++)if(i.get(o[d])){var u=i.get(o[d]).replace(/(\|)?\|(\|)?/g,s);i.destroy(o[d],t.d,t.i),i.destroy(o[d],t.d,!t.i),i.set(o[d],u,t.l,t.d,t.i)}i.get(n.containers.session)&&i.set(n.containers.session,n.pack.session(0),t.l,t.d,t.i),i.set(n.service.migrations,r,t.l,t.d,t.i)}catch(p){i.set(n.service.migrations,a,t.l,t.d,t.i)}}}]}},{"./data":2,"./helpers/cookies":3}],8:[function(e,t,r){"use strict";var n=e("./terms"),i=e("./helpers/uri");t.exports={fetch:function(e){var t=e||{},r={};if(r.lifetime=this.validate.checkFloat(t.lifetime)||6,r.lifetime=parseInt(30*r.lifetime*24*60),r.session_length=this.validate.checkInt(t.session_length)||30,r.timezone_offset=this.validate.checkInt(t.timezone_offset),r.campaign_param=t.campaign_param||!1,r.term_param=t.term_param||!1,r.content_param=t.content_param||!1,r.user_ip=t.user_ip||n.none,t.promocode?(r.promocode={},r.promocode.min=parseInt(t.promocode.min)||1e5,r.promocode.max=parseInt(t.promocode.max)||999999):r.promocode=!1,t.typein_attributes&&t.typein_attributes.source&&t.typein_attributes.medium?(r.typein_attributes={},r.typein_attributes.source=t.typein_attributes.source,r.typein_attributes.medium=t.typein_attributes.medium):r.typein_attributes={source:"(direct)",medium:"(none)"},t.domain&&this.validate.isString(t.domain)?r.domain={host:t.domain,isolate:!1}:t.domain&&t.domain.host?r.domain=t.domain:r.domain={host:i.getHost(document.location.hostname),isolate:!1},r.referrals=[],t.referrals&&t.referrals.length>0)for(var a=0;a<t.referrals.length;a++)t.referrals[a].host&&r.referrals.push(t.referrals[a]);if(r.organics=[],t.organics&&t.organics.length>0)for(var s=0;s<t.organics.length;s++)t.organics[s].host&&t.organics[s].param&&r.organics.push(t.organics[s]);return r.organics.push({host:"bing.com",param:"q",display:"bing"}),r.organics.push({host:"yahoo.com",param:"p",display:"yahoo"}),r.organics.push({host:"about.com",param:"q",display:"about"}),r.organics.push({host:"aol.com",param:"q",display:"aol"}),r.organics.push({host:"ask.com",param:"q",display:"ask"}),r.organics.push({host:"globososo.com",param:"q",display:"globo"}),r.organics.push({host:"go.mail.ru",param:"q",display:"go.mail.ru"}),r.organics.push({host:"rambler.ru",param:"query",display:"rambler"}),r.organics.push({host:"tut.by",param:"query",display:"tut.by"}),r.referrals.push({host:"t.co",display:"twitter.com"}),r.referrals.push({host:"plus.url.google.com",display:"plus.google.com"}),r},validate:{checkFloat:function(e){return!(!e||!this.isNumeric(parseFloat(e)))&&parseFloat(e)},checkInt:function(e){return!(!e||!this.isNumeric(parseInt(e)))&&parseInt(e)},isNumeric:function(e){return!isNaN(e)},isString:function(e){return"[object String]"===Object.prototype.toString.call(e)}}}},{"./helpers/uri":4,"./terms":9}],9:[function(e,t,r){"use strict";t.exports={traffic:{utm:"utm",organic:"organic",referral:"referral",typein:"typein"},referer:{referral:"referral",organic:"organic",social:"social"},none:"(none)",oops:"(Houston, we have a problem)"}},{}]},{},[1])(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mate-academy/sourcebuster",
3
- "version": "1.4.1",
3
+ "version": "1.5.1",
4
4
  "description": "Get sources of your site's visitors (utm / organic / referral / typein).",
5
5
  "license": "MIT",
6
6
  "main": "./dist/sourcebuster.js",
@@ -1,2 +1,2 @@
1
- /** @mate-academy/sourcebuster v1.4.1 **/
2
- !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.sbjs=e()}}(function(){return function e(t,r,n){function i(s,o){if(!r[s]){if(!t[s]){var c="function"==typeof require&&require;if(!o&&c)return c(s,!0);if(a)return a(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var d=r[s]={exports:{}};t[s][0].call(d.exports,function(e){var r=t[s][1][e];return i(r?r:e)},d,d.exports,e,t,r,n)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(e,t,r){"use strict";var n=e("./init"),i={init:function(e){this.get=n(e),e&&e.callback&&"function"==typeof e.callback&&e.callback(this.get)}};t.exports=i},{"./init":6}],2:[function(e,t,r){"use strict";var n=e("./terms"),i=e("./helpers/utils"),a={containers:{current:"sbjs_current",current_extra:"sbjs_current_add",first:"sbjs_first",first_extra:"sbjs_first_add",session:"sbjs_session",udata:"sbjs_udata",promocode:"sbjs_promo"},service:{migrations:"sbjs_migrations"},delimiter:"|||",aliases:{main:{type:"typ",source:"src",medium:"mdm",campaign:"cmp",content:"cnt",term:"trm",account_id:"ac_id",campaign_id:"cmp_id",ad_group_id:"adg_id",ad_id:"ad_id",term_id:"trm_id"},extra:{fire_date:"fd",entrance_point:"ep",referer:"rf"},session:{pages_seen:"pgs",current_page:"cpg",session_id:"sid"},udata:{visits:"vst",ip:"uip",agent:"uag"},promo:"code"},pack:{main:function(e){return a.aliases.main.type+"="+e.type+a.delimiter+a.aliases.main.source+"="+e.source+a.delimiter+a.aliases.main.medium+"="+e.medium+a.delimiter+a.aliases.main.campaign+"="+e.campaign+a.delimiter+a.aliases.main.content+"="+e.content+a.delimiter+a.aliases.main.term+"="+e.term+a.delimiter+a.aliases.main.account_id+"="+e.account_id+a.delimiter+a.aliases.main.campaign_id+"="+e.campaign_id+a.delimiter+a.aliases.main.ad_group_id+"="+e.ad_group_id+a.delimiter+a.aliases.main.ad_id+"="+e.ad_id+a.delimiter+a.aliases.main.term_id+"="+e.term_id},unpack:function(e){var t={},r=e.split("|||");return r.forEach(function(e){var r=e.split("="),n=r[0],i=r[1];t[n]=i}),t},extra:function(e){return a.aliases.extra.fire_date+"="+i.setDate(new Date,e)+a.delimiter+a.aliases.extra.entrance_point+"="+document.location.href+a.delimiter+a.aliases.extra.referer+"="+(document.referrer||n.none)},user:function(e,t){return a.aliases.udata.visits+"="+e+a.delimiter+a.aliases.udata.ip+"="+t+a.delimiter+a.aliases.udata.agent+"="+navigator.userAgent},session:function(e,t){var r=a.aliases.session.pages_seen+"="+e+a.delimiter+a.aliases.session.current_page+"="+document.location.href;return t?r+a.delimiter+a.aliases.session.session_id+"="+t:r},promo:function(e){return a.aliases.promo+"="+i.setLeadingZeroToInt(i.randomInt(e.min,e.max),e.max.toString().length)}}};t.exports=a},{"./helpers/utils":5,"./terms":9}],3:[function(e,t,r){"use strict";var n=e("../data").delimiter;t.exports={encodeData:function(e){return encodeURIComponent(e).replace(/\!/g,"%21").replace(/\~/g,"%7E").replace(/\*/g,"%2A").replace(/\'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")},decodeData:function(e){try{return decodeURIComponent(e).replace(/\%21/g,"!").replace(/\%7E/g,"~").replace(/\%2A/g,"*").replace(/\%27/g,"'").replace(/\%28/g,"(").replace(/\%29/g,")")}catch(t){try{return unescape(e)}catch(r){return""}}},set:function(e,t,r,n,i){var a,s;if(r){var o=new Date;o.setTime(o.getTime()+60*r*1e3),a="; expires="+o.toGMTString()}else a="";s=n&&!i?";domain=."+n:"",document.cookie=this.encodeData(e)+"="+this.encodeData(t)+a+s+"; path=/"},get:function(e){for(var t=this.encodeData(e)+"=",r=document.cookie.split(";"),n=0;n<r.length;n++){for(var i=r[n];" "===i.charAt(0);)i=i.substring(1,i.length);if(0===i.indexOf(t))return this.decodeData(i.substring(t.length,i.length))}return null},destroy:function(e,t,r){this.set(e,"",-1,t,r)},parse:function(e){var t=[],r={};if("string"==typeof e)t.push(e);else for(var i in e)e.hasOwnProperty(i)&&t.push(e[i]);for(var a=0;a<t.length;a++){var s;r[this.unsbjs(t[a])]={},s=this.get(t[a])?this.get(t[a]).split(n):[];for(var o=0;o<s.length;o++){var c=s[o].split("="),u=c.splice(0,1);u.push(c.join("=")),r[this.unsbjs(t[a])][u[0]]=this.decodeData(u[1])}}return r},unsbjs:function(e){return e.replace("sbjs_","")}}},{"../data":2}],4:[function(e,t,r){"use strict";t.exports={parse:function(e){for(var t=this.parseOptions,r=t.parser[t.strictMode?"strict":"loose"].exec(e),n={},i=14;i--;)n[t.key[i]]=r[i]||"";return n[t.q.name]={},n[t.key[12]].replace(t.q.parser,function(e,r,i){r&&(n[t.q.name][r]=i)}),n},parseOptions:{strictMode:!1,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}},getParam:function(e){for(var t={},r=e?e:window.location.search.substring(1),n=r.split("&"),i=0;i<n.length;i++){var a=n[i].split("=");if("undefined"==typeof t[a[0]])t[a[0]]=a[1];else if("string"==typeof t[a[0]]){var s=[t[a[0]],a[1]];t[a[0]]=s}else t[a[0]].push(a[1])}return t},getHost:function(e){return this.parse(e).host.replace("www.","")}}},{}],5:[function(e,t,r){"use strict";t.exports={escapeRegexp:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},setDate:function(e,t){var r=e.getTimezoneOffset()/60,n=e.getHours(),i=t||0===t?t:-r;e.setHours(n+r+i);var a=e.getFullYear(),s=this.setLeadingZeroToInt(e.getMonth()+1,2),o=this.setLeadingZeroToInt(e.getDate(),2),c=this.setLeadingZeroToInt(e.getHours(),2),u=this.setLeadingZeroToInt(e.getMinutes(),2),d=this.setLeadingZeroToInt(e.getSeconds(),2);return a+"-"+s+"-"+o+" "+c+":"+u+":"+d},setLeadingZeroToInt:function(e,t){for(var r=e+"";r.length<t;)r="0"+r;return r},randomInt:function(e,t){return Math.floor(Math.random()*(t-e+1))+e}}},{}],6:[function(e,t,r){"use strict";var n=e("./data"),i=e("./terms"),a=e("./helpers/cookies"),s=e("./helpers/uri"),o=e("./helpers/utils"),c=e("./params"),u=e("./migrations");t.exports=function(e){function t(){var e,t,s,o="undefined"!=typeof v.utm_source||"undefined"!=typeof v.utm_medium||"undefined"!=typeof v.utm_campaign||"undefined"!=typeof v.utm_content||"undefined"!=typeof v.utm_term||"undefined"!=typeof v.utm_ac_id||"undefined"!=typeof v.utm_id||"undefined"!=typeof v.utm_ad_group_id||"undefined"!=typeof v.utm_ad_id||"undefined"!=typeof v.utm_term_id||"undefined"!=typeof v.gclid||"undefined"!=typeof v.yclid||"undefined"!=typeof v[y.campaign_param]||"undefined"!=typeof v[y.term_param]||"undefined"!=typeof v[y.content_param],c=a.parse(n.containers),u=c[a.unsbjs(n.containers.current)],p=f(i.traffic.organic),m=!1;if(h(),o)_(),e=d(i.traffic.utm),t=u,s=n.pack.unpack(e),m=r(t,s);else if(p)_(),e=d(i.traffic.organic),t=u,s=n.pack.unpack(e),m=r(t,s);else if(!a.get(n.containers.session)&&f(i.traffic.referral))_(),e=d(i.traffic.referral),m=!0;else{if(a.get(n.containers.first)||a.get(n.containers.current))return{data:a.get(n.containers.current),is_utm_changed:m};_(),e=d(i.traffic.typein),m=!0}return{data:e,is_utm_changed:m}}function r(e,t){return e[n.aliases.main.type]!==t[n.aliases.main.type]||e[n.aliases.main.source]!==t[n.aliases.main.source]||e[n.aliases.main.medium]!==t[n.aliases.main.medium]||e[n.aliases.main.campaign]!==t[n.aliases.main.campaign]||e[n.aliases.main.content]!==t[n.aliases.main.content]||e[n.aliases.main.term]!==t[n.aliases.main.term]}function d(e){switch(e){case i.traffic.utm:w="undefined"!=typeof v.utm_type?v.utm_type:i.traffic.utm,q="undefined"!=typeof v.utm_source?v.utm_source:"undefined"!=typeof v.gclid?"google":"undefined"!=typeof v.yclid?"yandex":i.none,I="undefined"!=typeof v.utm_medium?v.utm_medium:"undefined"!=typeof v.gclid?"cpc":"undefined"!=typeof v.yclid?"cpc":i.none,j="undefined"!=typeof v.utm_campaign?v.utm_campaign:"undefined"!=typeof v[y.campaign_param]?v[y.campaign_param]:"undefined"!=typeof v.gclid?"google_cpc":"undefined"!=typeof v.yclid?"yandex_cpc":i.none,R="undefined"!=typeof v.utm_content?v.utm_content:"undefined"!=typeof v[y.content_param]?v[y.content_param]:i.none,D="undefined"!=typeof v.utm_term?v.utm_term:"undefined"!=typeof v[y.term_param]?v[y.term_param]:p()||i.none,H="undefined"!=typeof v.utm_ac_id?v.utm_ac_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,T="undefined"!=typeof v.utm_id?v.utm_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,E="undefined"!=typeof v.utm_ad_group_id?v.utm_ad_group_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,O="undefined"!=typeof v.utm_ad_id?v.utm_ad_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,$="undefined"!=typeof v.utm_term_id?v.utm_term_id:"undefined"!=typeof v.gclid?"google_cpc":i.none;break;case i.traffic.organic:w=i.traffic.organic,q=q||s.getHost(document.referrer),I=i.referer.organic,j=i.none,R=i.none,D=i.none,H=i.none,T=i.none,E=i.none,O=i.none,$=i.none;break;case i.traffic.referral:w=i.traffic.referral,q=q||s.getHost(document.referrer),I=I||i.referer.referral,j=i.none,R=s.parse(document.referrer).path,D=i.none,H=i.none,T=i.none,E=i.none,O=i.none,$=i.none;break;case i.traffic.typein:w=i.traffic.typein,q=y.typein_attributes.source,I=y.typein_attributes.medium,j=i.none,R=i.none,D=i.none,H=i.none,T=i.none,E=i.none,O=i.none,$=i.none;break;default:w=i.oops,q=i.oops,I=i.oops,j=i.oops,R=i.oops,D=i.oops,H=i.oops,T=i.oops,E=i.oops,O=i.oops,$=i.oops}var t={type:w,source:q,medium:I,campaign:j,content:R,term:D,account_id:H,campaign_id:T,ad_group_id:E,ad_id:O,term_id:$};return n.pack.main(t)}function p(){var e=document.referrer;if(v.utm_term)return v.utm_term;if(!(e&&s.parse(e).host&&s.parse(e).host.match(/^(?:.*\.)?yandex\..{2,9}$/i)))return!1;try{return s.getParam(s.parse(document.referrer).query).text}catch(t){return!1}}function f(e){var t=document.referrer;switch(e){case i.traffic.organic:return!!t&&m(t)&&l(t);case i.traffic.referral:return!!t&&m(t)&&g(t);default:return!1}}function m(e){if(y.domain){if(x)return s.getHost(e)!==s.getHost(b);var t=new RegExp("^(?:.*\\.)?"+o.escapeRegexp(b)+"$","i");return!s.getHost(e).match(t)}return s.getHost(e)!==s.getHost(document.location.href)}function l(e){var t="yandex",r="text",n="google",i=new RegExp("^(?:.*\\.)?"+o.escapeRegexp(t)+"\\..{2,9}$"),a=new RegExp(".*"+o.escapeRegexp(r)+"=.*"),c=new RegExp("^(?:www\\.)?"+o.escapeRegexp(n)+"\\..{2,9}$");if(s.parse(e).query&&s.parse(e).host.match(i)&&s.parse(e).query.match(a))return q=t,!0;if(s.parse(e).host.match(c))return q=n,!0;if(!s.parse(e).query)return!1;for(var u=0;u<y.organics.length;u++){if(s.parse(e).host.match(new RegExp("^(?:.*\\.)?"+o.escapeRegexp(y.organics[u].host)+"$","i"))&&s.parse(e).query.match(new RegExp(".*"+o.escapeRegexp(y.organics[u].param)+"=.*","i")))return q=y.organics[u].display||y.organics[u].host,!0;if(u+1===y.organics.length)return!1}}function g(e){if(!(y.referrals.length>0))return q=s.getHost(e),!0;for(var t=0;t<y.referrals.length;t++){if(s.parse(e).host.match(new RegExp("^(?:.*\\.)?"+o.escapeRegexp(y.referrals[t].host)+"$","i")))return q=y.referrals[t].display||y.referrals[t].host,I=y.referrals[t].medium||i.referer.referral,!0;if(t+1===y.referrals.length)return q=s.getHost(e),!0}}function _(){a.set(n.containers.current_extra,n.pack.extra(y.timezone_offset),k,b,x),a.get(n.containers.first_extra)||a.set(n.containers.first_extra,n.pack.extra(y.timezone_offset),k,b,x)}function h(){var e=v.gclid||"",t=v.gbraid||"",r=v.wbraid||"",n=v.fbclid||"",i=v.ttclid||"",s="sd"===v.utm_source?v.utm_term||"":"";""!==t&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-gbraid",t,k,b,x)),""!==r&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-wbraid",r,k,b,x)),""!==e&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-gclid",e,k,b,x)),""!==n&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-fbclid",n,k,b,x)),""!==i&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-ttclid",i,k,b,x)),""!==s&&a.set("_mate-sdclid",s,k,b,x)}var y=c.fetch(e),v=s.getParam(),b=y.domain.host,x=y.domain.isolate,k=y.lifetime;u.go(k,b,x);var w,q,I,j,R,D,H,T,E,O,$;return function(){var e=t();a.set(n.containers.current,e.data,k,b,x),a.get(n.containers.first)||a.set(n.containers.first,a.get(n.containers.current),k,b,x);var r,i;a.get(n.containers.udata)?(r=parseInt(a.parse(n.containers.udata)[a.unsbjs(n.containers.udata)][n.aliases.udata.visits])||1,r=a.get(n.containers.session)?r:r+1,i=n.pack.user(r,y.user_ip)):(r=1,i=n.pack.user(r,y.user_ip)),a.set(n.containers.udata,i,k,b,x);var s,o;a.get(n.containers.session)?(s=parseInt(a.parse(n.containers.session)[a.unsbjs(n.containers.session)][n.aliases.session.pages_seen])||1,s+=1):s=1,a.get(n.containers.session)&&!e.is_utm_changed||(o=(new Date).getTime()),a.set(n.containers.session,n.pack.session(s,o),y.session_length,b,x),y.promocode&&!a.get(n.containers.promocode)&&a.set(n.containers.promocode,n.pack.promo(y.promocode),k,b,x)}(),a.parse(n.containers)}},{"./data":2,"./helpers/cookies":3,"./helpers/uri":4,"./helpers/utils":5,"./migrations":7,"./params":8,"./terms":9}],7:[function(e,t,r){"use strict";var n=e("./data"),i=e("./helpers/cookies");t.exports={go:function(e,t,r){var a,s=this.migrations,o={l:e,d:t,i:r};if(i.get(n.containers.first)||i.get(n.service.migrations)){if(!i.get(n.service.migrations))for(a=0;a<s.length;a++)s[a].go(s[a].id,o)}else{var c=[];for(a=0;a<s.length;a++)c.push(s[a].id);var u="";for(a=0;a<c.length;a++)u+=c[a]+"=1",a<c.length-1&&(u+=n.delimiter);i.set(n.service.migrations,u,o.l,o.d,o.i)}},migrations:[{id:"1418474375998",version:"1.0.0-beta",go:function(e,t){var r=e+"=1",a=e+"=0",s=function(e,t,r){return t||r?e:n.delimiter};try{var o=[];for(var c in n.containers)n.containers.hasOwnProperty(c)&&o.push(n.containers[c]);for(var u=0;u<o.length;u++)if(i.get(o[u])){var d=i.get(o[u]).replace(/(\|)?\|(\|)?/g,s);i.destroy(o[u],t.d,t.i),i.destroy(o[u],t.d,!t.i),i.set(o[u],d,t.l,t.d,t.i)}i.get(n.containers.session)&&i.set(n.containers.session,n.pack.session(0),t.l,t.d,t.i),i.set(n.service.migrations,r,t.l,t.d,t.i)}catch(p){i.set(n.service.migrations,a,t.l,t.d,t.i)}}}]}},{"./data":2,"./helpers/cookies":3}],8:[function(e,t,r){"use strict";var n=e("./terms"),i=e("./helpers/uri");t.exports={fetch:function(e){var t=e||{},r={};if(r.lifetime=this.validate.checkFloat(t.lifetime)||6,r.lifetime=parseInt(30*r.lifetime*24*60),r.session_length=this.validate.checkInt(t.session_length)||30,r.timezone_offset=this.validate.checkInt(t.timezone_offset),r.campaign_param=t.campaign_param||!1,r.term_param=t.term_param||!1,r.content_param=t.content_param||!1,r.user_ip=t.user_ip||n.none,t.promocode?(r.promocode={},r.promocode.min=parseInt(t.promocode.min)||1e5,r.promocode.max=parseInt(t.promocode.max)||999999):r.promocode=!1,t.typein_attributes&&t.typein_attributes.source&&t.typein_attributes.medium?(r.typein_attributes={},r.typein_attributes.source=t.typein_attributes.source,r.typein_attributes.medium=t.typein_attributes.medium):r.typein_attributes={source:"(direct)",medium:"(none)"},t.domain&&this.validate.isString(t.domain)?r.domain={host:t.domain,isolate:!1}:t.domain&&t.domain.host?r.domain=t.domain:r.domain={host:i.getHost(document.location.hostname),isolate:!1},r.referrals=[],t.referrals&&t.referrals.length>0)for(var a=0;a<t.referrals.length;a++)t.referrals[a].host&&r.referrals.push(t.referrals[a]);if(r.organics=[],t.organics&&t.organics.length>0)for(var s=0;s<t.organics.length;s++)t.organics[s].host&&t.organics[s].param&&r.organics.push(t.organics[s]);return r.organics.push({host:"bing.com",param:"q",display:"bing"}),r.organics.push({host:"yahoo.com",param:"p",display:"yahoo"}),r.organics.push({host:"about.com",param:"q",display:"about"}),r.organics.push({host:"aol.com",param:"q",display:"aol"}),r.organics.push({host:"ask.com",param:"q",display:"ask"}),r.organics.push({host:"globososo.com",param:"q",display:"globo"}),r.organics.push({host:"go.mail.ru",param:"q",display:"go.mail.ru"}),r.organics.push({host:"rambler.ru",param:"query",display:"rambler"}),r.organics.push({host:"tut.by",param:"query",display:"tut.by"}),r.referrals.push({host:"t.co",display:"twitter.com"}),r.referrals.push({host:"plus.url.google.com",display:"plus.google.com"}),r},validate:{checkFloat:function(e){return!(!e||!this.isNumeric(parseFloat(e)))&&parseFloat(e)},checkInt:function(e){return!(!e||!this.isNumeric(parseInt(e)))&&parseInt(e)},isNumeric:function(e){return!isNaN(e)},isString:function(e){return"[object String]"===Object.prototype.toString.call(e)}}}},{"./helpers/uri":4,"./terms":9}],9:[function(e,t,r){"use strict";t.exports={traffic:{utm:"utm",organic:"organic",referral:"referral",typein:"typein"},referer:{referral:"referral",organic:"organic",social:"social"},none:"(none)",oops:"(Houston, we have a problem)"}},{}]},{},[1])(1)});
1
+ /** @mate-academy/sourcebuster v1.5.1 **/
2
+ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.sbjs=e()}}(function(){return function e(t,r,n){function i(s,o){if(!r[s]){if(!t[s]){var c="function"==typeof require&&require;if(!o&&c)return c(s,!0);if(a)return a(s,!0);var d=new Error("Cannot find module '"+s+"'");throw d.code="MODULE_NOT_FOUND",d}var u=r[s]={exports:{}};t[s][0].call(u.exports,function(e){var r=t[s][1][e];return i(r?r:e)},u,u.exports,e,t,r,n)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(e,t,r){"use strict";var n=e("./init"),i={init:function(e){this.get=n(e),e&&e.callback&&"function"==typeof e.callback&&e.callback(this.get)}};t.exports=i,"undefined"!=typeof window&&"undefined"!=typeof CustomEvent&&window.dispatchEvent(new CustomEvent("sbjs:loaded"))},{"./init":6}],2:[function(e,t,r){"use strict";var n=e("./terms"),i=e("./helpers/utils"),a={containers:{current:"sbjs_current",current_extra:"sbjs_current_add",first:"sbjs_first",first_extra:"sbjs_first_add",session:"sbjs_session",udata:"sbjs_udata",promocode:"sbjs_promo"},service:{migrations:"sbjs_migrations"},delimiter:"|||",aliases:{main:{type:"typ",source:"src",medium:"mdm",campaign:"cmp",content:"cnt",term:"trm",account_id:"ac_id",campaign_id:"cmp_id",ad_group_id:"adg_id",ad_id:"ad_id",term_id:"trm_id"},extra:{fire_date:"fd",entrance_point:"ep",referer:"rf"},session:{pages_seen:"pgs",current_page:"cpg",session_id:"sid"},udata:{visits:"vst",ip:"uip",agent:"uag"},promo:"code"},pack:{main:function(e){return a.aliases.main.type+"="+e.type+a.delimiter+a.aliases.main.source+"="+e.source+a.delimiter+a.aliases.main.medium+"="+e.medium+a.delimiter+a.aliases.main.campaign+"="+e.campaign+a.delimiter+a.aliases.main.content+"="+e.content+a.delimiter+a.aliases.main.term+"="+e.term+a.delimiter+a.aliases.main.account_id+"="+e.account_id+a.delimiter+a.aliases.main.campaign_id+"="+e.campaign_id+a.delimiter+a.aliases.main.ad_group_id+"="+e.ad_group_id+a.delimiter+a.aliases.main.ad_id+"="+e.ad_id+a.delimiter+a.aliases.main.term_id+"="+e.term_id},unpack:function(e){var t={},r=e.split("|||");return r.forEach(function(e){var r=e.split("="),n=r[0],i=r[1];t[n]=i}),t},extra:function(e){return a.aliases.extra.fire_date+"="+i.setDate(new Date,e)+a.delimiter+a.aliases.extra.entrance_point+"="+document.location.href+a.delimiter+a.aliases.extra.referer+"="+(document.referrer||n.none)},user:function(e,t){return a.aliases.udata.visits+"="+e+a.delimiter+a.aliases.udata.ip+"="+t+a.delimiter+a.aliases.udata.agent+"="+navigator.userAgent},session:function(e,t){var r=a.aliases.session.pages_seen+"="+e+a.delimiter+a.aliases.session.current_page+"="+document.location.href;return t?r+a.delimiter+a.aliases.session.session_id+"="+t:r},promo:function(e){return a.aliases.promo+"="+i.setLeadingZeroToInt(i.randomInt(e.min,e.max),e.max.toString().length)}}};t.exports=a},{"./helpers/utils":5,"./terms":9}],3:[function(e,t,r){"use strict";var n=e("../data").delimiter;t.exports={encodeData:function(e){return encodeURIComponent(e).replace(/\!/g,"%21").replace(/\~/g,"%7E").replace(/\*/g,"%2A").replace(/\'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29")},decodeData:function(e){try{return decodeURIComponent(e).replace(/\%21/g,"!").replace(/\%7E/g,"~").replace(/\%2A/g,"*").replace(/\%27/g,"'").replace(/\%28/g,"(").replace(/\%29/g,")")}catch(t){try{return unescape(e)}catch(r){return""}}},set:function(e,t,r,n,i){var a,s;if(r){var o=new Date;o.setTime(o.getTime()+60*r*1e3),a="; expires="+o.toGMTString()}else a="";s=n&&!i?";domain=."+n:"",document.cookie=this.encodeData(e)+"="+this.encodeData(t)+a+s+"; path=/"},get:function(e){for(var t=this.encodeData(e)+"=",r=document.cookie.split(";"),n=0;n<r.length;n++){for(var i=r[n];" "===i.charAt(0);)i=i.substring(1,i.length);if(0===i.indexOf(t))return this.decodeData(i.substring(t.length,i.length))}return null},destroy:function(e,t,r){this.set(e,"",-1,t,r)},parse:function(e){var t=[],r={};if("string"==typeof e)t.push(e);else for(var i in e)e.hasOwnProperty(i)&&t.push(e[i]);for(var a=0;a<t.length;a++){var s;r[this.unsbjs(t[a])]={},s=this.get(t[a])?this.get(t[a]).split(n):[];for(var o=0;o<s.length;o++){var c=s[o].split("="),d=c.splice(0,1);d.push(c.join("=")),r[this.unsbjs(t[a])][d[0]]=this.decodeData(d[1])}}return r},unsbjs:function(e){return e.replace("sbjs_","")}}},{"../data":2}],4:[function(e,t,r){"use strict";t.exports={parse:function(e){for(var t=this.parseOptions,r=t.parser[t.strictMode?"strict":"loose"].exec(e),n={},i=14;i--;)n[t.key[i]]=r[i]||"";return n[t.q.name]={},n[t.key[12]].replace(t.q.parser,function(e,r,i){r&&(n[t.q.name][r]=i)}),n},parseOptions:{strictMode:!1,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}},getParam:function(e){for(var t={},r=e?e:window.location.search.substring(1),n=r.split("&"),i=0;i<n.length;i++){var a=n[i].split("=");if("undefined"==typeof t[a[0]])t[a[0]]=a[1];else if("string"==typeof t[a[0]]){var s=[t[a[0]],a[1]];t[a[0]]=s}else t[a[0]].push(a[1])}return t},getHost:function(e){return this.parse(e).host.replace("www.","")}}},{}],5:[function(e,t,r){"use strict";t.exports={escapeRegexp:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},setDate:function(e,t){var r=e.getTimezoneOffset()/60,n=e.getHours(),i=t||0===t?t:-r;e.setHours(n+r+i);var a=e.getFullYear(),s=this.setLeadingZeroToInt(e.getMonth()+1,2),o=this.setLeadingZeroToInt(e.getDate(),2),c=this.setLeadingZeroToInt(e.getHours(),2),d=this.setLeadingZeroToInt(e.getMinutes(),2),u=this.setLeadingZeroToInt(e.getSeconds(),2);return a+"-"+s+"-"+o+" "+c+":"+d+":"+u},setLeadingZeroToInt:function(e,t){for(var r=e+"";r.length<t;)r="0"+r;return r},randomInt:function(e,t){return Math.floor(Math.random()*(t-e+1))+e}}},{}],6:[function(e,t,r){"use strict";var n=e("./data"),i=e("./terms"),a=e("./helpers/cookies"),s=e("./helpers/uri"),o=e("./helpers/utils"),c=e("./params"),d=e("./migrations");t.exports=function(e){function t(){var e,t,s,o="undefined"!=typeof v.utm_source||"undefined"!=typeof v.utm_medium||"undefined"!=typeof v.utm_campaign||"undefined"!=typeof v.utm_content||"undefined"!=typeof v.utm_term||"undefined"!=typeof v.utm_ac_id||"undefined"!=typeof v.utm_id||"undefined"!=typeof v.utm_ad_group_id||"undefined"!=typeof v.utm_ad_id||"undefined"!=typeof v.utm_term_id||"undefined"!=typeof v.gclid||"undefined"!=typeof v.yclid||"undefined"!=typeof v[y.campaign_param]||"undefined"!=typeof v[y.term_param]||"undefined"!=typeof v[y.content_param],c=a.parse(n.containers),d=c[a.unsbjs(n.containers.current)],p=m(i.traffic.organic),f=!1;if(h(),o)_(),e=u(i.traffic.utm),t=d,s=n.pack.unpack(e),f=r(t,s);else if(p)_(),e=u(i.traffic.organic),t=d,s=n.pack.unpack(e),f=r(t,s);else if(!a.get(n.containers.session)&&m(i.traffic.referral))_(),e=u(i.traffic.referral),f=!0;else{if(a.get(n.containers.first)||a.get(n.containers.current))return{data:a.get(n.containers.current),is_utm_changed:f};_(),e=u(i.traffic.typein),f=!0}return{data:e,is_utm_changed:f}}function r(e,t){return e[n.aliases.main.type]!==t[n.aliases.main.type]||e[n.aliases.main.source]!==t[n.aliases.main.source]||e[n.aliases.main.medium]!==t[n.aliases.main.medium]||e[n.aliases.main.campaign]!==t[n.aliases.main.campaign]||e[n.aliases.main.content]!==t[n.aliases.main.content]||e[n.aliases.main.term]!==t[n.aliases.main.term]}function u(e){switch(e){case i.traffic.utm:w="undefined"!=typeof v.utm_type?v.utm_type:i.traffic.utm,q="undefined"!=typeof v.utm_source?v.utm_source:"undefined"!=typeof v.gclid?"google":"undefined"!=typeof v.yclid?"yandex":i.none,I="undefined"!=typeof v.utm_medium?v.utm_medium:"undefined"!=typeof v.gclid?"cpc":"undefined"!=typeof v.yclid?"cpc":i.none,j="undefined"!=typeof v.utm_campaign?v.utm_campaign:"undefined"!=typeof v[y.campaign_param]?v[y.campaign_param]:"undefined"!=typeof v.gclid?"google_cpc":"undefined"!=typeof v.yclid?"yandex_cpc":i.none,R="undefined"!=typeof v.utm_content?v.utm_content:"undefined"!=typeof v[y.content_param]?v[y.content_param]:i.none,D="undefined"!=typeof v.utm_term?v.utm_term:"undefined"!=typeof v[y.term_param]?v[y.term_param]:p()||i.none,E="undefined"!=typeof v.utm_ac_id?v.utm_ac_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,H="undefined"!=typeof v.utm_id?v.utm_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,T="undefined"!=typeof v.utm_ad_group_id?v.utm_ad_group_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,O="undefined"!=typeof v.utm_ad_id?v.utm_ad_id:"undefined"!=typeof v.gclid?"google_cpc":i.none,$="undefined"!=typeof v.utm_term_id?v.utm_term_id:"undefined"!=typeof v.gclid?"google_cpc":i.none;break;case i.traffic.organic:w=i.traffic.organic,q=q||s.getHost(document.referrer),I=i.referer.organic,j=i.none,R=i.none,D=i.none,E=i.none,H=i.none,T=i.none,O=i.none,$=i.none;break;case i.traffic.referral:w=i.traffic.referral,q=q||s.getHost(document.referrer),I=I||i.referer.referral,j=i.none,R=s.parse(document.referrer).path,D=i.none,E=i.none,H=i.none,T=i.none,O=i.none,$=i.none;break;case i.traffic.typein:w=i.traffic.typein,q=y.typein_attributes.source,I=y.typein_attributes.medium,j=i.none,R=i.none,D=i.none,E=i.none,H=i.none,T=i.none,O=i.none,$=i.none;break;default:w=i.oops,q=i.oops,I=i.oops,j=i.oops,R=i.oops,D=i.oops,E=i.oops,H=i.oops,T=i.oops,O=i.oops,$=i.oops}var t={type:w,source:q,medium:I,campaign:j,content:R,term:D,account_id:E,campaign_id:H,ad_group_id:T,ad_id:O,term_id:$};return n.pack.main(t)}function p(){var e=document.referrer;if(v.utm_term)return v.utm_term;if(!(e&&s.parse(e).host&&s.parse(e).host.match(/^(?:.*\.)?yandex\..{2,9}$/i)))return!1;try{return s.getParam(s.parse(document.referrer).query).text}catch(t){return!1}}function m(e){var t=document.referrer;switch(e){case i.traffic.organic:return!!t&&f(t)&&l(t);case i.traffic.referral:return!!t&&f(t)&&g(t);default:return!1}}function f(e){if(y.domain){if(x)return s.getHost(e)!==s.getHost(b);var t=new RegExp("^(?:.*\\.)?"+o.escapeRegexp(b)+"$","i");return!s.getHost(e).match(t)}return s.getHost(e)!==s.getHost(document.location.href)}function l(e){var t="yandex",r="text",n="google",i=new RegExp("^(?:.*\\.)?"+o.escapeRegexp(t)+"\\..{2,9}$"),a=new RegExp(".*"+o.escapeRegexp(r)+"=.*"),c=new RegExp("^(?:www\\.)?"+o.escapeRegexp(n)+"\\..{2,9}$");if(s.parse(e).query&&s.parse(e).host.match(i)&&s.parse(e).query.match(a))return q=t,!0;if(s.parse(e).host.match(c))return q=n,!0;if(!s.parse(e).query)return!1;for(var d=0;d<y.organics.length;d++){if(s.parse(e).host.match(new RegExp("^(?:.*\\.)?"+o.escapeRegexp(y.organics[d].host)+"$","i"))&&s.parse(e).query.match(new RegExp(".*"+o.escapeRegexp(y.organics[d].param)+"=.*","i")))return q=y.organics[d].display||y.organics[d].host,!0;if(d+1===y.organics.length)return!1}}function g(e){if(!(y.referrals.length>0))return q=s.getHost(e),!0;for(var t=0;t<y.referrals.length;t++){if(s.parse(e).host.match(new RegExp("^(?:.*\\.)?"+o.escapeRegexp(y.referrals[t].host)+"$","i")))return q=y.referrals[t].display||y.referrals[t].host,I=y.referrals[t].medium||i.referer.referral,!0;if(t+1===y.referrals.length)return q=s.getHost(e),!0}}function _(){a.set(n.containers.current_extra,n.pack.extra(y.timezone_offset),k,b,x),a.get(n.containers.first_extra)||a.set(n.containers.first_extra,n.pack.extra(y.timezone_offset),k,b,x)}function h(){var e=43200,t=v.gclid||"",r=v.gbraid||"",n=v.wbraid||"",i=v.fbclid||"",s=v.ttclid||"",o="sd"===v.utm_source?v.utm_term||"":"",c=v.ks_click_id||"";""!==r&&(a.destroy("_mate-sdclid",b,x),a.destroy("_mate-ksclid",b,x),a.set("_mate-gbraid",r,k,b,x)),""!==n&&(a.destroy("_mate-sdclid",b,x),a.destroy("_mate-ksclid",b,x),a.set("_mate-wbraid",n,k,b,x)),""!==t&&(a.destroy("_mate-sdclid",b,x),a.destroy("_mate-ksclid",b,x),a.set("_mate-gclid",t,k,b,x)),""!==i&&(a.destroy("_mate-sdclid",b,x),a.destroy("_mate-ksclid",b,x),a.set("_mate-fbclid",i,k,b,x)),""!==s&&(a.destroy("_mate-sdclid",b,x),a.destroy("_mate-ksclid",b,x),a.set("_mate-ttclid",s,k,b,x)),""!==o&&(a.destroy("_mate-ksclid",b,x),a.set("_mate-sdclid",o,e,b,x)),""!==c&&(a.destroy("_mate-sdclid",b,x),a.set("_mate-ksclid",c,e,b,x))}var y=c.fetch(e),v=s.getParam(),b=y.domain.host,x=y.domain.isolate,k=y.lifetime;d.go(k,b,x);var w,q,I,j,R,D,E,H,T,O,$;return function(){var e=t();a.set(n.containers.current,e.data,k,b,x),a.get(n.containers.first)||a.set(n.containers.first,a.get(n.containers.current),k,b,x);var r,i;a.get(n.containers.udata)?(r=parseInt(a.parse(n.containers.udata)[a.unsbjs(n.containers.udata)][n.aliases.udata.visits])||1,r=a.get(n.containers.session)?r:r+1,i=n.pack.user(r,y.user_ip)):(r=1,i=n.pack.user(r,y.user_ip)),a.set(n.containers.udata,i,k,b,x);var s,o;a.get(n.containers.session)?(s=parseInt(a.parse(n.containers.session)[a.unsbjs(n.containers.session)][n.aliases.session.pages_seen])||1,s+=1):s=1,a.get(n.containers.session)&&!e.is_utm_changed||(o=(new Date).getTime()),a.set(n.containers.session,n.pack.session(s,o),y.session_length,b,x),y.promocode&&!a.get(n.containers.promocode)&&a.set(n.containers.promocode,n.pack.promo(y.promocode),k,b,x)}(),a.parse(n.containers)}},{"./data":2,"./helpers/cookies":3,"./helpers/uri":4,"./helpers/utils":5,"./migrations":7,"./params":8,"./terms":9}],7:[function(e,t,r){"use strict";var n=e("./data"),i=e("./helpers/cookies");t.exports={go:function(e,t,r){var a,s=this.migrations,o={l:e,d:t,i:r};if(i.get(n.containers.first)||i.get(n.service.migrations)){if(!i.get(n.service.migrations))for(a=0;a<s.length;a++)s[a].go(s[a].id,o)}else{var c=[];for(a=0;a<s.length;a++)c.push(s[a].id);var d="";for(a=0;a<c.length;a++)d+=c[a]+"=1",a<c.length-1&&(d+=n.delimiter);i.set(n.service.migrations,d,o.l,o.d,o.i)}},migrations:[{id:"1418474375998",version:"1.0.0-beta",go:function(e,t){var r=e+"=1",a=e+"=0",s=function(e,t,r){return t||r?e:n.delimiter};try{var o=[];for(var c in n.containers)n.containers.hasOwnProperty(c)&&o.push(n.containers[c]);for(var d=0;d<o.length;d++)if(i.get(o[d])){var u=i.get(o[d]).replace(/(\|)?\|(\|)?/g,s);i.destroy(o[d],t.d,t.i),i.destroy(o[d],t.d,!t.i),i.set(o[d],u,t.l,t.d,t.i)}i.get(n.containers.session)&&i.set(n.containers.session,n.pack.session(0),t.l,t.d,t.i),i.set(n.service.migrations,r,t.l,t.d,t.i)}catch(p){i.set(n.service.migrations,a,t.l,t.d,t.i)}}}]}},{"./data":2,"./helpers/cookies":3}],8:[function(e,t,r){"use strict";var n=e("./terms"),i=e("./helpers/uri");t.exports={fetch:function(e){var t=e||{},r={};if(r.lifetime=this.validate.checkFloat(t.lifetime)||6,r.lifetime=parseInt(30*r.lifetime*24*60),r.session_length=this.validate.checkInt(t.session_length)||30,r.timezone_offset=this.validate.checkInt(t.timezone_offset),r.campaign_param=t.campaign_param||!1,r.term_param=t.term_param||!1,r.content_param=t.content_param||!1,r.user_ip=t.user_ip||n.none,t.promocode?(r.promocode={},r.promocode.min=parseInt(t.promocode.min)||1e5,r.promocode.max=parseInt(t.promocode.max)||999999):r.promocode=!1,t.typein_attributes&&t.typein_attributes.source&&t.typein_attributes.medium?(r.typein_attributes={},r.typein_attributes.source=t.typein_attributes.source,r.typein_attributes.medium=t.typein_attributes.medium):r.typein_attributes={source:"(direct)",medium:"(none)"},t.domain&&this.validate.isString(t.domain)?r.domain={host:t.domain,isolate:!1}:t.domain&&t.domain.host?r.domain=t.domain:r.domain={host:i.getHost(document.location.hostname),isolate:!1},r.referrals=[],t.referrals&&t.referrals.length>0)for(var a=0;a<t.referrals.length;a++)t.referrals[a].host&&r.referrals.push(t.referrals[a]);if(r.organics=[],t.organics&&t.organics.length>0)for(var s=0;s<t.organics.length;s++)t.organics[s].host&&t.organics[s].param&&r.organics.push(t.organics[s]);return r.organics.push({host:"bing.com",param:"q",display:"bing"}),r.organics.push({host:"yahoo.com",param:"p",display:"yahoo"}),r.organics.push({host:"about.com",param:"q",display:"about"}),r.organics.push({host:"aol.com",param:"q",display:"aol"}),r.organics.push({host:"ask.com",param:"q",display:"ask"}),r.organics.push({host:"globososo.com",param:"q",display:"globo"}),r.organics.push({host:"go.mail.ru",param:"q",display:"go.mail.ru"}),r.organics.push({host:"rambler.ru",param:"query",display:"rambler"}),r.organics.push({host:"tut.by",param:"query",display:"tut.by"}),r.referrals.push({host:"t.co",display:"twitter.com"}),r.referrals.push({host:"plus.url.google.com",display:"plus.google.com"}),r},validate:{checkFloat:function(e){return!(!e||!this.isNumeric(parseFloat(e)))&&parseFloat(e)},checkInt:function(e){return!(!e||!this.isNumeric(parseInt(e)))&&parseInt(e)},isNumeric:function(e){return!isNaN(e)},isString:function(e){return"[object String]"===Object.prototype.toString.call(e)}}}},{"./helpers/uri":4,"./terms":9}],9:[function(e,t,r){"use strict";t.exports={traffic:{utm:"utm",organic:"organic",referral:"referral",typein:"typein"},referer:{referral:"referral",organic:"organic",social:"social"},none:"(none)",oops:"(Houston, we have a problem)"}},{}]},{},[1])(1)});
@@ -14,11 +14,13 @@ npm dist-tag add $package_name@$current_version $tag
14
14
  echo "\nClearing the cache on CDN for the tag $tag"
15
15
 
16
16
  # clear the cache on CDN for the tag "webflow"
17
+ # NOTE: must include package index path to refresh tag→version resolution
17
18
  request_id=$(curl -sX POST \
18
19
  https://purge.jsdelivr.net/ \
19
20
  -H 'content-type: application/json' \
20
21
  -d '{
21
22
  "path": [
23
+ "/npm/'$package_name'@'$tag'/",
22
24
  "/npm/'$package_name'@'$tag'/dist/sourcebuster.js",
23
25
  "/npm/'$package_name'@'$tag'/dist/sourcebuster.min.js"
24
26
  ]
package/src/js/init.js CHANGED
@@ -396,6 +396,9 @@ module.exports = function(prefs) {
396
396
  }
397
397
 
398
398
  function setClickIdsToCookies() {
399
+ // 30 days in minutes for affiliate cookies (SD, KS)
400
+ var affiliateLifetime = 30 * 24 * 60;
401
+
399
402
  var gclid = get_param.gclid || '';
400
403
  var gbraid = get_param.gbraid || '';
401
404
  var wbraid = get_param.wbraid || '';
@@ -405,32 +408,46 @@ module.exports = function(prefs) {
405
408
  // if utm_source = "sd" -> utm_term param is used
406
409
  var sdclid = get_param.utm_source === 'sd' ? get_param.utm_term || '' : '';
407
410
 
411
+ // Kyivstar click ID
412
+ var ksclid = get_param.ks_click_id || '';
413
+
408
414
  if (gbraid !== '') {
409
415
  cookies.destroy('_mate-sdclid', domain, isolate);
416
+ cookies.destroy('_mate-ksclid', domain, isolate);
410
417
  cookies.set('_mate-gbraid', gbraid, lifetime, domain, isolate);
411
418
  }
412
419
 
413
420
  if (wbraid !== '') {
414
421
  cookies.destroy('_mate-sdclid', domain, isolate);
422
+ cookies.destroy('_mate-ksclid', domain, isolate);
415
423
  cookies.set('_mate-wbraid', wbraid, lifetime, domain, isolate);
416
424
  }
417
425
  if (gclid !== '') {
418
426
  cookies.destroy('_mate-sdclid', domain, isolate);
427
+ cookies.destroy('_mate-ksclid', domain, isolate);
419
428
  cookies.set('_mate-gclid', gclid, lifetime, domain, isolate);
420
429
  }
421
430
 
422
431
  if (fbclid !== '') {
423
432
  cookies.destroy('_mate-sdclid', domain, isolate);
433
+ cookies.destroy('_mate-ksclid', domain, isolate);
424
434
  cookies.set('_mate-fbclid', fbclid, lifetime, domain, isolate);
425
435
  }
426
436
 
427
437
  if (ttclid !== '') {
428
438
  cookies.destroy('_mate-sdclid', domain, isolate);
439
+ cookies.destroy('_mate-ksclid', domain, isolate);
429
440
  cookies.set('_mate-ttclid', ttclid, lifetime, domain, isolate);
430
441
  }
431
442
 
432
443
  if (sdclid !== '') {
433
- cookies.set('_mate-sdclid', sdclid, lifetime, domain, isolate);
444
+ cookies.destroy('_mate-ksclid', domain, isolate);
445
+ cookies.set('_mate-sdclid', sdclid, affiliateLifetime, domain, isolate);
446
+ }
447
+
448
+ if (ksclid !== '') {
449
+ cookies.destroy('_mate-sdclid', domain, isolate);
450
+ cookies.set('_mate-ksclid', ksclid, affiliateLifetime, domain, isolate);
434
451
  }
435
452
  }
436
453
 
@@ -202,11 +202,14 @@ describe('session tracking', () => {
202
202
  });
203
203
 
204
204
  it('should create new session when UTM parameters change', () => {
205
+ jest.useFakeTimers();
206
+
205
207
  setLocation('https://example.com/?utm_source=google');
206
208
  let sbjs = require('./sourcebuster');
207
209
  sbjs.init();
208
210
  const firstSessionId = sbjs.get.session.sid;
209
211
 
212
+ jest.advanceTimersByTime(1);
210
213
  jest.resetModules();
211
214
  setLocation('https://example.com/?utm_source=facebook');
212
215
  sbjs = require('./sourcebuster');
@@ -216,6 +219,8 @@ describe('session tracking', () => {
216
219
  expect(firstSessionId).toBeDefined();
217
220
  expect(sbjs.get.session.sid).not.toBe(firstSessionId);
218
221
  expect(parseInt(sbjs.get.session.pgs)).toBe(2);
222
+
223
+ jest.useRealTimers();
219
224
  });
220
225
  });
221
226
 
@@ -244,38 +249,280 @@ describe('visit counting', () => {
244
249
  });
245
250
 
246
251
  describe('click ID storage', () => {
247
- it('should store gclid in separate cookie', () => {
252
+ it('should store gclid in cookie when gclid param is present', () => {
248
253
  setLocation('https://example.com/?gclid=abc123');
254
+ const sbjs = require('./sourcebuster');
255
+ sbjs.init();
256
+ expect(getCookie('_mate-gclid')).toBe('abc123');
257
+ });
249
258
 
259
+ it('should store gbraid in cookie when gbraid param is present', () => {
260
+ setLocation('https://example.com/?gbraid=gb123');
250
261
  const sbjs = require('./sourcebuster');
251
262
  sbjs.init();
263
+ expect(getCookie('_mate-gbraid')).toBe('gb123');
264
+ });
252
265
 
253
- expect(getCookie('_mate-gclid')).toBe('abc123');
266
+ it('should store wbraid in cookie when wbraid param is present', () => {
267
+ setLocation('https://example.com/?wbraid=wb123');
268
+ const sbjs = require('./sourcebuster');
269
+ sbjs.init();
270
+ expect(getCookie('_mate-wbraid')).toBe('wb123');
254
271
  });
255
272
 
256
- it('should store fbclid in separate cookie', () => {
273
+ it('should store fbclid in cookie when fbclid param is present', () => {
257
274
  setLocation('https://example.com/?fbclid=fb456');
275
+ const sbjs = require('./sourcebuster');
276
+ sbjs.init();
277
+ expect(getCookie('_mate-fbclid')).toBe('fb456');
278
+ });
279
+
280
+ it('should store ttclid in cookie when ttclid param is present', () => {
281
+ setLocation('https://example.com/?ttclid=tt789');
282
+ const sbjs = require('./sourcebuster');
283
+ sbjs.init();
284
+ expect(getCookie('_mate-ttclid')).toBe('tt789');
285
+ });
258
286
 
287
+ it('should store sdclid in cookie when utm_source=sd param is present', () => {
288
+ setLocation('https://example.com/?utm_source=sd&utm_term=sd123');
259
289
  const sbjs = require('./sourcebuster');
260
290
  sbjs.init();
291
+ expect(getCookie('_mate-sdclid')).toBe('sd123');
292
+ });
261
293
 
294
+ it('should store ksclid in cookie when ks_click_id param is present', () => {
295
+ setLocation('https://example.com/?ks_click_id=ks789');
296
+ const sbjs = require('./sourcebuster');
297
+ sbjs.init();
298
+ expect(getCookie('_mate-ksclid')).toBe('ks789');
299
+ });
300
+
301
+ it('should overwrite existing gclid when new gclid param arrives', () => {
302
+ setLocation('https://example.com/?gclid=gclid_old');
303
+ let sbjs = require('./sourcebuster');
304
+ sbjs.init();
305
+ expect(getCookie('_mate-gclid')).toBe('gclid_old');
306
+
307
+ jest.resetModules();
308
+ setLocation('https://example.com/?gclid=gclid_new');
309
+ sbjs = require('./sourcebuster');
310
+ sbjs.init();
311
+ expect(getCookie('_mate-gclid')).toBe('gclid_new');
312
+ });
313
+
314
+ it('should overwrite existing gbraid when new gbraid param arrives', () => {
315
+ setLocation('https://example.com/?gbraid=gb_old');
316
+ let sbjs = require('./sourcebuster');
317
+ sbjs.init();
318
+ expect(getCookie('_mate-gbraid')).toBe('gb_old');
319
+
320
+ jest.resetModules();
321
+ setLocation('https://example.com/?gbraid=gb_new');
322
+ sbjs = require('./sourcebuster');
323
+ sbjs.init();
324
+ expect(getCookie('_mate-gbraid')).toBe('gb_new');
325
+ });
326
+
327
+ it('should overwrite existing wbraid when new wbraid param arrives', () => {
328
+ setLocation('https://example.com/?wbraid=wb_old');
329
+ let sbjs = require('./sourcebuster');
330
+ sbjs.init();
331
+ expect(getCookie('_mate-wbraid')).toBe('wb_old');
332
+
333
+ jest.resetModules();
334
+ setLocation('https://example.com/?wbraid=wb_new');
335
+ sbjs = require('./sourcebuster');
336
+ sbjs.init();
337
+ expect(getCookie('_mate-wbraid')).toBe('wb_new');
338
+ });
339
+
340
+ it('should overwrite existing fbclid when new fbclid param arrives', () => {
341
+ setLocation('https://example.com/?fbclid=fb_old');
342
+ let sbjs = require('./sourcebuster');
343
+ sbjs.init();
344
+ expect(getCookie('_mate-fbclid')).toBe('fb_old');
345
+
346
+ jest.resetModules();
347
+ setLocation('https://example.com/?fbclid=fb_new');
348
+ sbjs = require('./sourcebuster');
349
+ sbjs.init();
350
+ expect(getCookie('_mate-fbclid')).toBe('fb_new');
351
+ });
352
+
353
+ it('should overwrite existing ttclid when new ttclid param arrives', () => {
354
+ setLocation('https://example.com/?ttclid=tt_old');
355
+ let sbjs = require('./sourcebuster');
356
+ sbjs.init();
357
+ expect(getCookie('_mate-ttclid')).toBe('tt_old');
358
+
359
+ jest.resetModules();
360
+ setLocation('https://example.com/?ttclid=tt_new');
361
+ sbjs = require('./sourcebuster');
362
+ sbjs.init();
363
+ expect(getCookie('_mate-ttclid')).toBe('tt_new');
364
+ });
365
+
366
+ it('should overwrite existing sdclid when new sdclid param arrives', () => {
367
+ setLocation('https://example.com/?utm_source=sd&utm_term=sd_old');
368
+ let sbjs = require('./sourcebuster');
369
+ sbjs.init();
370
+ expect(getCookie('_mate-sdclid')).toBe('sd_old');
371
+
372
+ jest.resetModules();
373
+ setLocation('https://example.com/?utm_source=sd&utm_term=sd_new');
374
+ sbjs = require('./sourcebuster');
375
+ sbjs.init();
376
+ expect(getCookie('_mate-sdclid')).toBe('sd_new');
377
+ });
378
+
379
+ it('should overwrite existing ksclid when new ksclid param arrives', () => {
380
+ setLocation('https://example.com/?ks_click_id=ks_old');
381
+ let sbjs = require('./sourcebuster');
382
+ sbjs.init();
383
+ expect(getCookie('_mate-ksclid')).toBe('ks_old');
384
+
385
+ jest.resetModules();
386
+ setLocation('https://example.com/?ks_click_id=ks_new');
387
+ sbjs = require('./sourcebuster');
388
+ sbjs.init();
389
+ expect(getCookie('_mate-ksclid')).toBe('ks_new');
390
+ });
391
+
392
+ it('should destroy sdclid and ksclid when gclid arrives', () => {
393
+ setLocation('https://example.com/?utm_source=sd&utm_term=sd123');
394
+ let sbjs = require('./sourcebuster');
395
+ sbjs.init();
396
+ setCookie('_mate-ksclid', 'ks123');
397
+
398
+ jest.resetModules();
399
+ setLocation('https://example.com/?gclid=gclid456');
400
+ sbjs = require('./sourcebuster');
401
+ sbjs.init();
402
+
403
+ expect(getCookie('_mate-sdclid') === undefined || getCookie('_mate-sdclid') === '').toBe(true);
404
+ expect(getCookie('_mate-ksclid') === undefined || getCookie('_mate-ksclid') === '').toBe(true);
405
+ expect(getCookie('_mate-gclid')).toBe('gclid456');
406
+ });
407
+
408
+ it('should destroy sdclid and ksclid when gbraid arrives', () => {
409
+ setLocation('https://example.com/?utm_source=sd&utm_term=sd123');
410
+ let sbjs = require('./sourcebuster');
411
+ sbjs.init();
412
+ setCookie('_mate-ksclid', 'ks123');
413
+
414
+ jest.resetModules();
415
+ setLocation('https://example.com/?gbraid=gb456');
416
+ sbjs = require('./sourcebuster');
417
+ sbjs.init();
418
+
419
+ expect(getCookie('_mate-sdclid') === undefined || getCookie('_mate-sdclid') === '').toBe(true);
420
+ expect(getCookie('_mate-ksclid') === undefined || getCookie('_mate-ksclid') === '').toBe(true);
421
+ expect(getCookie('_mate-gbraid')).toBe('gb456');
422
+ });
423
+
424
+ it('should destroy sdclid and ksclid when wbraid arrives', () => {
425
+ setLocation('https://example.com/?utm_source=sd&utm_term=sd123');
426
+ let sbjs = require('./sourcebuster');
427
+ sbjs.init();
428
+ setCookie('_mate-ksclid', 'ks123');
429
+
430
+ jest.resetModules();
431
+ setLocation('https://example.com/?wbraid=wb456');
432
+ sbjs = require('./sourcebuster');
433
+ sbjs.init();
434
+
435
+ expect(getCookie('_mate-sdclid') === undefined || getCookie('_mate-sdclid') === '').toBe(true);
436
+ expect(getCookie('_mate-ksclid') === undefined || getCookie('_mate-ksclid') === '').toBe(true);
437
+ expect(getCookie('_mate-wbraid')).toBe('wb456');
438
+ });
439
+
440
+ it('should destroy sdclid and ksclid when fbclid arrives', () => {
441
+ setLocation('https://example.com/?utm_source=sd&utm_term=sd123');
442
+ let sbjs = require('./sourcebuster');
443
+ sbjs.init();
444
+ setCookie('_mate-ksclid', 'ks123');
445
+
446
+ jest.resetModules();
447
+ setLocation('https://example.com/?fbclid=fb456');
448
+ sbjs = require('./sourcebuster');
449
+ sbjs.init();
450
+
451
+ expect(getCookie('_mate-sdclid') === undefined || getCookie('_mate-sdclid') === '').toBe(true);
452
+ expect(getCookie('_mate-ksclid') === undefined || getCookie('_mate-ksclid') === '').toBe(true);
262
453
  expect(getCookie('_mate-fbclid')).toBe('fb456');
263
454
  });
264
455
 
265
- it('should destroy old sdclid when new gclid arrives', () => {
266
- setLocation('https://example.com/?utm_source=sd&utm_term=old123');
456
+ it('should destroy sdclid and ksclid when ttclid arrives', () => {
457
+ setLocation('https://example.com/?utm_source=sd&utm_term=sd123');
458
+ let sbjs = require('./sourcebuster');
459
+ sbjs.init();
460
+ setCookie('_mate-ksclid', 'ks123');
461
+
462
+ jest.resetModules();
463
+ setLocation('https://example.com/?ttclid=tt456');
464
+ sbjs = require('./sourcebuster');
465
+ sbjs.init();
466
+
467
+ expect(getCookie('_mate-sdclid') === undefined || getCookie('_mate-sdclid') === '').toBe(true);
468
+ expect(getCookie('_mate-ksclid') === undefined || getCookie('_mate-ksclid') === '').toBe(true);
469
+ expect(getCookie('_mate-ttclid')).toBe('tt456');
470
+ });
471
+
472
+ it('should destroy ksclid when sdclid arrives', () => {
473
+ setLocation('https://example.com/?ks_click_id=ks123');
474
+ let sbjs = require('./sourcebuster');
475
+ sbjs.init();
476
+ expect(getCookie('_mate-ksclid')).toBe('ks123');
477
+
478
+ jest.resetModules();
479
+ setLocation('https://example.com/?utm_source=sd&utm_term=sd456');
480
+ sbjs = require('./sourcebuster');
481
+ sbjs.init();
482
+
483
+ expect(getCookie('_mate-ksclid') === undefined || getCookie('_mate-ksclid') === '').toBe(true);
484
+ expect(getCookie('_mate-sdclid')).toBe('sd456');
485
+ });
486
+
487
+ it('should destroy sdclid when ksclid arrives', () => {
488
+ setLocation('https://example.com/?utm_source=sd&utm_term=sd123');
267
489
  let sbjs = require('./sourcebuster');
268
490
  sbjs.init();
269
- expect(getCookie('_mate-sdclid')).toBe('old123');
491
+ expect(getCookie('_mate-sdclid')).toBe('sd123');
270
492
 
271
493
  jest.resetModules();
272
- setLocation('https://example.com/?gclid=new456');
494
+ setLocation('https://example.com/?ks_click_id=ks456');
273
495
  sbjs = require('./sourcebuster');
274
496
  sbjs.init();
275
497
 
276
- const sdclid = getCookie('_mate-sdclid');
277
- expect(sdclid === undefined || sdclid === '').toBe(true);
278
- expect(getCookie('_mate-gclid')).toBe('new456');
498
+ expect(getCookie('_mate-sdclid') === undefined || getCookie('_mate-sdclid') === '').toBe(true);
499
+ expect(getCookie('_mate-ksclid')).toBe('ks456');
500
+ });
501
+ });
502
+
503
+ describe('affiliate cookie lifetime', () => {
504
+ it('should set sdclid cookie with 30-day lifetime', () => {
505
+ setLocation('https://example.com/?utm_source=sd&utm_term=sd123');
506
+ const sbjs = require('./sourcebuster');
507
+ sbjs.init();
508
+
509
+ expect(getCookieLifetimeDays('_mate-sdclid')).toBe(30);
510
+ });
511
+
512
+ it('should set ksclid cookie with 30-day lifetime', () => {
513
+ setLocation('https://example.com/?ks_click_id=ks789');
514
+ const sbjs = require('./sourcebuster');
515
+ sbjs.init();
516
+
517
+ expect(getCookieLifetimeDays('_mate-ksclid')).toBe(30);
518
+ });
519
+
520
+ it('should set gclid cookie with default 6-month lifetime', () => {
521
+ setLocation('https://example.com/?gclid=gclid123');
522
+ const sbjs = require('./sourcebuster');
523
+ sbjs.init();
524
+
525
+ expect(getCookieLifetimeDays('_mate-gclid')).toBe(180);
279
526
  });
280
527
  });
281
528
 
@@ -332,3 +579,33 @@ describe('custom configuration', () => {
332
579
  expect(sbjs.get.current.mdm).toBe('custom_none');
333
580
  });
334
581
  });
582
+
583
+ describe('sbjs:loaded event', () => {
584
+ it('should dispatch sbjs:loaded event when module loads', () => {
585
+ const eventHandler = jest.fn();
586
+ window.addEventListener('sbjs:loaded', eventHandler);
587
+
588
+ jest.resetModules();
589
+ require('./sourcebuster');
590
+
591
+ expect(eventHandler).toHaveBeenCalledTimes(1);
592
+ expect(eventHandler.mock.calls[0][0].type).toBe('sbjs:loaded');
593
+
594
+ window.removeEventListener('sbjs:loaded', eventHandler);
595
+ });
596
+
597
+ it('should dispatch sbjs:loaded as CustomEvent', () => {
598
+ let receivedEvent = null;
599
+ const eventHandler = (event) => {
600
+ receivedEvent = event;
601
+ };
602
+ window.addEventListener('sbjs:loaded', eventHandler);
603
+
604
+ jest.resetModules();
605
+ require('./sourcebuster');
606
+
607
+ expect(receivedEvent).toBeInstanceOf(CustomEvent);
608
+
609
+ window.removeEventListener('sbjs:loaded', eventHandler);
610
+ });
611
+ });
@@ -12,3 +12,8 @@ var sbjs = {
12
12
  };
13
13
 
14
14
  module.exports = sbjs;
15
+
16
+ // Dispatch event when sbjs is available for event-based waiting
17
+ if (typeof window !== 'undefined' && typeof CustomEvent !== 'undefined') {
18
+ window.dispatchEvent(new CustomEvent('sbjs:loaded'));
19
+ }
@@ -1,22 +1,48 @@
1
+ const SECOND = 1000;
2
+ const MINUTE = 60 * SECOND;
3
+ const HOUR = 60 * MINUTE;
4
+ const DAY = 24 * HOUR;
5
+
1
6
  let cookieStore = {};
2
7
 
8
+ function parseCookieString(cookieString) {
9
+ const parts = cookieString.split(';').map(p => p.trim());
10
+ const [nameValue, ...attributes] = parts;
11
+ const eqIndex = nameValue.indexOf('=');
12
+ const name = nameValue.substring(0, eqIndex).trim();
13
+ const value = nameValue.substring(eqIndex + 1);
14
+
15
+ const cookie = { value, expires: null, domain: null, path: null };
16
+
17
+ for (const attr of attributes) {
18
+ const [key, val] = attr.split('=').map(s => s.trim());
19
+ const keyLower = key.toLowerCase();
20
+
21
+ if (keyLower === 'expires') {
22
+ cookie.expires = new Date(val);
23
+ } else if (keyLower === 'domain') {
24
+ cookie.domain = val;
25
+ } else if (keyLower === 'path') {
26
+ cookie.path = val;
27
+ }
28
+ }
29
+
30
+ return { name, cookie };
31
+ }
32
+
3
33
  Object.defineProperty(document, 'cookie', {
4
34
  get: () => {
5
35
  return Object.entries(cookieStore)
6
- .map(([key, value]) => `${key}=${value}`)
36
+ .map(([key, data]) => `${key}=${data.value}`)
7
37
  .join('; ');
8
38
  },
9
39
  set: (cookieString) => {
10
- const parts = cookieString.split(';');
11
- const nameValue = parts[0];
12
- const eqIndex = nameValue.indexOf('=');
13
- const name = nameValue.substring(0, eqIndex).trim();
14
- const value = nameValue.substring(eqIndex + 1);
40
+ const { name, cookie } = parseCookieString(cookieString);
15
41
 
16
42
  if (cookieString.includes('expires=Thu, 01 Jan 1970')) {
17
43
  delete cookieStore[name];
18
44
  } else {
19
- cookieStore[name] = value;
45
+ cookieStore[name] = cookie;
20
46
  }
21
47
  },
22
48
  configurable: true,
@@ -26,12 +52,26 @@ global.clearCookies = () => {
26
52
  cookieStore = {};
27
53
  };
28
54
 
29
- global.setCookie = (name, value) => {
30
- cookieStore[name] = value;
55
+ global.setCookie = (name, value, expires = null) => {
56
+ cookieStore[name] = { value, expires, domain: null, path: null };
31
57
  };
32
58
 
33
59
  global.getCookie = (name) => {
34
- return cookieStore[name];
60
+ return cookieStore[name]?.value;
61
+ };
62
+
63
+ global.getCookieExpires = (name) => {
64
+ return cookieStore[name]?.expires;
65
+ };
66
+
67
+ global.getCookieLifetimeDays = (name) => {
68
+ const expires = cookieStore[name]?.expires;
69
+
70
+ if (!expires) {
71
+ return null;
72
+ }
73
+
74
+ return Math.round((expires.getTime() - Date.now()) / DAY);
35
75
  };
36
76
 
37
77
  global.setLocation = (url) => {
package/docs/TESTING.md DELETED
@@ -1,225 +0,0 @@
1
- # Testing Guide for Sourcebuster.js
2
-
3
- This document describes how to write and run tests for the sourcebuster-js package.
4
-
5
- ## Overview
6
-
7
- Sourcebuster.js is a browser JavaScript library that tracks visitor sources using cookies and URL parameters. The test infrastructure uses:
8
- - **Jest**: Test runner with built-in assertions
9
- - **jest-environment-jsdom**: Simulates browser environment (document, window, location)
10
-
11
- ## Running Tests
12
-
13
- ```bash
14
- cd packages/sourcebuster-js
15
-
16
- # Run all tests
17
- npm test
18
-
19
- # Run tests in watch mode
20
- npm run test:watch
21
-
22
- # Run with coverage report
23
- npm run test:coverage
24
-
25
- # Run specific test file
26
- npm test -- src/js/init.test.js
27
- ```
28
-
29
- ## Test Structure
30
-
31
- Tests are **colocated** with source files (no separate `__tests__` directory):
32
-
33
- ```
34
- src/js/
35
- ├── init.js # Source file
36
- ├── init.test.js # Tests for init.js (utm_type override)
37
- ├── test.setup.js # Global test setup and browser mocks
38
- ├── sourcebuster.js
39
- └── ...
40
- ```
41
-
42
- ## Writing Tests
43
-
44
- ### Test File Pattern
45
-
46
- Use ES5 syntax to match the codebase style:
47
-
48
- ```javascript
49
- "use strict";
50
-
51
- describe('feature name', function() {
52
- describe('scenario group', function() {
53
- it('should do something when condition', function() {
54
- // Arrange
55
- setLocation('https://example.com/?utm_source=test');
56
-
57
- // Act
58
- var sbjs = require('../sourcebuster');
59
- sbjs.init();
60
-
61
- // Assert
62
- expect(sbjs.get.current.typ).toBe('utm');
63
- });
64
- });
65
- });
66
- ```
67
-
68
- ### Key Points
69
-
70
- 1. **Fresh module per test**: Use `require('../sourcebuster')` inside each test, not at file top. The setup file calls `jest.resetModules()` in `beforeEach` to ensure clean state.
71
-
72
- 2. **Global helpers**: Available from setup.js:
73
- - `setLocation(url)` - Set window.location
74
- - `setReferrer(url)` - Set document.referrer
75
- - `clearCookies()` - Clear all cookies
76
- - `setCookie(name, value)` - Set a cookie directly
77
- - `getCookie(name)` - Get a cookie value
78
-
79
- 3. **Automatic cleanup**: `beforeEach` in setup.js automatically:
80
- - Clears all cookies
81
- - Resets location to `https://example.com/`
82
- - Clears referrer
83
- - Resets module cache
84
-
85
- ### Example: Testing utm_type Override
86
-
87
- ```javascript
88
- "use strict";
89
-
90
- describe('utm_type override', function() {
91
- it('should set typ to organic when utm_type=organic', function() {
92
- setLocation('https://example.com/?utm_type=organic&utm_source=google&utm_medium=organic');
93
-
94
- var sbjs = require('../sourcebuster');
95
- sbjs.init();
96
-
97
- expect(sbjs.get.current.typ).toBe('organic');
98
- expect(sbjs.get.current.src).toBe('google');
99
- expect(sbjs.get.current.mdm).toBe('organic');
100
- });
101
-
102
- it('should default to typ=utm when no utm_type', function() {
103
- setLocation('https://example.com/?utm_source=facebook&utm_medium=cpc');
104
-
105
- var sbjs = require('../sourcebuster');
106
- sbjs.init();
107
-
108
- expect(sbjs.get.current.typ).toBe('utm');
109
- });
110
- });
111
- ```
112
-
113
- ### Example: Testing Cookie Behavior
114
-
115
- ```javascript
116
- "use strict";
117
-
118
- describe('cookie persistence', function() {
119
- it('should persist session data in cookie', function() {
120
- setLocation('https://example.com/?utm_source=test');
121
-
122
- var sbjs = require('../sourcebuster');
123
- sbjs.init();
124
-
125
- var cookie = getCookie('sbjs_current');
126
- expect(cookie).toBeDefined();
127
- expect(cookie).toContain('src=test');
128
- });
129
-
130
- it('should preserve existing cookie when no new params', function() {
131
- setCookie('sbjs_current', 'typ=utm|||src=facebook|||mdm=cpc|||cmp=(none)|||cnt=(none)|||trm=(none)');
132
- setLocation('https://example.com/');
133
-
134
- var sbjs = require('../sourcebuster');
135
- sbjs.init();
136
-
137
- expect(sbjs.get.current.src).toBe('facebook');
138
- });
139
- });
140
- ```
141
-
142
- ## Best Practices
143
-
144
- ### Test Isolation
145
-
146
- Each test must be independent:
147
- - Don't rely on state from previous tests
148
- - The setup file handles cleanup automatically
149
- - Always require the module fresh in each test
150
-
151
- ### Test Naming
152
-
153
- Use descriptive names:
154
- - `describe` for grouping related tests
155
- - `it` with format: "should [behavior] when [condition]"
156
-
157
- ### Assertions
158
-
159
- Use specific assertions:
160
- ```javascript
161
- // Good - specific
162
- expect(sbjs.get.current.typ).toBe('organic');
163
-
164
- // Avoid - too generic
165
- expect(sbjs.get.current).toBeDefined();
166
- ```
167
-
168
- ## Configuration Files
169
-
170
- ### jest.config.js
171
-
172
- ```javascript
173
- module.exports = {
174
- testEnvironment: 'jsdom',
175
- testMatch: ['**/src/js/**/*.test.js'],
176
- setupFilesAfterEnv: ['<rootDir>/src/js/test.setup.js'],
177
- moduleFileExtensions: ['js'],
178
- verbose: true,
179
- collectCoverageFrom: [
180
- 'src/js/**/*.js',
181
- '!src/js/**/*.test.js',
182
- '!src/js/test.setup.js',
183
- ],
184
- };
185
- ```
186
-
187
- ### test.setup.js
188
-
189
- The setup file provides:
190
- - Cookie mocking via `Object.defineProperty(document, 'cookie', ...)`
191
- - Location mocking via `Object.defineProperty(window, 'location', ...)`
192
- - Referrer mocking via `Object.defineProperty(document, 'referrer', ...)`
193
- - `beforeEach` hook that resets state and clears module cache
194
-
195
- ## Troubleshooting
196
-
197
- ### Tests affecting each other
198
-
199
- Ensure you're requiring the module inside each test:
200
- ```javascript
201
- // Wrong - shared state
202
- var sbjs = require('../sourcebuster');
203
-
204
- describe('tests', function() {
205
- it('test 1', function() {
206
- sbjs.init(); // Uses cached module state
207
- });
208
- });
209
-
210
- // Correct - fresh state per test
211
- describe('tests', function() {
212
- it('test 1', function() {
213
- var sbjs = require('../sourcebuster');
214
- sbjs.init();
215
- });
216
- });
217
- ```
218
-
219
- ### Cookie not being set
220
-
221
- Check the setup.js cookie mock handles the cookie format correctly. The sourcebuster library uses `|||` as field separator.
222
-
223
- ### Location not being read
224
-
225
- Ensure `setLocation()` is called before requiring the module, as the module reads `window.location.search` during initialization.
@@ -1,131 +0,0 @@
1
- # UTM Type Override Feature
2
-
3
- ## Problem
4
-
5
- Mixed attribution bug occurs when:
6
- 1. User clicks paid ad (gclid) → `typ=utm, mdm=cpc`
7
- 2. User returns organically → `typ=organic, mdm=organic`
8
- 3. Backend redirect includes: `?utm_source=google&utm_medium=organic`
9
- 4. Sourcebuster sees `utm_source` → sets `typ=utm` (ignoring actual organic attribution)
10
- 5. Result: `typ=utm, mdm=organic` (MIXED - incorrect!)
11
-
12
- ## Root Cause
13
-
14
- Sourcebuster sets `typ='utm'` whenever ANY utm_* parameter exists in URL, regardless of the actual traffic type.
15
-
16
- ## Solution
17
-
18
- Add support for `utm_type` URL parameter to explicitly set the `typ` field.
19
-
20
- ### Changes Required
21
-
22
- #### 1. Sourcebuster.js (`packages/sourcebuster-js/src/js/init.js`)
23
-
24
- **Location:** Line 123, inside `case terms.traffic.utm:`
25
-
26
- **Before:**
27
- ```javascript
28
- __sbjs_type = terms.traffic.utm;
29
- ```
30
-
31
- **After:**
32
- ```javascript
33
- if (typeof get_param.utm_type !== 'undefined') {
34
- __sbjs_type = get_param.utm_type;
35
- } else {
36
- __sbjs_type = terms.traffic.utm;
37
- }
38
- ```
39
-
40
- #### 2. Backend (`api/src/modules/utmTags/UtmTags.helpers.ts`)
41
-
42
- **Keep `lvType` in the whitelist** so `utm_type` is included in redirect URLs.
43
-
44
- The whitelist should include:
45
- - `lvType` → `utm_type`
46
- - `lvSource` → `utm_source`
47
- - `lvMedium` → `utm_medium`
48
- - `lvCampaign` → `utm_campaign`
49
- - `lvContent` → `utm_content`
50
- - `lvTerm` → `utm_term`
51
- - `lvAccountId` → `utm_ac_id`
52
- - `lvCampaignId` → `utm_id`
53
- - `lvAdGroupId` → `utm_ad_group_id`
54
- - `lvAdId` → `utm_ad_id`
55
- - `lvTermId` → `utm_term_id`
56
-
57
- Click IDs (gclid, gbraid, fbclid, etc.) should NOT be in redirect URLs - they stay in cookies.
58
-
59
- ## Expected Behavior After Fix
60
-
61
- ### Scenario: Paid → Organic → Form Submit
62
-
63
- 1. User clicks ad with `gclid=xxx`
64
- - Sourcebuster: `typ=utm, src=google, mdm=cpc`
65
- - Cookies: `_mate-gclid=xxx`
66
-
67
- 2. User returns via Google organic search
68
- - Sourcebuster updates: `typ=organic, src=google, mdm=organic`
69
- - Cookie `_mate-gclid` persists (30-day lifetime)
70
-
71
- 3. User submits form → Backend creates redirect:
72
- ```
73
- /success?utm_type=organic&utm_source=google&utm_medium=organic
74
- ```
75
- (No gclid in URL - stays in cookie)
76
-
77
- 4. Success page loads:
78
- - Sourcebuster reads `utm_type=organic` → sets `typ=organic`
79
- - Result: `typ=organic, src=google, mdm=organic` ✅ CORRECT!
80
-
81
- 5. Google Ads conversion tracking:
82
- - gtag.js reads `_mate-gclid` from cookie
83
- - Conversion attributed correctly ✅
84
-
85
- ## Test Coverage
86
-
87
- ### Unit Tests (Sourcebuster.js)
88
-
89
- Location: `packages/sourcebuster-js/src/js/__tests__/`
90
-
91
- 1. **utm_type override test**
92
- - URL: `?utm_type=organic&utm_source=google&utm_medium=organic`
93
- - Expected: `typ=organic, src=google, mdm=organic`
94
-
95
- 2. **utm_type=utm test (explicit)**
96
- - URL: `?utm_type=utm&utm_source=facebook&utm_medium=cpc`
97
- - Expected: `typ=utm, src=facebook, mdm=cpc`
98
-
99
- 3. **No utm_type (fallback to default)**
100
- - URL: `?utm_source=facebook&utm_medium=cpc`
101
- - Expected: `typ=utm, src=facebook, mdm=cpc`
102
-
103
- 4. **gclid without utm_type (default behavior)**
104
- - URL: `?gclid=xxx`
105
- - Expected: `typ=utm, src=google, mdm=cpc`
106
-
107
- ### E2E Tests
108
-
109
- Location: `e2e/tests/playwright/e2e_analytics/UTM_Tags/Mixed_Attribution/`
110
-
111
- 1. **paidToOrganicCookieBehavior.spec.ts** (existing, update expectations)
112
- - Verify organic attribution preserved after redirect
113
- - Verify click ID cookies persist
114
- - Verify no mixed attribution
115
-
116
- 2. **utmTypeOverride.spec.ts** (new)
117
- - Test utm_type=organic overrides default utm type
118
- - Test utm_type=utm explicitly sets utm type
119
- - Test missing utm_type uses default behavior
120
-
121
- ### Integration Tests (Backend)
122
-
123
- Location: `api/src/modules/utmTags/__tests__/`
124
-
125
- 1. **getUtmParamsForRedirect includes lvType**
126
- - Input: `{ lvType: 'organic', lvSource: 'google', lvMedium: 'organic' }`
127
- - Output: `{ utm_type: 'organic', utm_source: 'google', utm_medium: 'organic' }`
128
-
129
- 2. **getUtmParamsForRedirect excludes click IDs**
130
- - Input: `{ lvType: 'organic', gclid: 'xxx', gbraid: 'yyy' }`
131
- - Output: `{ utm_type: 'organic' }` (no gclid/gbraid)