Socket
Socket
Sign inDemoInstall

@segment/analytics.js-core

Package Overview
Dependencies
Maintainers
110
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@segment/analytics.js-core - npm Package Compare versions

Comparing version 3.8.1 to 3.8.2

9

lib/entity.js

@@ -147,3 +147,6 @@ 'use strict';

Entity.prototype._getIdFromLocalStorage = function() {
return store.get(this._options.cookie.key);
if (!this._options.localStorageFallbackDisabled) {
return store.get(this._options.cookie.key);
}
return null;
};

@@ -183,3 +186,5 @@

Entity.prototype._setIdInLocalStorage = function(id) {
store.set(this._options.cookie.key, id);
if (!this._options.localStorageFallbackDisabled) {
store.set(this._options.cookie.key, id);
}
};

@@ -186,0 +191,0 @@

@@ -103,3 +103,3 @@ 'use strict';

store.set('ajs_anonymous_id', anonymousId);
localStorage.set('ajs_anonymous_id', anonymousId);
this._setAnonymousIdInLocalStorage(anonymousId);
return this;

@@ -111,4 +111,4 @@ }

if (anonymousId) {
// value exist in cookie, copy it to localStorage
localStorage.set('ajs_anonymous_id', anonymousId);
// value exists in cookie, copy it to localStorage
this._setAnonymousIdInLocalStorage(anonymousId);
// refresh cookie to extend expiry

@@ -119,8 +119,10 @@ store.set('ajs_anonymous_id', anonymousId);

// if anonymousId doesn't exist in cookies, check localStorage
anonymousId = localStorage.get('ajs_anonymous_id');
if (anonymousId) {
// Write to cookies if available in localStorage but not cookies
store.set('ajs_anonymous_id', anonymousId);
return anonymousId;
if (!this._options.localStorageFallbackDisabled) {
// if anonymousId doesn't exist in cookies, check localStorage
anonymousId = localStorage.get('ajs_anonymous_id');
if (anonymousId) {
// Write to cookies if available in localStorage but not cookies
store.set('ajs_anonymous_id', anonymousId);
return anonymousId;
}
}

@@ -133,3 +135,3 @@

store.set('ajs_anonymous_id', anonymousId);
localStorage.set('ajs_anonymous_id', anonymousId);
this._setAnonymousIdInLocalStorage(anonymousId);
store.remove('_sio');

@@ -142,3 +144,3 @@ return anonymousId;

store.set('ajs_anonymous_id', anonymousId);
localStorage.set('ajs_anonymous_id', anonymousId);
this._setAnonymousIdInLocalStorage(anonymousId);
return store.get('ajs_anonymous_id');

@@ -148,2 +150,14 @@ };

/**
* Set the user's `anonymousid` in local storage.
*
* @param {String} id
*/
User.prototype._setAnonymousIdInLocalStorage = function(id) {
if (!this._options.localStorageFallbackDisabled) {
localStorage.set('ajs_anonymous_id', id);
}
};
/**
* Remove anonymous id on logout too.

@@ -150,0 +164,0 @@ */

{
"name": "@segment/analytics.js-core",
"author": "Segment <friends@segment.com>",
"version": "3.8.1",
"version": "3.8.2",
"description": "The hassle-free way to integrate analytics into any web application.",

@@ -6,0 +6,0 @@ "keywords": [

@@ -60,2 +60,20 @@ 'use strict';

});
it('id() should not fallback to localStorage when localStorage fallback is disabled', function() {
var group = new Group();
group.options({
localStorageFallbackDisabled: true
});
group.id('gid');
// delete the cookie.
cookie.remove(cookieKey);
// verify cookie is deleted.
assert.equal(cookie.get(cookieKey), null);
// verify id() does not return the id when cookie is deleted.
assert.equal(group.id(), null);
});
});

@@ -254,2 +272,12 @@

it('should not save an id to localStorage when localStorage fallback is disabled', function() {
group.options({
localStorageFallbackDisabled: true
});
group.id('id');
group.save();
assert.equal(store.get(cookieKey), null);
});
it('should save properties to local storage', function() {

@@ -256,0 +284,0 @@ group.properties({ property: true });

@@ -60,6 +60,24 @@ 'use strict';

// verify cookie value is retored from localStorage.
// verify cookie value is restored from localStorage.
assert.equal(cookie.get(cookieKey), 'id');
});
it('id() should not fallback to localStorage when disabled', function() {
var user = new User();
user.options({
localStorageFallbackDisabled: true
});
user.id('id');
// delete the cookie.
cookie.remove(cookieKey);
// verify cookie is deleted.
assert.equal(cookie.get(cookieKey), null);
// verify id() does not return the id when cookie is deleted.
assert.equal(user.id(), null);
});
it('should pick the old "_sio" anonymousId', function() {

@@ -349,2 +367,12 @@ rawCookie('_sio', 'anonymous-id----user-id');

it('should not set anonymousId in localStorage when localStorage fallback is disabled', function() {
var user = new User();
user.options({
localStorageFallbackDisabled: true
});
user.anonymousId('anon0');
assert.equal(cookie.get('ajs_anonymous_id'), 'anon0');
assert.equal(store.get('ajs_anonymous_id'), null);
});
it('should copy value from cookie to localStorage', function() {

@@ -357,2 +385,12 @@ var user = new User();

it('should not copy value from cookie to localStorage when localStorage fallback is disabled', function() {
var user = new User();
user.options({
localStorageFallbackDisabled: true
});
cookie.set('ajs_anonymous_id', 'anon1');
assert.equal(user.anonymousId(), 'anon1');
assert.equal(store.get('ajs_anonymous_id'), null);
});
it('should fall back to localStorage when cookie is not set', function() {

@@ -371,6 +409,23 @@ var user = new User();

// verify cookie value is retored from localStorage
// verify cookie value is restored from localStorage
assert.equal(cookie.get('ajs_anonymous_id'), 'anon12');
});
it('should not fall back to localStorage when cookie is not set and localStorage fallback is disabled', function() {
var user = new User();
user.options({
localStorageFallbackDisabled: true
});
user.anonymousId('anon12');
assert.equal(cookie.get('ajs_anonymous_id'), 'anon12');
// delete the cookie
cookie.remove('ajs_anonymous_id');
assert.equal(cookie.get('ajs_anonymous_id'), null);
// verify anonymousId() does not return the id when there's no cookie.
assert.notEqual(user.anonymousId(), 'anon12');
});
it('should write to both cookie and localStorage when generating a new anonymousId', function() {

@@ -383,2 +438,15 @@ var user = new User();

});
it('should not write to both cookie and localStorage when generating a new anonymousId and localStorage fallback is disabled', function() {
var user = new User();
user.options({
localStorageFallbackDisabled: true
});
var anonId = user.anonymousId();
assert.notEqual(anonId, null);
assert.equal(cookie.get('ajs_anonymous_id'), anonId);
assert.equal(store.get('ajs_anonymous_id'), null);
});
});

@@ -471,2 +539,13 @@ });

it('should not save an id to localStorage when localStorage fallback is disabled', function() {
user.options({
localStorageFallbackDisabled: true
});
user.id('id');
user.save();
assert.equal(store.get(cookieKey), null);
});
it('should save traits to local storage', function() {

@@ -473,0 +552,0 @@ user.traits({ trait: true });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc