@mate-academy/sourcebuster 1.1.2

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.
@@ -0,0 +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)});
package/gulpfile.js ADDED
@@ -0,0 +1,7 @@
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 });
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ var pkg = require('../../package.json'),
4
+ bundler = require('./helpers/bundler');
5
+
6
+ var paths = {
7
+ in_base: './src/',
8
+ out_dist: './dist/',
9
+ out_public: './public/'
10
+ };
11
+
12
+ var types = {
13
+ js: 'js',
14
+ };
15
+
16
+ var bundles = [
17
+ {
18
+ name: 'sourcebuster',
19
+ global: 'sbjs',
20
+ compress: true,
21
+ save_to_dist: true
22
+ }
23
+ ];
24
+
25
+ // Go
26
+ module.exports = {
27
+
28
+ scripts: {
29
+ bundle_configs: bundler(bundles, types.js, paths),
30
+ banner: '/** ' + pkg.name + ' v' + pkg.version + ' **/\n',
31
+ debug: global.not_4production,
32
+ extensions: ['.jsx'],
33
+ lint: {
34
+ options: pkg.lintOptions,
35
+ dir: paths.in_base + types.js + '/'
36
+ }
37
+ },
38
+
39
+ clean: {
40
+ html: paths.out_public,
41
+ imgs: paths.out_public + types.img + '/',
42
+ css: paths.out_public + types.css + '/',
43
+ scripts: paths.out_public + types.js + '/',
44
+ dist: paths.out_dist
45
+ }
46
+
47
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ module.exports = function(bundles, type, paths) {
4
+
5
+ var makeBundle = function(bundle) {
6
+
7
+ var type_dir = type + '/',
8
+ in_dir = paths.in_base + type_dir,
9
+ in_file = bundle.name + '.' + type,
10
+ out_dir = paths.out_public + type_dir,
11
+ out_file = bundle.name + '.' + type;
12
+
13
+ return {
14
+ in_dir: in_dir,
15
+ in_file: in_file,
16
+ out_dist_dir: paths.out_dist,
17
+ out_public_dir: out_dir,
18
+ out_file: out_file,
19
+ global: bundle.global,
20
+ compress: bundle.compress,
21
+ save_to_dist: bundle.save_to_dist
22
+ };
23
+ };
24
+
25
+ var pack = [];
26
+ for (var i = 0; i < bundles.length; i++) {
27
+ pack.push(makeBundle(bundles[i]));
28
+ }
29
+ return pack;
30
+
31
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ module.exports = function(location, extension) {
4
+ var files = [];
5
+ if (extension) {
6
+ files.push(location + '*.' + extension);
7
+ files.push(location + '**/*.' + extension);
8
+ } else {
9
+ files.push(location + '**')
10
+ }
11
+ return files;
12
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var gulp = require('gulp'),
4
+ jshint = require('gulp-jshint'),
5
+ map = require('map-stream'),
6
+ finder = require('../helpers/finder'),
7
+ notifier = require('../helpers/notifier'),
8
+ config = require('../config').scripts.lint;
9
+
10
+ module.exports = function() {
11
+
12
+ var failReporter = map(function(file, cb) {
13
+ if (!file.jshint.success) notifier(file.relative, true, 'Ooooooops!');
14
+ cb(null, file);
15
+ });
16
+
17
+ return gulp.src(finder(config.dir, 'js'))
18
+ .pipe(jshint(config.options))
19
+ .pipe(jshint.reporter())
20
+ .pipe(failReporter);
21
+
22
+ };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ var gutil = require('gulp-util'),
4
+ notifier = require('node-notifier');
5
+
6
+ module.exports = function(file, is_fail, msg) {
7
+
8
+ var say = msg || 'Bundled!',
9
+ color = is_fail ? 'red' : 'green',
10
+ icon = is_fail ? '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns' : false;
11
+
12
+ if (global.do_beep) {
13
+ notifier.notify({
14
+ title: file,
15
+ message: say,
16
+ icon: icon,
17
+ sound: true
18
+ });
19
+ }
20
+
21
+ gutil.log(say, gutil.colors[color](file));
22
+
23
+ };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ var gulp = require('gulp'),
4
+ del = require('del'),
5
+ finder = require('../helpers/finder'),
6
+ config = require('../config').clean;
7
+
8
+ gulp.task('bundle', ['scripts'], function() {
9
+ if (global.not_4production) { global.do_beep = true; }
10
+ });
11
+
12
+ gulp.task('clean', function(cb) {
13
+
14
+ del([].concat(
15
+ finder(config.scripts, 'js'),
16
+ finder(config.scripts, 'map'),
17
+ finder(config.dist, 'js'),
18
+ finder(config.dist, 'map')
19
+ ),
20
+ cb
21
+ );
22
+
23
+ });
24
+
25
+ gulp.task('build', ['clean'], function() {
26
+ gulp.start('bundle')
27
+ });
@@ -0,0 +1,3 @@
1
+ var gulp = require('gulp');
2
+
3
+ gulp.task('default', ['watch']);
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ var gulp = require('gulp'),
4
+ browserify = require('browserify'),
5
+ watchify = require('watchify'),
6
+ uglify = require('gulp-uglify'),
7
+ sourcemaps = require('gulp-sourcemaps'),
8
+ derequire = require('gulp-derequire'),
9
+ source = require('vinyl-source-stream'),
10
+ buffer = require('vinyl-buffer'),
11
+ rename = require('gulp-rename'),
12
+ header = require('gulp-header'),
13
+ gulpif = require('gulp-if'),
14
+ linter = require('../helpers/linter'),
15
+ notifier = require('../helpers/notifier'),
16
+ config = require('../config').scripts;
17
+
18
+ gulp.task('scripts', function(cb) {
19
+
20
+ var bundle_queue = config.bundle_configs.length,
21
+ not_4production = process.env.NODE_ENV !== 'production';
22
+
23
+ var browserifyThis = function(bundle_config) {
24
+
25
+ var bundler = browserify({
26
+ cache: {}, packageCache: {}, fullPaths: not_4production,
27
+ entries: bundle_config.in_dir + bundle_config.in_file,
28
+ standalone: bundle_config.global,
29
+ extensions: config.extensions,
30
+ debug: config.debug
31
+ });
32
+
33
+ var bundle = function() {
34
+
35
+ linter();
36
+
37
+ return bundler
38
+ .bundle()
39
+ .pipe(source(bundle_config.out_file))
40
+ .pipe(derequire())
41
+ .pipe(gulpif(global.not_4production, gulp.dest(bundle_config.out_public_dir)))
42
+ .pipe(gulpif(bundle_config.save_to_dist, gulp.dest(bundle_config.out_dist_dir)))
43
+ .pipe(gulpif(bundle_config.compress, buffer()))
44
+ .pipe(gulpif(bundle_config.compress && global.not_4production, sourcemaps.init({loadMaps: true})))
45
+ .pipe(gulpif(bundle_config.compress, uglify()))
46
+ .pipe(gulpif(bundle_config.compress, rename({suffix: '.min'})))
47
+ .pipe(gulpif(!global.not_4production, header(config.banner)))
48
+ .pipe(gulpif(bundle_config.compress && global.not_4production, sourcemaps.write('./')))
49
+ .pipe(gulpif(bundle_config.save_to_dist, gulp.dest(bundle_config.out_dist_dir)))
50
+ .pipe(gulp.dest(bundle_config.out_public_dir))
51
+ .on('end', handleQueue);
52
+ };
53
+
54
+ if (global.is_watching) {
55
+ bundler = watchify(bundler);
56
+ bundler.on('update', bundle);
57
+ }
58
+
59
+ var handleQueue = function() {
60
+ notifier(bundle_config.out_file);
61
+ if (bundle_queue) {
62
+ bundle_queue--;
63
+ if (bundle_queue === 0) {
64
+ cb();
65
+ }
66
+ }
67
+ };
68
+
69
+ return bundle();
70
+ };
71
+
72
+ config.bundle_configs.forEach(browserifyThis);
73
+
74
+ });
75
+
76
+ gulp.task('lint', function() {
77
+ linter();
78
+ });
@@ -0,0 +1,13 @@
1
+ var gulp = require('gulp'),
2
+ finder = require('../helpers/finder'),
3
+ config = require('../config');
4
+
5
+ gulp.task('watch', ['watching', 'build'], function() {
6
+ gulp.watch(finder(config.css.in_dir), ['css']);
7
+ gulp.watch(finder(config.imgs.in_dir), ['imgs']);
8
+ gulp.watch(finder(config.html.in_dir), ['html']);
9
+ });
10
+
11
+ gulp.task('watching', function() {
12
+ global.is_watching = true;
13
+ });
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@mate-academy/sourcebuster",
3
+ "version": "1.1.2",
4
+ "description": "Get sources of your site's visitors (utm / organic / referral / typein).",
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
+ "main": "./dist/sourcebuster.js",
21
+ "scripts": {
22
+ "build": "NODE_ENV=production gulp build",
23
+ "patch": "npm version patch && npm publish",
24
+ "minor": "npm version minor && npm publish",
25
+ "major": "npm version major && npm publish"
26
+ },
27
+ "lintOptions": {
28
+ "exported": {
29
+ "sbjs": true,
30
+ "data": true
31
+ },
32
+ "node": true,
33
+ "bitwise": true,
34
+ "browser": true,
35
+ "curly": false,
36
+ "eqeqeq": true,
37
+ "forin": true,
38
+ "immed": true,
39
+ "indent": 2,
40
+ "latedef": "nofunc",
41
+ "newcap": true,
42
+ "noarg": true,
43
+ "noempty": true,
44
+ "nonbsp": true,
45
+ "nonew": true,
46
+ "nonstandard": true,
47
+ "strict": false,
48
+ "globalstrict": true,
49
+ "sub": true,
50
+ "supernew": true,
51
+ "undef": true,
52
+ "unused": true
53
+ },
54
+ "devDependencies": {
55
+ "browserify": "^7.0.0",
56
+ "del": "^1.1.0",
57
+ "gulp": "^3.8.10",
58
+ "gulp-autoprefixer": "^2.0.0",
59
+ "gulp-changed": "^1.1.0",
60
+ "gulp-derequire": "^2.0.0",
61
+ "gulp-header": "^1.2.2",
62
+ "gulp-if": "^1.2.5",
63
+ "gulp-jshint": "^1.9.0",
64
+ "gulp-rename": "^1.2.0",
65
+ "gulp-slim": "^0.3.0",
66
+ "gulp-sourcemaps": "^1.2.8",
67
+ "gulp-uglify": "^1.0.2",
68
+ "gulp-util": "^3.0.1",
69
+ "map-stream": "0.0.5",
70
+ "node-notifier": "^4.0.3",
71
+ "require-dir": "^0.1.0",
72
+ "vinyl-buffer": "^1.0.0",
73
+ "vinyl-source-stream": "^1.0.0",
74
+ "watchify": "^2.1.1"
75
+ },
76
+ "overrides": {
77
+ "graceful-fs": "^4.2.11"
78
+ }
79
+ }
@@ -0,0 +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)});
package/src/js/data.js ADDED
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ var terms = require('./terms'),
4
+ utils = require('./helpers/utils');
5
+
6
+ var data = {
7
+
8
+ containers: {
9
+ current: 'sbjs_current',
10
+ current_extra: 'sbjs_current_add',
11
+ first: 'sbjs_first',
12
+ first_extra: 'sbjs_first_add',
13
+ session: 'sbjs_session',
14
+ udata: 'sbjs_udata',
15
+ promocode: 'sbjs_promo'
16
+ },
17
+
18
+ service: {
19
+ migrations: 'sbjs_migrations'
20
+ },
21
+
22
+ delimiter: '|||',
23
+
24
+ aliases: {
25
+
26
+ main: {
27
+ type: 'typ',
28
+ source: 'src',
29
+ medium: 'mdm',
30
+ campaign: 'cmp',
31
+ content: 'cnt',
32
+ term: 'trm',
33
+ account_id: 'ac_id',
34
+ campaign_id: 'cmp_id',
35
+ ad_group_id: 'adg_id',
36
+ ad_id: 'ad_id',
37
+ term_id: 'trm_id'
38
+ },
39
+
40
+ extra: {
41
+ fire_date: 'fd',
42
+ entrance_point: 'ep',
43
+ referer: 'rf'
44
+ },
45
+
46
+ session: {
47
+ pages_seen: 'pgs',
48
+ current_page: 'cpg'
49
+ },
50
+
51
+ udata: {
52
+ visits: 'vst',
53
+ ip: 'uip',
54
+ agent: 'uag'
55
+ },
56
+
57
+ promo: 'code'
58
+
59
+ },
60
+
61
+ pack: {
62
+
63
+ main: function(sbjs) {
64
+ return (
65
+ data.aliases.main.type + '=' + sbjs.type + data.delimiter +
66
+ data.aliases.main.source + '=' + sbjs.source + data.delimiter +
67
+ data.aliases.main.medium + '=' + sbjs.medium + data.delimiter +
68
+ data.aliases.main.campaign + '=' + sbjs.campaign + data.delimiter +
69
+ data.aliases.main.content + '=' + sbjs.content + data.delimiter +
70
+ data.aliases.main.term + '=' + sbjs.term + data.delimiter +
71
+ data.aliases.main.account_id + '=' + sbjs.account_id + data.delimiter +
72
+ data.aliases.main.campaign_id + '=' + sbjs.campaign_id + data.delimiter +
73
+ data.aliases.main.ad_group_id + '=' + sbjs.ad_group_id + data.delimiter +
74
+ data.aliases.main.ad_id + '=' + sbjs.ad_id + data.delimiter +
75
+ data.aliases.main.term_id + '=' + sbjs.term_id
76
+ );
77
+ },
78
+
79
+ extra: function(timezone_offset) {
80
+ return (
81
+ data.aliases.extra.fire_date + '=' + utils.setDate(new Date, timezone_offset) + data.delimiter +
82
+ data.aliases.extra.entrance_point + '=' + document.location.href + data.delimiter +
83
+ data.aliases.extra.referer + '=' + (document.referrer || terms.none)
84
+ );
85
+ },
86
+
87
+ user: function(visits, user_ip) {
88
+ return (
89
+ data.aliases.udata.visits + '=' + visits + data.delimiter +
90
+ data.aliases.udata.ip + '=' + user_ip + data.delimiter +
91
+ data.aliases.udata.agent + '=' + navigator.userAgent
92
+ );
93
+ },
94
+
95
+ session: function(pages) {
96
+ return (
97
+ data.aliases.session.pages_seen + '=' + pages + data.delimiter +
98
+ data.aliases.session.current_page + '=' + document.location.href
99
+ );
100
+ },
101
+
102
+ promo: function(promo) {
103
+ return (
104
+ data.aliases.promo + '=' + utils.setLeadingZeroToInt(utils.randomInt(promo.min, promo.max), promo.max.toString().length)
105
+ );
106
+ }
107
+
108
+ }
109
+ };
110
+
111
+ module.exports = data;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ var delimiter = require('../data').delimiter;
4
+
5
+ module.exports = {
6
+
7
+ encodeData: function(s) {
8
+ return encodeURIComponent(s).replace(/\!/g, '%21')
9
+ .replace(/\~/g, '%7E')
10
+ .replace(/\*/g, '%2A')
11
+ .replace(/\'/g, '%27')
12
+ .replace(/\(/g, '%28')
13
+ .replace(/\)/g, '%29');
14
+ },
15
+
16
+ decodeData: function(s) {
17
+ try {
18
+ return decodeURIComponent(s).replace(/\%21/g, '!')
19
+ .replace(/\%7E/g, '~')
20
+ .replace(/\%2A/g, '*')
21
+ .replace(/\%27/g, "'")
22
+ .replace(/\%28/g, '(')
23
+ .replace(/\%29/g, ')');
24
+ } catch(err1) {
25
+ // try unescape for backward compatibility
26
+ try { return unescape(s); } catch(err2) { return ''; }
27
+ }
28
+ },
29
+
30
+ set: function(name, value, minutes, domain, excl_subdomains) {
31
+ var expires, basehost;
32
+
33
+ if (minutes) {
34
+ var date = new Date();
35
+ date.setTime(date.getTime() + (minutes * 60 * 1000));
36
+ expires = '; expires=' + date.toGMTString();
37
+ } else {
38
+ expires = '';
39
+ }
40
+ if (domain && !excl_subdomains) {
41
+ basehost = ';domain=.' + domain;
42
+ } else {
43
+ basehost = '';
44
+ }
45
+ document.cookie = this.encodeData(name) + '=' + this.encodeData(value) + expires + basehost + '; path=/';
46
+ },
47
+
48
+ get: function(name) {
49
+ var nameEQ = this.encodeData(name) + '=',
50
+ ca = document.cookie.split(';');
51
+
52
+ for (var i = 0; i < ca.length; i++) {
53
+ var c = ca[i];
54
+ while (c.charAt(0) === ' ') { c = c.substring(1, c.length); }
55
+ if (c.indexOf(nameEQ) === 0) {
56
+ return this.decodeData(c.substring(nameEQ.length, c.length));
57
+ }
58
+ }
59
+ return null;
60
+ },
61
+
62
+ destroy: function(name, domain, excl_subdomains) {
63
+ this.set(name, '', -1, domain, excl_subdomains);
64
+ },
65
+
66
+ parse: function(yummy) {
67
+
68
+ var cookies = [],
69
+ data = {};
70
+
71
+ if (typeof yummy === 'string') {
72
+ cookies.push(yummy);
73
+ } else {
74
+ for (var prop in yummy) {
75
+ if (yummy.hasOwnProperty(prop)) {
76
+ cookies.push(yummy[prop]);
77
+ }
78
+ }
79
+ }
80
+
81
+ for (var i1 = 0; i1 < cookies.length; i1++) {
82
+ var cookie_array;
83
+ data[this.unsbjs(cookies[i1])] = {};
84
+ if (this.get(cookies[i1])) {
85
+ cookie_array = this.get(cookies[i1]).split(delimiter);
86
+ } else {
87
+ cookie_array = [];
88
+ }
89
+ for (var i2 = 0; i2 < cookie_array.length; i2++) {
90
+ var tmp_array = cookie_array[i2].split('='),
91
+ result_array = tmp_array.splice(0, 1);
92
+ result_array.push(tmp_array.join('='));
93
+ data[this.unsbjs(cookies[i1])][result_array[0]] = this.decodeData(result_array[1]);
94
+ }
95
+ }
96
+
97
+ return data;
98
+
99
+ },
100
+
101
+ unsbjs: function (string) {
102
+ return string.replace('sbjs_', '');
103
+ }
104
+
105
+ };