Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@segment/analytics.js-integration-amplitude

Package Overview
Dependencies
Maintainers
63
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@segment/analytics.js-integration-amplitude - npm Package Compare versions

Comparing version 2.6.0 to 2.7.0

5

HISTORY.md

@@ -0,1 +1,6 @@

2.7.0 / 2018-02-12
==================
* anonymousID-as-deviceID + group{Type, Value}Trait support (#38)
2.6.0 / 2017-09-18

@@ -2,0 +7,0 @@ ==================

40

lib/index.js

@@ -49,2 +49,3 @@ 'use strict';

.option('trackRevenuePerProduct', false)
.option('preferAnonymousIdForDeviceId', false)
.tag('<script src="' + src + '">');

@@ -120,2 +121,4 @@

Amplitude.prototype.page = function(page) {
this.setDeviceIdFromAnonymousId(page);
var category = page.category();

@@ -149,2 +152,4 @@ var name = page.fullName();

Amplitude.prototype.identify = function(identify) {
this.setDeviceIdFromAnonymousId(identify);
var id = identify.userId();

@@ -187,2 +192,4 @@ var traits = identify.traits();

function logEvent(track, dontSetRevenue) {
this.setDeviceIdFromAnonymousId(track);
var props = track.properties();

@@ -222,2 +229,4 @@ var options = track.options(this.name);

Amplitude.prototype.orderCompleted = function(track) {
this.setDeviceIdFromAnonymousId(track);
var products = track.products();

@@ -263,4 +272,14 @@ var clonedTrack = track.json();

Amplitude.prototype.group = function(group) {
var groupId = group.groupId();
if (groupId) window.amplitude.setGroup('[Segment] Group', groupId);
this.setDeviceIdFromAnonymousId(group);
var groupType = group.traits()[this.options.groupTypeTrait];
var groupValue = group.traits()[this.options.groupValueTrait];
if (groupType && groupValue) {
window.amplitude.setGroup(groupType, groupValue);
} else {
var groupId = group.groupId();
if (groupId) {
window.amplitude.setGroup('[Segment] Group', groupId);
}
}
};

@@ -281,2 +300,18 @@

/**
* If enabled by settings, set the device ID from the Segment anonymous ID.
*
* This logic cannot be performed at initialization time, because customers may
* want to modify anonymous IDs between initializing Segment and sending their
* first event.
*
* @api private
* @param {Fadade} facade to get anonymousId from.
*/
Amplitude.prototype.setDeviceIdFromAnonymousId = function(facade) {
if (this.options.preferAnonymousIdForDeviceId) {
this.setDeviceId(facade.anonymousId());
}
};
/**
* Override device ID in Amplitude.

@@ -292,3 +327,2 @@ *

Amplitude.prototype.setRevenue = function(properties) {

@@ -295,0 +329,0 @@ var price = properties.price;

2

package.json
{
"name": "@segment/analytics.js-integration-amplitude",
"description": "The Amplitude analytics.js integration.",
"version": "2.6.0",
"version": "2.7.0",
"keywords": [

@@ -6,0 +6,0 @@ "analytics.js",

@@ -150,2 +150,3 @@ 'use strict';

analytics.stub(window.amplitude, 'setUserProperties');
analytics.stub(window.amplitude, 'setDeviceId');
});

@@ -206,2 +207,13 @@

});
it('should set deviceId if `preferAnonymousIdForDeviceId` is set', function() {
analytics.user().anonymousId('example');
amplitude.options.preferAnonymousIdForDeviceId = false;
analytics.identify('id');
analytics.didNotCall(window.amplitude.setDeviceId);
amplitude.options.preferAnonymousIdForDeviceId = true;
analytics.identify('id');
analytics.called(window.amplitude.setDeviceId, 'example');
});
});

@@ -214,2 +226,3 @@

analytics.stub(window.amplitude, 'setGroup');
analytics.stub(window.amplitude, 'setDeviceId');
});

@@ -244,2 +257,13 @@

});
it('should set deviceId if `preferAnonymousIdForDeviceId` is set', function() {
analytics.user().anonymousId('example');
amplitude.options.preferAnonymousIdForDeviceId = false;
analytics.identify('id');
analytics.didNotCall(window.amplitude.setDeviceId);
amplitude.options.preferAnonymousIdForDeviceId = true;
analytics.identify('id');
analytics.called(window.amplitude.setDeviceId, 'example');
});
});

@@ -254,2 +278,3 @@

analytics.stub(window.amplitude, 'logEventWithGroups');
analytics.stub(window.amplitude, 'setDeviceId');
});

@@ -341,5 +366,20 @@

});
it('should set deviceId if `preferAnonymousIdForDeviceId` is set', function() {
analytics.user().anonymousId('example');
amplitude.options.preferAnonymousIdForDeviceId = false;
analytics.page();
analytics.didNotCall(window.amplitude.setDeviceId);
amplitude.options.preferAnonymousIdForDeviceId = true;
analytics.page();
analytics.called(window.amplitude.setDeviceId, 'example');
});
});
describe('#orderCompleted', function() {
beforeEach(function() {
analytics.stub(window.amplitude, 'setDeviceId');
});
var payload;

@@ -396,2 +436,13 @@ beforeEach(function() {

});
it('should set deviceId if `preferAnonymousIdForDeviceId` is set', function() {
analytics.user().anonymousId('example');
amplitude.options.preferAnonymousIdForDeviceId = false;
analytics.track('Order Completed');
analytics.didNotCall(window.amplitude.setDeviceId);
amplitude.options.preferAnonymousIdForDeviceId = true;
analytics.track('Order Completed');
analytics.called(window.amplitude.setDeviceId, 'example');
});
});

@@ -402,2 +453,3 @@

analytics.stub(window.amplitude, 'setGroup');
analytics.stub(window.amplitude, 'setDeviceId');
});

@@ -409,4 +461,29 @@

});
it('should use `groupTypeTrait` and `groupValueTrait` when both are present', function() {
amplitude.options.groupTypeTrait = 'foo';
amplitude.options.groupValueTrait = 'bar';
analytics.group('testGroupId', { foo: 'asdf', bar: 'fafa' });
analytics.called(window.amplitude.setGroup, 'asdf', 'fafa');
});
it('should fall back to default behavior if either `group{Type, Value}Trait` is missing', function() {
amplitude.options.groupTypeTrait = 'foo';
amplitude.options.groupValueTrait = 'bar';
analytics.group('testGroupId', { notFoo: 'asdf', bar: 'fafa' });
analytics.called(window.amplitude.setGroup, '[Segment] Group', 'testGroupId');
});
it('should set deviceId if `preferAnonymousIdForDeviceId` is set', function() {
analytics.user().anonymousId('example');
amplitude.options.preferAnonymousIdForDeviceId = false;
analytics.group('group');
analytics.didNotCall(window.amplitude.setDeviceId);
amplitude.options.preferAnonymousIdForDeviceId = true;
analytics.group('group');
analytics.called(window.amplitude.setDeviceId, 'example');
});
});
});
});
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