@mate-academy/sourcebuster 1.1.4 → 1.2.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.
@@ -364,26 +364,48 @@ module.exports = function(prefs) {
364
364
 
365
365
  function mainData() {
366
366
  var sbjs_data;
367
- if (
368
- typeof get_param.utm_source !== 'undefined' ||
369
- typeof get_param.utm_medium !== 'undefined' ||
370
- typeof get_param.utm_campaign !== 'undefined' ||
371
- typeof get_param.utm_content !== 'undefined' ||
372
- typeof get_param.utm_term !== 'undefined' ||
373
- typeof get_param.utm_ac_id !== 'undefined' ||
374
- typeof get_param.utm_id !== 'undefined' ||
375
- typeof get_param.utm_ad_group_id !== 'undefined' ||
376
- typeof get_param.utm_ad_id !== 'undefined' ||
377
- typeof get_param.utm_term_id !== 'undefined' ||
378
- typeof get_param.gclid !== 'undefined' ||
379
- typeof get_param.yclid !== 'undefined' ||
380
- typeof get_param[p.campaign_param] !== 'undefined' ||
381
- typeof get_param[p.term_param] !== 'undefined' ||
382
- typeof get_param[p.content_param] !== 'undefined'
383
- ) {
367
+
368
+ var isGetParamsContainsUtm = (
369
+ typeof get_param.utm_source !== 'undefined' ||
370
+ typeof get_param.utm_medium !== 'undefined' ||
371
+ typeof get_param.utm_campaign !== 'undefined' ||
372
+ typeof get_param.utm_content !== 'undefined' ||
373
+ typeof get_param.utm_term !== 'undefined' ||
374
+ typeof get_param.utm_ac_id !== 'undefined' ||
375
+ typeof get_param.utm_id !== 'undefined' ||
376
+ typeof get_param.utm_ad_group_id !== 'undefined' ||
377
+ typeof get_param.utm_ad_id !== 'undefined' ||
378
+ typeof get_param.utm_term_id !== 'undefined' ||
379
+ typeof get_param.gclid !== 'undefined' ||
380
+ typeof get_param.yclid !== 'undefined' ||
381
+ typeof get_param[p.campaign_param] !== 'undefined' ||
382
+ typeof get_param[p.term_param] !== 'undefined' ||
383
+ typeof get_param[p.content_param] !== 'undefined'
384
+ );
385
+
386
+ var parsedContainer = cookies.parse(data.containers);
387
+ var parsedCurrent = parsedContainer[cookies.unsbjs(data.containers.current)];
388
+ var parsedCurrentExtra = parsedContainer[cookies.unsbjs(data.containers.current_extra)];
389
+
390
+ var fireTime = new Date(parsedCurrentExtra[data.aliases.extra.fire_date]).getTime();
391
+ var DAY = 24 * 60 * 60 * 1000;
392
+ var now = new Date().getTime();
393
+ var fireTimeDiff = now - fireTime;
394
+
395
+ var isOrganic = checkReferer(terms.traffic.organic);
396
+ var isCurrentContainerContainsUtm = parsedCurrent[data.aliases.main.type] === terms.traffic.utm;
397
+
398
+ var shouldOverrideWithOrganic = (
399
+ isOrganic && (
400
+ !isCurrentContainerContainsUtm ||
401
+ fireTimeDiff > 45 * DAY
402
+ )
403
+ );
404
+
405
+ if (isGetParamsContainsUtm) {
384
406
  setFirstAndCurrentExtraData();
385
407
  sbjs_data = getData(terms.traffic.utm);
386
- } else if (checkReferer(terms.traffic.organic)) {
408
+ } else if (shouldOverrideWithOrganic) {
387
409
  setFirstAndCurrentExtraData();
388
410
  sbjs_data = getData(terms.traffic.organic);
389
411
  } else if (!cookies.get(data.containers.session) && checkReferer(terms.traffic.referral)) {
@@ -1,2 +1,2 @@
1
- /** @mate-academy/sourcebuster v1.1.0 **/
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(o,s){if(!r[o]){if(!t[o]){var c="function"==typeof require&&require;if(!s&&c)return c(o,!0);if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var p=r[o]={exports:{}};t[o][0].call(p.exports,function(e){var r=t[o][1][e];return i(r?r:e)},p,p.exports,e,t,r,n)}return r[o].exports}for(var a="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);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"},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},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){return a.aliases.session.pages_seen+"="+e+a.delimiter+a.aliases.session.current_page+"="+document.location.href},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,o;if(r){var s=new Date;s.setTime(s.getTime()+60*r*1e3),a="; expires="+s.toGMTString()}else a="";o=n&&!i?";domain=."+n:"",document.cookie=this.encodeData(e)+"="+this.encodeData(t)+a+o+"; 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 o;r[this.unsbjs(t[a])]={},o=this.get(t[a])?this.get(t[a]).split(n):[];for(var s=0;s<o.length;s++){var c=o[s].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 o=[t[a[0]],a[1]];t[a[0]]=o}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(),o=this.setLeadingZeroToInt(e.getMonth()+1,2),s=this.setLeadingZeroToInt(e.getDate(),2),c=this.setLeadingZeroToInt(e.getHours(),2),u=this.setLeadingZeroToInt(e.getMinutes(),2),p=this.setLeadingZeroToInt(e.getSeconds(),2);return a+"-"+o+"-"+s+" "+c+":"+u+":"+p},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"),o=e("./helpers/uri"),s=e("./helpers/utils"),c=e("./params"),u=e("./migrations");t.exports=function(e){function t(){var e;if("undefined"!=typeof _.utm_source||"undefined"!=typeof _.utm_medium||"undefined"!=typeof _.utm_campaign||"undefined"!=typeof _.utm_content||"undefined"!=typeof _.utm_term||"undefined"!=typeof _.utm_ac_id||"undefined"!=typeof _.utm_id||"undefined"!=typeof _.utm_ad_group_id||"undefined"!=typeof _.utm_ad_id||"undefined"!=typeof _.utm_term_id||"undefined"!=typeof _.gclid||"undefined"!=typeof _.yclid||"undefined"!=typeof _[h.campaign_param]||"undefined"!=typeof _[h.term_param]||"undefined"!=typeof _[h.content_param])g(),e=r(i.traffic.utm);else if(d(i.traffic.organic))g(),e=r(i.traffic.organic);else if(!a.get(n.containers.session)&&d(i.traffic.referral))g(),e=r(i.traffic.referral);else{if(a.get(n.containers.first)||a.get(n.containers.current))return a.get(n.containers.current);g(),e=r(i.traffic.typein)}return e}function r(e){switch(e){case i.traffic.utm:b=i.traffic.utm,k="undefined"!=typeof _.utm_source?_.utm_source:"undefined"!=typeof _.gclid?"google":"undefined"!=typeof _.yclid?"yandex":i.none,w="undefined"!=typeof _.utm_medium?_.utm_medium:"undefined"!=typeof _.gclid?"cpc":"undefined"!=typeof _.yclid?"cpc":i.none,q="undefined"!=typeof _.utm_campaign?_.utm_campaign:"undefined"!=typeof _[h.campaign_param]?_[h.campaign_param]:"undefined"!=typeof _.gclid?"google_cpc":"undefined"!=typeof _.yclid?"yandex_cpc":i.none,I="undefined"!=typeof _.utm_content?_.utm_content:"undefined"!=typeof _[h.content_param]?_[h.content_param]:i.none,j="undefined"!=typeof _.utm_term?_.utm_term:"undefined"!=typeof _[h.term_param]?_[h.term_param]:p()||i.none,R="undefined"!=typeof _.utm_ac_id?_.utm_ac_id:"undefined"!=typeof _.gclid?"google_cpc":i.none,H="undefined"!=typeof _.utm_id?_.utm_id:"undefined"!=typeof _.gclid?"google_cpc":i.none,D="undefined"!=typeof _.utm_ad_group_id?_.utm_ad_group_id:"undefined"!=typeof _.gclid?"google_cpc":i.none,T="undefined"!=typeof _.utm_ad_id?_.utm_ad_id:"undefined"!=typeof _.gclid?"google_cpc":i.none,E="undefined"!=typeof _.utm_term_id?_.utm_term_id:"undefined"!=typeof _.gclid?"google_cpc":i.none;break;case i.traffic.organic:b=i.traffic.organic,k=k||o.getHost(document.referrer),w=i.referer.organic,q=i.none,I=i.none,j=i.none,R=i.none,H=i.none,D=i.none,T=i.none,E=i.none;break;case i.traffic.referral:b=i.traffic.referral,k=k||o.getHost(document.referrer),w=w||i.referer.referral,q=i.none,I=o.parse(document.referrer).path,j=i.none,R=i.none,H=i.none,D=i.none,T=i.none,E=i.none;break;case i.traffic.typein:b=i.traffic.typein,k=h.typein_attributes.source,w=h.typein_attributes.medium,q=i.none,I=i.none,j=i.none,R=i.none,H=i.none,D=i.none,T=i.none,E=i.none;break;default:b=i.oops,k=i.oops,w=i.oops,q=i.oops,I=i.oops,j=i.oops,R=i.oops,H=i.oops,D=i.oops,T=i.oops,E=i.oops}var t={type:b,source:k,medium:w,campaign:q,content:I,term:j,account_id:R,campaign_id:H,ad_group_id:D,ad_id:T,term_id:E};return n.pack.main(t)}function p(){var e=document.referrer;if(_.utm_term)return _.utm_term;if(!(e&&o.parse(e).host&&o.parse(e).host.match(/^(?:.*\.)?yandex\..{2,9}$/i)))return!1;try{return o.getParam(o.parse(document.referrer).query).text}catch(t){return!1}}function d(e){var t=document.referrer;switch(e){case i.traffic.organic:return!!t&&f(t)&&m(t);case i.traffic.referral:return!!t&&f(t)&&l(t);default:return!1}}function f(e){if(h.domain){if(v)return o.getHost(e)!==o.getHost(y);var t=new RegExp("^(?:.*\\.)?"+s.escapeRegexp(y)+"$","i");return!o.getHost(e).match(t)}return o.getHost(e)!==o.getHost(document.location.href)}function m(e){var t="yandex",r="text",n="google",i=new RegExp("^(?:.*\\.)?"+s.escapeRegexp(t)+"\\..{2,9}$"),a=new RegExp(".*"+s.escapeRegexp(r)+"=.*"),c=new RegExp("^(?:www\\.)?"+s.escapeRegexp(n)+"\\..{2,9}$");if(o.parse(e).query&&o.parse(e).host.match(i)&&o.parse(e).query.match(a))return k=t,!0;if(o.parse(e).host.match(c))return k=n,!0;if(!o.parse(e).query)return!1;for(var u=0;u<h.organics.length;u++){if(o.parse(e).host.match(new RegExp("^(?:.*\\.)?"+s.escapeRegexp(h.organics[u].host)+"$","i"))&&o.parse(e).query.match(new RegExp(".*"+s.escapeRegexp(h.organics[u].param)+"=.*","i")))return k=h.organics[u].display||h.organics[u].host,!0;if(u+1===h.organics.length)return!1}}function l(e){if(!(h.referrals.length>0))return k=o.getHost(e),!0;for(var t=0;t<h.referrals.length;t++){if(o.parse(e).host.match(new RegExp("^(?:.*\\.)?"+s.escapeRegexp(h.referrals[t].host)+"$","i")))return k=h.referrals[t].display||h.referrals[t].host,w=h.referrals[t].medium||i.referer.referral,!0;if(t+1===h.referrals.length)return k=o.getHost(e),!0}}function g(){a.set(n.containers.current_extra,n.pack.extra(h.timezone_offset),x,y,v),a.get(n.containers.first_extra)||a.set(n.containers.first_extra,n.pack.extra(h.timezone_offset),x,y,v)}var h=c.fetch(e),_=o.getParam(),y=h.domain.host,v=h.domain.isolate,x=h.lifetime;u.go(x,y,v);var b,k,w,q,I,j,R,H,D,T,E;return function(){a.set(n.containers.current,t(),x,y,v),a.get(n.containers.first)||a.set(n.containers.first,a.get(n.containers.current),x,y,v);var e,r;a.get(n.containers.udata)?(e=parseInt(a.parse(n.containers.udata)[a.unsbjs(n.containers.udata)][n.aliases.udata.visits])||1,e=a.get(n.containers.session)?e:e+1,r=n.pack.user(e,h.user_ip)):(e=1,r=n.pack.user(e,h.user_ip)),a.set(n.containers.udata,r,x,y,v);var i;a.get(n.containers.session)?(i=parseInt(a.parse(n.containers.session)[a.unsbjs(n.containers.session)][n.aliases.session.pages_seen])||1,i+=1):i=1,a.set(n.containers.session,n.pack.session(i),h.session_length,y,v),h.promocode&&!a.get(n.containers.promocode)&&a.set(n.containers.promocode,n.pack.promo(h.promocode),x,y,v)}(),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,o=this.migrations,s={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<o.length;a++)o[a].go(o[a].id,s)}else{var c=[];for(a=0;a<o.length;a++)c.push(o[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,s.l,s.d,s.i)}},migrations:[{id:"1418474375998",version:"1.0.0-beta",go:function(e,t){var r=e+"=1",a=e+"=0",o=function(e,t,r){return t||r?e:n.delimiter};try{var s=[];for(var c in n.containers)n.containers.hasOwnProperty(c)&&s.push(n.containers[c]);for(var u=0;u<s.length;u++)if(i.get(s[u])){var p=i.get(s[u]).replace(/(\|)?\|(\|)?/g,o);i.destroy(s[u],t.d,t.i),i.destroy(s[u],t.d,!t.i),i.set(s[u],p,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(d){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 o=0;o<t.organics.length;o++)t.organics[o].host&&t.organics[o].param&&r.organics.push(t.organics[o]);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.2.0 **/
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(o,s){if(!r[o]){if(!t[o]){var c="function"==typeof require&&require;if(!s&&c)return c(o,!0);if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var p=r[o]={exports:{}};t[o][0].call(p.exports,function(e){var r=t[o][1][e];return i(r?r:e)},p,p.exports,e,t,r,n)}return r[o].exports}for(var a="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);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"},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},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){return a.aliases.session.pages_seen+"="+e+a.delimiter+a.aliases.session.current_page+"="+document.location.href},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,o;if(r){var s=new Date;s.setTime(s.getTime()+60*r*1e3),a="; expires="+s.toGMTString()}else a="";o=n&&!i?";domain=."+n:"",document.cookie=this.encodeData(e)+"="+this.encodeData(t)+a+o+"; 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 o;r[this.unsbjs(t[a])]={},o=this.get(t[a])?this.get(t[a]).split(n):[];for(var s=0;s<o.length;s++){var c=o[s].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 o=[t[a[0]],a[1]];t[a[0]]=o}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(),o=this.setLeadingZeroToInt(e.getMonth()+1,2),s=this.setLeadingZeroToInt(e.getDate(),2),c=this.setLeadingZeroToInt(e.getHours(),2),u=this.setLeadingZeroToInt(e.getMinutes(),2),p=this.setLeadingZeroToInt(e.getSeconds(),2);return a+"-"+o+"-"+s+" "+c+":"+u+":"+p},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"),o=e("./helpers/uri"),s=e("./helpers/utils"),c=e("./params"),u=e("./migrations");t.exports=function(e){function t(){var e,t="undefined"!=typeof _.utm_source||"undefined"!=typeof _.utm_medium||"undefined"!=typeof _.utm_campaign||"undefined"!=typeof _.utm_content||"undefined"!=typeof _.utm_term||"undefined"!=typeof _.utm_ac_id||"undefined"!=typeof _.utm_id||"undefined"!=typeof _.utm_ad_group_id||"undefined"!=typeof _.utm_ad_id||"undefined"!=typeof _.utm_term_id||"undefined"!=typeof _.gclid||"undefined"!=typeof _.yclid||"undefined"!=typeof _[h.campaign_param]||"undefined"!=typeof _[h.term_param]||"undefined"!=typeof _[h.content_param],o=a.parse(n.containers),s=o[a.unsbjs(n.containers.current)],c=o[a.unsbjs(n.containers.current_extra)],u=new Date(c[n.aliases.extra.fire_date]).getTime(),p=864e5,f=(new Date).getTime(),m=f-u,l=d(i.traffic.organic),y=s[n.aliases.main.type]===i.traffic.utm,v=l&&(!y||m>45*p);if(t)g(),e=r(i.traffic.utm);else if(v)g(),e=r(i.traffic.organic);else if(!a.get(n.containers.session)&&d(i.traffic.referral))g(),e=r(i.traffic.referral);else{if(a.get(n.containers.first)||a.get(n.containers.current))return a.get(n.containers.current);g(),e=r(i.traffic.typein)}return e}function r(e){switch(e){case i.traffic.utm:b=i.traffic.utm,k="undefined"!=typeof _.utm_source?_.utm_source:"undefined"!=typeof _.gclid?"google":"undefined"!=typeof _.yclid?"yandex":i.none,w="undefined"!=typeof _.utm_medium?_.utm_medium:"undefined"!=typeof _.gclid?"cpc":"undefined"!=typeof _.yclid?"cpc":i.none,q="undefined"!=typeof _.utm_campaign?_.utm_campaign:"undefined"!=typeof _[h.campaign_param]?_[h.campaign_param]:"undefined"!=typeof _.gclid?"google_cpc":"undefined"!=typeof _.yclid?"yandex_cpc":i.none,I="undefined"!=typeof _.utm_content?_.utm_content:"undefined"!=typeof _[h.content_param]?_[h.content_param]:i.none,j="undefined"!=typeof _.utm_term?_.utm_term:"undefined"!=typeof _[h.term_param]?_[h.term_param]:p()||i.none,R="undefined"!=typeof _.utm_ac_id?_.utm_ac_id:"undefined"!=typeof _.gclid?"google_cpc":i.none,D="undefined"!=typeof _.utm_id?_.utm_id:"undefined"!=typeof _.gclid?"google_cpc":i.none,H="undefined"!=typeof _.utm_ad_group_id?_.utm_ad_group_id:"undefined"!=typeof _.gclid?"google_cpc":i.none,T="undefined"!=typeof _.utm_ad_id?_.utm_ad_id:"undefined"!=typeof _.gclid?"google_cpc":i.none,E="undefined"!=typeof _.utm_term_id?_.utm_term_id:"undefined"!=typeof _.gclid?"google_cpc":i.none;break;case i.traffic.organic:b=i.traffic.organic,k=k||o.getHost(document.referrer),w=i.referer.organic,q=i.none,I=i.none,j=i.none,R=i.none,D=i.none,H=i.none,T=i.none,E=i.none;break;case i.traffic.referral:b=i.traffic.referral,k=k||o.getHost(document.referrer),w=w||i.referer.referral,q=i.none,I=o.parse(document.referrer).path,j=i.none,R=i.none,D=i.none,H=i.none,T=i.none,E=i.none;break;case i.traffic.typein:b=i.traffic.typein,k=h.typein_attributes.source,w=h.typein_attributes.medium,q=i.none,I=i.none,j=i.none,R=i.none,D=i.none,H=i.none,T=i.none,E=i.none;break;default:b=i.oops,k=i.oops,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}var t={type:b,source:k,medium:w,campaign:q,content:I,term:j,account_id:R,campaign_id:D,ad_group_id:H,ad_id:T,term_id:E};return n.pack.main(t)}function p(){var e=document.referrer;if(_.utm_term)return _.utm_term;if(!(e&&o.parse(e).host&&o.parse(e).host.match(/^(?:.*\.)?yandex\..{2,9}$/i)))return!1;try{return o.getParam(o.parse(document.referrer).query).text}catch(t){return!1}}function d(e){var t=document.referrer;switch(e){case i.traffic.organic:return!!t&&f(t)&&m(t);case i.traffic.referral:return!!t&&f(t)&&l(t);default:return!1}}function f(e){if(h.domain){if(v)return o.getHost(e)!==o.getHost(y);var t=new RegExp("^(?:.*\\.)?"+s.escapeRegexp(y)+"$","i");return!o.getHost(e).match(t)}return o.getHost(e)!==o.getHost(document.location.href)}function m(e){var t="yandex",r="text",n="google",i=new RegExp("^(?:.*\\.)?"+s.escapeRegexp(t)+"\\..{2,9}$"),a=new RegExp(".*"+s.escapeRegexp(r)+"=.*"),c=new RegExp("^(?:www\\.)?"+s.escapeRegexp(n)+"\\..{2,9}$");if(o.parse(e).query&&o.parse(e).host.match(i)&&o.parse(e).query.match(a))return k=t,!0;if(o.parse(e).host.match(c))return k=n,!0;if(!o.parse(e).query)return!1;for(var u=0;u<h.organics.length;u++){if(o.parse(e).host.match(new RegExp("^(?:.*\\.)?"+s.escapeRegexp(h.organics[u].host)+"$","i"))&&o.parse(e).query.match(new RegExp(".*"+s.escapeRegexp(h.organics[u].param)+"=.*","i")))return k=h.organics[u].display||h.organics[u].host,!0;if(u+1===h.organics.length)return!1}}function l(e){if(!(h.referrals.length>0))return k=o.getHost(e),!0;for(var t=0;t<h.referrals.length;t++){if(o.parse(e).host.match(new RegExp("^(?:.*\\.)?"+s.escapeRegexp(h.referrals[t].host)+"$","i")))return k=h.referrals[t].display||h.referrals[t].host,w=h.referrals[t].medium||i.referer.referral,!0;if(t+1===h.referrals.length)return k=o.getHost(e),!0}}function g(){a.set(n.containers.current_extra,n.pack.extra(h.timezone_offset),x,y,v),a.get(n.containers.first_extra)||a.set(n.containers.first_extra,n.pack.extra(h.timezone_offset),x,y,v)}var h=c.fetch(e),_=o.getParam(),y=h.domain.host,v=h.domain.isolate,x=h.lifetime;u.go(x,y,v);var b,k,w,q,I,j,R,D,H,T,E;return function(){a.set(n.containers.current,t(),x,y,v),a.get(n.containers.first)||a.set(n.containers.first,a.get(n.containers.current),x,y,v);var e,r;a.get(n.containers.udata)?(e=parseInt(a.parse(n.containers.udata)[a.unsbjs(n.containers.udata)][n.aliases.udata.visits])||1,e=a.get(n.containers.session)?e:e+1,r=n.pack.user(e,h.user_ip)):(e=1,r=n.pack.user(e,h.user_ip)),a.set(n.containers.udata,r,x,y,v);var i;a.get(n.containers.session)?(i=parseInt(a.parse(n.containers.session)[a.unsbjs(n.containers.session)][n.aliases.session.pages_seen])||1,i+=1):i=1,a.set(n.containers.session,n.pack.session(i),h.session_length,y,v),h.promocode&&!a.get(n.containers.promocode)&&a.set(n.containers.promocode,n.pack.promo(h.promocode),x,y,v)}(),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,o=this.migrations,s={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<o.length;a++)o[a].go(o[a].id,s)}else{var c=[];for(a=0;a<o.length;a++)c.push(o[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,s.l,s.d,s.i)}},migrations:[{id:"1418474375998",version:"1.0.0-beta",go:function(e,t){var r=e+"=1",a=e+"=0",o=function(e,t,r){return t||r?e:n.delimiter};try{var s=[];for(var c in n.containers)n.containers.hasOwnProperty(c)&&s.push(n.containers[c]);for(var u=0;u<s.length;u++)if(i.get(s[u])){var p=i.get(s[u]).replace(/(\|)?\|(\|)?/g,o);i.destroy(s[u],t.d,t.i),i.destroy(s[u],t.d,!t.i),i.set(s[u],p,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(d){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 o=0;o<t.organics.length;o++)t.organics[o].host&&t.organics[o].param&&r.organics.push(t.organics[o]);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,28 +1,15 @@
1
1
  {
2
2
  "name": "@mate-academy/sourcebuster",
3
- "version": "1.1.4",
3
+ "version": "1.2.1",
4
4
  "description": "Get sources of your site's visitors (utm / organic / referral / typein).",
5
5
  "license": "MIT",
6
- "keywords": [
7
- "google",
8
- "analytics",
9
- "adwords",
10
- "utm",
11
- "utm_source",
12
- "utm_medium",
13
- "utm_campaign",
14
- "utm_content",
15
- "utm_term",
16
- "organic",
17
- "referral",
18
- "direct"
19
- ],
20
6
  "main": "./dist/sourcebuster.js",
21
7
  "scripts": {
22
8
  "build": "NODE_ENV=production gulp build",
23
9
  "patch": "npm version patch && npm publish",
24
10
  "minor": "npm version minor && npm publish",
25
- "major": "npm version major && npm publish"
11
+ "major": "npm version major && npm publish",
12
+ "publish-webflow": "sh publish_current_version_to_webflow.sh"
26
13
  },
27
14
  "lintOptions": {
28
15
  "exported": {
@@ -75,5 +62,19 @@
75
62
  },
76
63
  "overrides": {
77
64
  "graceful-fs": "^4.2.11"
78
- }
65
+ },
66
+ "keywords": [
67
+ "google",
68
+ "analytics",
69
+ "adwords",
70
+ "utm",
71
+ "utm_source",
72
+ "utm_medium",
73
+ "utm_campaign",
74
+ "utm_content",
75
+ "utm_term",
76
+ "organic",
77
+ "referral",
78
+ "direct"
79
+ ]
79
80
  }
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- v20
package/CHANGELOG.md DELETED
@@ -1,123 +0,0 @@
1
- ## 1.0.5
2
-
3
- Features:
4
-
5
- - added `t.co` (`host: 't.co', display: 'twitter.com'`) and `plus.url.google.com` (`host: 'plus.url.google.com', display: 'plus.google.com'`) to default `referral` sources. You still can override it by your custom setting (to mark it as `social` for example).
6
-
7
- ## 1.0.4
8
-
9
- Fixes:
10
-
11
- - fixed IE8 bug
12
-
13
- ## 1.0.3
14
-
15
- Fixes:
16
-
17
- - fixed month in dates (`sbjs.get.first_add.fd` & `sbjs.get.current_add.fd`): it was -1 from actual one
18
-
19
- ## 1.0.2
20
-
21
- Fixes:
22
-
23
- - fixed validation of `lifetime`, `session_length` and `timezone_offset` params
24
-
25
- ## 1.0.0
26
-
27
- [Upgrade guide](UPGRADING.md) &middot; [Updated documentation](README.md)
28
-
29
- Changes:
30
-
31
- _Major_
32
-
33
- - API. Rewritten from the ground. See [upgrade guide](UPGRADING.md) and [updated documentation](README.md).
34
- - Changed cookie's domain handling — also see [upgrade guide](UPGRADING.md) and [updated documentation](README.md).
35
- - Changed default `utm_source` & `utm_medium` values for `typein` traffic — you know [what to do](UPGRADING.md) :)
36
-
37
- _Minor_
38
-
39
- - Changed default timezone from UTC to user's system (default — means no custom value provided during `sbjs` initialization).
40
-
41
- _Under the hood_
42
-
43
- - In short: `mess` became `structure`. Check the sources if interested.
44
- - Added migration tool, which updates visitor's cookies to `1.x.x`.
45
- - Changed params delimiter in cookies: from `|` to `|||`. Cookies will be automatically upgraded by migration tool without data loss. You don't have to worry about this change unless you parse these cookies by yourself.
46
-
47
- Features:
48
-
49
- - Added `callback` option to set custom function, which will be executed right after `sbjs` cookies will be set. This function will get `sbjs.get`-object as argument (it contains all detected `sbjs` data).
50
- - Added ability to set custom cookies expiration period
51
- - Added `term` detection from Yandex Direct traffic (if there is no `utm_term` in URL)
52
- - Added `visits` counter: available through `sbjs.get.udata.vst`
53
- - Added `pages` counter for current session: available through `sbjs.get.session.pgs`
54
- - Added `current page` url for current session: available through `sbjs.get.session.cpg`
55
- - And Sourcebuster `1.0.0` available as `CommonJS` / `AMD` module.
56
-
57
- ## 0.0.7
58
-
59
- Features:
60
-
61
- - add `sbjs_current_add` cookie, which holds same data as `sbjs_first_add` cookie, but for the visit when current source was written
62
- - add info about first referer (see changes below)
63
-
64
- Changes:
65
-
66
- - move current `referer` data from stand-alone `sbjs_referer` cookie to `sbjs_current_add` cookie (and also to `sbjs_first_add` cookie, now you can get first and current referers via `get_sbjs.first_add.rf` & `get_sbjs.current_add.rf` getters)
67
-
68
- ## 0.0.6
69
-
70
- Features:
71
-
72
- - add `_setPromocode` user setting to set promocode for visitor;
73
-
74
- ## 0.0.5
75
-
76
- Features:
77
-
78
- - add `_setTypeinAttributes` user setting to set custom `source` and `medium` for `typein` traffic
79
- - set value of `content` = `referer_path` in cookies for `referral` traffic
80
-
81
- ## 0.0.4
82
-
83
- Features:
84
-
85
- - add predefined organic sources into the core (see comments and the list of added sources [in the docs](./README.md#_addorganicsource))
86
- - add Sourcebuster to `bower` ([bower.io](http://bower.io)). Now you can [install it via... `bower`](./README.md#install)
87
-
88
- Changes:
89
-
90
- - switch from Closure Compiler to UglifyJS minification library
91
- - switch from deprecated `escape()`/`unescape()` methods to custom `encode_data()`/`decode_data()` functions (which uses `encodeURIComponent()`/`decodeURIComponent()` with some additions) to set/get cookies. **Please pay attention to this if you parse `sbjs` cookies by yourself.**
92
-
93
- ## 0.0.3
94
-
95
- Features:
96
-
97
- - add `_setTimeZoneOffset` user setting to set default time zone
98
- - add alias param to custom organic source (added via `_addOrganicSource`)
99
-
100
- Changes:
101
-
102
- - change simple and advanced setup methods
103
- - change datetime format to `yyyy-mm-dd hh:mm:ss` (`2014-06-11 17:28:26`)
104
- - store datetime in UTC by default
105
- - remove events `'sbjs:set'` and `'sbjs:ready'` (see *Using the data* section for details)
106
-
107
- Fixes:
108
-
109
- - fix matching of Yandex organic source
110
- - fix matching of custom organic source (added via `_addOrganicSource`)
111
- - fix getter (`get_sbjs`) in IE8 and lower
112
- - fix output of non-ASCII chars via `get_sbjs`
113
-
114
- ## 0.0.2
115
-
116
- Features:
117
-
118
- - add Google AdWords `gclid` param handler
119
- - add `_setCampaignParam` user setting to set custom GET-param, whose value will be set as `utm_campaign` in cookies (if there is no original `utm_campaign` in request)
120
-
121
- ## 0.0.1
122
-
123
- Sourcebuster JS released.
package/UPGRADING.md DELETED
@@ -1,293 +0,0 @@
1
- ## From 0.0.x to 1.0.0
2
-
3
- I'm gonna walk you through the inline-HTML setup pattern, but keep in mind, that Sourcebuster `1.0.0` is available as `CommonJS` / `AMD` module, so you can `require` it as dependency as well.
4
-
5
- ### Install
6
-
7
- ```python
8
- # from `npm`
9
- npm install --save sourcebuster
10
-
11
- # or `bower`
12
- bower install --save sourcebuster
13
- ```
14
-
15
- Or you can [download this repo](https://github.com/alexfedoseev/sourcebuster-js/archive/master.zip) and use `sourcebuster.min.js` from `/dist` folder.
16
-
17
- ### Setup
18
-
19
- Place inside the `<head>` tag:
20
-
21
- ```html
22
- <script src="/path/to/sourcebuster.min.js"></script>
23
- ```
24
-
25
- Unlike `0.0.x`, in `1.0.0` this line will do nothing (I mean no cookies will be set) except it will make available Sourcebuster object — `sbjs`.
26
-
27
- This object has just 2 methods: `init` and `get`. Basically first one is `setter`, and the second one is `getter`.
28
-
29
- So, lets initialize it:
30
-
31
- ```html
32
- <script src="/path/to/sourcebuster.min.js"></script>
33
- <script>
34
-
35
- sbjs.init();
36
-
37
- </script>
38
- ```
39
-
40
- This will:
41
-
42
- - set all the cookies
43
- - give you the data (through the second method `sbjs.get`)
44
-
45
- ### Configure
46
-
47
- `sbjs.init` accepts one argument: object with the settings. It's optional and usually it will be something like this:
48
-
49
- ```javascript
50
- sbjs.init({
51
- domain: 'alexfedoseev.com',
52
- lifetime: 3,
53
- callback: doSmth
54
- });
55
- ```
56
-
57
- Now I'll show you the whole list of configurable options. The short description is provided in comments. Some critical changes explained in this guide. The rest is explained in the documentation.
58
-
59
- ```javascript
60
- sbjs.init({
61
-
62
- // Set custom expiration period for cookies in months
63
- // 6 months is default
64
- lifetime: 6,
65
-
66
- // Set custom session length in minutes (no changes since 0.0.x)
67
- // 30 minutes is default
68
- session_length: 30,
69
-
70
- // Set domain name in cookies
71
- // Behaviour is changed! Detailed explanation below
72
- domain: {
73
- host: 'alexfedoseev.com',
74
- isolate: false
75
- },
76
-
77
- // Set custom referrals (no changes since 0.0.x)
78
- // This is an array of objects
79
- referrals: [
80
- {
81
- host: 't.co', // This is host from Twitter's `http referer`
82
- medium: 'social', // This is custom `utm_medium`, you can drop it and it'll be `referral`
83
- display: 'twitter.com' // And this is how you'll see it in the result data
84
- },
85
- {
86
- host: 'plus.url.google.com',
87
- display: 'plus.google.com'
88
- }
89
- ],
90
-
91
- // Set custom organics (no changes since 0.0.x)
92
- // This is an array of objects
93
- organics: [
94
- {
95
- host: 'bing.com',
96
- param: 'q',
97
- display: 'bing'
98
- }
99
- ],
100
-
101
- // Set `utm_source` & `utm_medium` values for `typein` traffic
102
- // Defaults are changed, now it's `(direct)` & `(none)`, detailed explanation below
103
- typein_attributes: {
104
- source: '(direct)',
105
- medium: '(none)'
106
- },
107
-
108
- // Set time zone
109
- // Default behaviour is changed, detailed explanation below
110
- timezone_offset: 3,
111
-
112
- // Set custom `utm_campaign` param (no changes since 0.0.x)
113
- campaign_param: 'my_adwords_campaign',
114
-
115
- // Set user ip (no changes since 0.0.x)
116
- user_ip: '192.168.1.1',
117
-
118
- // Set promocode (no changes since 0.0.x)
119
- // Default range is [100000..999999]
120
- promocode: {
121
- min: 100000,
122
- max: 999999
123
- },
124
-
125
- // Set callback-function,
126
- // It will be executed right after `sbjs` cookies will be set
127
- // Detailed explanation below
128
- callback: doSmth
129
- });
130
- ```
131
-
132
- #### Highlights
133
-
134
- ##### domain
135
-
136
- ```javascript
137
- // 0.0.x
138
- _sbjs.push(['_setBaseHost', 'alexfedoseev.com']);
139
-
140
-
141
- //1.0.0
142
- domain: 'alexfedoseev.com'
143
-
144
- // the same
145
- domain: {
146
- host: 'alexfedoseev.com',
147
- isolate: false
148
- }
149
- ```
150
-
151
- The main thing, that changed, is how the script handles **the absence** of this custom option. When no `BaseHost` was set, script's cookie was set **only for current host**. That is ok, if the site doesn't have subdomains to share traffic with and it **never will**.
152
-
153
- But what's gonna happen if someday subdomains will occur? In `0.0.x` they won't get the cookies, it means they won't share the traffic, and visitors from main domain to subdomains will be considered as `referral`.
154
-
155
- I changed this behaviour, so if the setting is absent, cookies will be set for **current domain and all its subdomains**.
156
-
157
- However if you don't want to share the cookies — use `isolate: true`, to isolate this domain.
158
-
159
- So, how to update: just pick suitable configuration and pass it to `init` method. Migration tool will do the rest. It's one-time migration, so chose wisely.
160
-
161
- Lets see how to set this option in common cases.
162
-
163
- **— You don't have subdomains, but someday maybe**
164
-
165
- ```javascript
166
- // just don't use this option or use this one
167
- domain: 'your-domain.com'
168
- ```
169
-
170
- **— You don't have subdomains, and don't want to share cookies for some reason**
171
-
172
- ```javascript
173
- domain: {
174
- host: 'your-domain.com',
175
- isolate: true
176
- }
177
- ```
178
-
179
- **— You have subdomains and want to share traffic between them**
180
-
181
- ```javascript
182
- // on all pages of domain and its subdomains
183
- domain: 'your-domain.com'
184
- ```
185
-
186
- **— You have subdomains, but don't want to share traffic between them**
187
- (so visits from domain to subdomains and vise versa will be considered as `referral`)
188
-
189
- ```javascript
190
- // on all pages of domain
191
- domain: {
192
- host: 'your-domain.com',
193
- isolate: true
194
- }
195
-
196
- // and on all pages of subdomain
197
- domain: 'sub.your-domain.com'
198
-
199
- // or
200
- domain: {
201
- host: 'sub.your-domain.com',
202
- isolate: false // or use `isolate: true` if you'd like to isolate it too
203
- }
204
- ```
205
-
206
- Hope you've got the point. If you have any questions — check [documentation](README.md) for more detailed explanation or [post an issue](https://github.com/alexfedoseev/sourcebuster-js/issues/new).
207
-
208
- After you'll roll out the `1.0.0` to production, visitor's old cookies will be updated to chosen setup. Again: it's one-time migration, so chose wisely.
209
-
210
- **NB! Do not change `isolate` value after update. If you'll do — your visitors will get doubled cookies and bad things may happen.**
211
-
212
- The option, that will give the ability to force-update cookies domain (if you need to change subdomains handling rules), is in my TODO-list, but not available yet.
213
-
214
- ##### typein_attributes
215
-
216
- ```javascript
217
- // 0.0.x
218
- _sbjs.push(['_setTypeinAttributes', '(typein)', '(typein)']);
219
-
220
-
221
- //1.0.0
222
- typein_attributes: {
223
- source: '(direct)',
224
- medium: '(none)'
225
- }
226
- ```
227
-
228
- In `0.0.x` default `utm_source` & `utm_medium` values for `typein` traffic was `(typein)`. And they differ from Google Analytics values: `(direct)` & `(none)`. So I made them equal by default.
229
-
230
- How to update.
231
-
232
- If you haven't used `_setTypeinAttributes` and wish to keep `utm_source` & `utm_medium` values as `(typein)`, then you need to add:
233
-
234
- ```javascript
235
- typein_attributes: {
236
- source: '(typein)',
237
- medium: '(typein)'
238
- }
239
- ```
240
-
241
- Otherwise just don't use this setting. Values will be `(direct)` & `(none)`.
242
-
243
- ##### timezone_offset
244
-
245
- ```javascript
246
- // 0.0.x
247
- _sbjs.push(['_setTimeZoneOffset', 3]);
248
-
249
- //1.0.0
250
- timezone_offset: 3
251
- ```
252
-
253
- Nothing changed except default behaviour. In `0.0.x`, if no custom value was set, time was normalized to UTC. `1.0.0` have no normalization by default, script uses user's system time.
254
-
255
- Example. Your visitor is in London (`UTC +00:00`). His local time is `03:00 AM`. If no `timezone_offset` was set, the time in cookie will be `03:00 AM`. Another visitor at the same moment is from Berlin (`UTC +01:00`) and his local time is `04:00 AM`. The time in cookie will be `04:00 AM`.
256
-
257
- If you want to normalize time of all visitors (let it be `UTC +03:00` for example), you should set it via `timezone_offset: 3`. So the time in cookies of both visitors will be `06:00 AM`.
258
-
259
- ##### callback
260
-
261
- ```javascript
262
- callback: doSmth
263
- ```
264
-
265
- No workarounds anymore, just pass the name of the function to `callback` option, and it will be executed right after the cookies will be set. Callback will get the object with `sbjs` data as argument.
266
-
267
- ```javascript
268
- sbjs.init({ callback: go });
269
-
270
- function go(sb) {
271
- console.log('Cookies are set! Your current source is: ' + sb.current.src);
272
- }
273
- ```
274
-
275
- ### Get data
276
-
277
- `get_sbjs` is gone. Grab the data through `sbjs.get` method.
278
-
279
- If you don't want to replace `get_sbjs` in your code, just do this:
280
-
281
- ```javascript
282
- var get_sbjs = sbjs.get;
283
-
284
- // and your old code is fine
285
- document.getElementById('user-source').innerHTML = get_sbjs.current.src;
286
- ```
287
-
288
- ### Cookies
289
-
290
- Changed params delimiter in cookies: from `|` to `|||`. Cookies will be automatically upgraded by migration tool without data loss. You don't have to worry about this change unless you parse these cookies by yourself.
291
-
292
-
293
- That's it. If you have any questions — [place an issue](https://github.com/alexfedoseev/sourcebuster-js/issues/new).
package/bower.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "name": "sourcebuster",
3
- "version": "1.0.5",
4
- "description": "Get sources of your site's visitors (utm / organic / referral / typein).",
5
- "homepage": "https://github.com/alexfedoseev/sourcebuster-js",
6
- "authors": [
7
- {
8
- "name": "Alex Fedoseev",
9
- "email": "alex.fedoseev@gmail.com",
10
- "homepage": "http://www.alexfedoseev.com"
11
- }
12
- ],
13
- "license": "MIT",
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/alexfedoseev/sourcebuster-js.git"
17
- },
18
- "bugs": {
19
- "url": "https://github.com/alexfedoseev/sourcebuster-js/issues"
20
- },
21
- "main": "./dist/sourcebuster.min.js",
22
- "ignore": [
23
- ".*",
24
- "**/.*",
25
- "package.json",
26
- "gulpfile.js",
27
- "node_modules",
28
- "bower_components",
29
- "test",
30
- "tests",
31
- "src",
32
- "lib"
33
- ],
34
- "dependencies": {}
35
- }
package/gulpfile.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- var requireDir = require('require-dir');
4
-
5
- global.not_4production = process.env.NODE_ENV !== 'production';
6
-
7
- requireDir('./lib/gulp/tasks', { recurse: true });