Browse Source

Sync with master

master
dustinlarimer 9 years ago
parent
commit
e95c53eb11
  1. 150
      dist/keen-tracking.js
  2. 10
      dist/keen-tracking.min.js
  3. 28
      lib/utils/cookie.js
  4. 4
      package.json

150
dist/keen-tracking.js

File diff suppressed because one or more lines are too long

10
dist/keen-tracking.min.js

File diff suppressed because one or more lines are too long

28
lib/utils/cookie.js

@ -1,4 +1,4 @@
var Cookies = require('cookies-js');
var Cookies = require('js-cookie');
var extend = require('./extend');
module.exports = cookie;
@ -11,7 +11,9 @@ function cookie(str){
this.config = {
key: str,
options: {}
options: {
expires: 365
}
};
this.data = this.get();
return this;
@ -21,10 +23,10 @@ cookie.prototype.get = function(str){
var data = {};
if (Cookies.get(this.config.key)) {
data = JSON.parse( decodeURIComponent(Cookies.get(this.config.key)) );
data = JSON.parse(Cookies.get(this.config.key));
}
if (str) {
return ('undefined' !== typeof data[str]) ? data[str] : null;
return (typeof data[str] !== 'undefined') ? data[str] : null;
}
else {
return data;
@ -33,19 +35,23 @@ cookie.prototype.get = function(str){
cookie.prototype.set = function(str, value){
if (!arguments.length || !this.enabled()) return this;
if ('string' === typeof str && arguments.length === 2) {
if (typeof str === 'string' && arguments.length === 2) {
this.data[str] = value ? value : null;
}
else if ('object' === typeof str && arguments.length === 1) {
else if (typeof str === 'object' && arguments.length === 1) {
extend(this.data, str);
}
Cookies.set(this.config.key, encodeURIComponent( JSON.stringify(this.data) ), this.config.options);
Cookies.set(this.config.key, this.data, this.config.options);
return this;
};
cookie.prototype.expire = function(){
Cookies.expire(this.config.key);
this.data = {};
cookie.prototype.expire = function(daysUntilExpire){
if (daysUntilExpire) {
Cookies.set(this.config.key, this.data, extend(this.config.options, { expires: daysUntilExpire }));
} else {
Cookies.remove(this.config.key);
this.data = {};
}
return this;
};
@ -56,5 +62,5 @@ cookie.prototype.options = function(obj){
};
cookie.prototype.enabled = function(){
return Cookies.enabled;
return navigator.cookieEnabled;
};

4
package.json

@ -1,6 +1,6 @@
{
"name": "keen-tracking",
"version": "0.1.1",
"version": "1.0.0",
"description": "Data Collection SDK for Keen IO",
"main": "lib/server.js",
"browser": "lib/browser.js",
@ -26,7 +26,7 @@
},
"dependencies": {
"component-emitter": "^1.2.0",
"cookies-js": "^1.2.1",
"js-cookie": "2.1.0",
"keen-core": "0.0.2"
},
"devDependencies": {

Loading…
Cancel
Save