!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.sbjs=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { for (var i = 0; i < p.referrals.length; i++) { if (uri.parse(referer).host.match(new RegExp('^(?:.*\\.)?' + utils.escapeRegexp(p.referrals[i].host) + '$', 'i'))) { __sbjs_source = p.referrals[i].display || p.referrals[i].host; __sbjs_medium = p.referrals[i].medium || terms.referer.referral; return true; } if (i + 1 === p.referrals.length) { __sbjs_source = uri.getHost(referer); return true; } } } else { __sbjs_source = uri.getHost(referer); return true; } } function setFirstAndCurrentExtraData() { cookies.set(data.containers.current_extra, data.pack.extra(p.timezone_offset), lifetime, domain, isolate); if (!cookies.get(data.containers.first_extra)) { cookies.set(data.containers.first_extra, data.pack.extra(p.timezone_offset), lifetime, domain, isolate); } } (function setData() { // Main data cookies.set(data.containers.current, mainData(), lifetime, domain, isolate); if (!cookies.get(data.containers.first)) { cookies.set(data.containers.first, cookies.get(data.containers.current), lifetime, domain, isolate); } // User data var visits, udata; if (!cookies.get(data.containers.udata)) { visits = 1; udata = data.pack.user(visits, p.user_ip); } else { visits = parseInt(cookies.parse(data.containers.udata)[cookies.unsbjs(data.containers.udata)][data.aliases.udata.visits]) || 1; visits = cookies.get(data.containers.session) ? visits : visits + 1; udata = data.pack.user(visits, p.user_ip); } cookies.set(data.containers.udata, udata, lifetime, domain, isolate); // Session var pages_count; if (!cookies.get(data.containers.session)) { pages_count = 1; } else { pages_count = parseInt(cookies.parse(data.containers.session)[cookies.unsbjs(data.containers.session)][data.aliases.session.pages_seen]) || 1; pages_count += 1; } cookies.set(data.containers.session, data.pack.session(pages_count), p.session_length, domain, isolate); // Promocode if (p.promocode && !cookies.get(data.containers.promocode)) { cookies.set(data.containers.promocode, data.pack.promo(p.promocode), lifetime, domain, isolate); } })(); return cookies.parse(data.containers); }; },{"./data":2,"./helpers/cookies":3,"./helpers/uri":4,"./helpers/utils":5,"./migrations":7,"./params":8,"./terms":9}],7:[function(_dereq_,module,exports){ "use strict"; var data = _dereq_('./data'), cookies = _dereq_('./helpers/cookies'); module.exports = { go: function(lifetime, domain, isolate) { var migrate = this.migrations, _with = { l: lifetime, d: domain, i: isolate }; var i; if (!cookies.get(data.containers.first) && !cookies.get(data.service.migrations)) { var mids = []; for (i = 0; i < migrate.length; i++) { mids.push(migrate[i].id); } var advance = ''; for (i = 0; i < mids.length; i++) { advance += mids[i] + '=1'; if (i < mids.length - 1) { advance += data.delimiter; } } cookies.set(data.service.migrations, advance, _with.l, _with.d, _with.i); } else if (!cookies.get(data.service.migrations)) { // We have only one migration for now, so just for (i = 0; i < migrate.length; i++) { migrate[i].go(migrate[i].id, _with); } } }, migrations: [ { id: '1418474375998', version: '1.0.0-beta', go: function(mid, _with) { var success = mid + '=1', fail = mid + '=0'; var safeReplace = function($0, $1, $2) { return ($1 || $2 ? $0 : data.delimiter); }; try { // Switch delimiter and renew cookies var _in = []; for (var prop in data.containers) { if (data.containers.hasOwnProperty(prop)) { _in.push(data.containers[prop]); } } for (var i = 0; i < _in.length; i++) { if (cookies.get(_in[i])) { var buffer = cookies.get(_in[i]).replace(/(\|)?\|(\|)?/g, safeReplace); cookies.destroy(_in[i], _with.d, _with.i); cookies.destroy(_in[i], _with.d, !_with.i); cookies.set(_in[i], buffer, _with.l, _with.d, _with.i); } } // Update `session` if (cookies.get(data.containers.session)) { cookies.set(data.containers.session, data.pack.session(0), _with.l, _with.d, _with.i); } // Yay! cookies.set(data.service.migrations, success, _with.l, _with.d, _with.i); } catch (err) { // Oops cookies.set(data.service.migrations, fail, _with.l, _with.d, _with.i); } } } ] }; },{"./data":2,"./helpers/cookies":3}],8:[function(_dereq_,module,exports){ "use strict"; var terms = _dereq_('./terms'), uri = _dereq_('./helpers/uri'); module.exports = { fetch: function(prefs) { var user = prefs || {}, params = {}; // Set `lifetime of the cookie` in months params.lifetime = this.validate.checkFloat(user.lifetime) || 6; params.lifetime = parseInt(params.lifetime * 30 * 24 * 60); // Set `session length` in minutes params.session_length = this.validate.checkInt(user.session_length) || 30; // Set `timezone offset` in hours params.timezone_offset = this.validate.checkInt(user.timezone_offset); // Enable `base64 encoding` params.base64 = user.base64 || false; // Set `campaign param` for AdWords links params.campaign_param = user.campaign_param || false; // Set `term param` and `content param` for AdWords links params.term_param = user.term_param || false; params.content_param = user.content_param || false; // Set `user ip` params.user_ip = user.user_ip || terms.none; // Set `promocode` if (user.promocode) { params.promocode = {}; params.promocode.min = parseInt(user.promocode.min) || 100000; params.promocode.max = parseInt(user.promocode.max) || 999999; } else { params.promocode = false; } // Set `typein attributes` if (user.typein_attributes && user.typein_attributes.source && user.typein_attributes.medium) { params.typein_attributes = {}; params.typein_attributes.source = user.typein_attributes.source; params.typein_attributes.medium = user.typein_attributes.medium; } else { params.typein_attributes = { source: '(direct)', medium: '(none)' }; } // Set `domain` if (user.domain && this.validate.isString(user.domain)) { params.domain = { host: user.domain, isolate: false }; } else if (user.domain && user.domain.host) { params.domain = user.domain; } else { params.domain = { host: uri.getHost(document.location.hostname), isolate: false }; } // Set `referral sources` params.referrals = []; if (user.referrals && user.referrals.length > 0) { for (var ir = 0; ir < user.referrals.length; ir++) { if (user.referrals[ir].host) { params.referrals.push(user.referrals[ir]); } } } // Set `organic sources` params.organics = []; if (user.organics && user.organics.length > 0) { for (var io = 0; io < user.organics.length; io++) { if (user.organics[io].host && user.organics[io].param) { params.organics.push(user.organics[io]); } } } params.organics.push({ host: 'bing.com', param: 'q', display: 'bing' }); params.organics.push({ host: 'yahoo.com', param: 'p', display: 'yahoo' }); params.organics.push({ host: 'about.com', param: 'q', display: 'about' }); params.organics.push({ host: 'aol.com', param: 'q', display: 'aol' }); params.organics.push({ host: 'ask.com', param: 'q', display: 'ask' }); params.organics.push({ host: 'globososo.com', param: 'q', display: 'globo' }); params.organics.push({ host: 'go.mail.ru', param: 'q', display: 'go.mail.ru' }); params.organics.push({ host: 'rambler.ru', param: 'query', display: 'rambler' }); params.organics.push({ host: 'tut.by', param: 'query', display: 'tut.by' }); params.referrals.push({ host: 't.co', display: 'twitter.com' }); params.referrals.push({ host: 'plus.url.google.com', display: 'plus.google.com' }); return params; }, validate: { checkFloat: function(v) { return v && this.isNumeric(parseFloat(v)) ? parseFloat(v) : false; }, checkInt: function(v) { return v && this.isNumeric(parseInt(v)) ? parseInt(v) : false; }, isNumeric: function(v){ return !isNaN(v); }, isString: function(v) { return Object.prototype.toString.call(v) === '[object String]'; } } }; },{"./helpers/uri":4,"./terms":9}],9:[function(_dereq_,module,exports){ "use strict"; module.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) });