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
131
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 3.2.0 to 3.3.0

LICENSE

5

HISTORY.md

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

# 3.3.0 / 2019-10-09
- Add support for versionName setting, this will allow user to specify version.
- Add support for trackProductsOnce setting, this will track all products at once.
# 3.2.0 / 2019-08-27

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

36

lib/index.js

@@ -54,2 +54,4 @@ 'use strict';

.option('unsetParamsReferrerOnNewSession', false)
.option('trackProductsOnce', false)
.option('versionName', '')
.tag('<script src="' + src + '">'));

@@ -93,2 +95,9 @@

// Initialize the amplitute with user specified site version if any.
// https://help.amplitude.com/hc/en-us/articles/115001361248-JavaScript-SDK-Installation#setting-version-name
var versionName = this.options.versionName;
if (versionName) {
window.amplitude.getInstance().setVersionName(versionName);
}
var loaded = bind(this, this.loaded);

@@ -291,4 +300,16 @@ var ready = this.ready;

var revenue = track.revenue();
var trackProductsOnce = this.options.trackProductsOnce;
// Amplitude does not allow arrays of objects to as properties of events.
if (trackProductsOnce) {
var allProducts = [];
// products is object
var productKeys = Object.keys(products);
for (var index = 0; index < productKeys.length; index++) {
var eachProduct = new Track({ properties: products[index] });
allProducts.push(mapProductAttributes(eachProduct));
}
clonedTrack.properties.products = allProducts;
logEvent.call(this, new Track(clonedTrack), trackRevenuePerProduct);
return;
}
// Our Order Completed event however uses a products array for product level tracking.

@@ -470,1 +491,14 @@ // We need to remove this before logging the event and then use it to track revenue.

}
// map product for Order Completed event
// REF: https://segment.com/docs/destinations/amplitude/#order-completed
function mapProductAttributes(product) {
return {
productId: product.productId(),
sku: product.sku(),
name: product.name(),
price: product.price(),
quantity: product.quantity(),
category: product.category()
};
}

5

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

@@ -52,3 +52,4 @@ "analytics.js",

"watchify": "^3.11.1"
}
},
"gitHead": "8df7c32bed588a51ec2e1e3e0b726f0ed50be0d7"
}

@@ -30,3 +30,4 @@ 'use strict';

preferAnonymousIdForDeviceId: true,
unsetParamsReferrerOnNewSession: false
unsetParamsReferrerOnNewSession: false,
versionName: '4.6.0'
};

@@ -119,2 +120,3 @@

var config = window.amplitude.getInstance().options;
analytics.assert(config.includeUtm === options.trackUtmProperties);

@@ -143,2 +145,3 @@ analytics.assert(config.includeReferrer === options.trackReferrer);

);
analytics.assert(config.versionName === options.versionName);
});

@@ -152,2 +155,17 @@

describe('Initialize amplitude without versionName', function() {
before(function() {
delete options.versionName;
});
it('should init without versionName', function() {
var config = window.amplitude.getInstance().options;
analytics.assert(config.versionName === undefined);
});
after(function() {
options.versionName = '4.6.0';
});
});
describe('preferAnonymousIdForDeviceId disabled', function() {

@@ -765,2 +783,49 @@ before(function() {

});
it('should call logEvent once if `trackProductsOnce` is set', function() {
var spy = sinon.spy(window.amplitude.getInstance(), 'logEvent');
amplitude.options.trackProductsOnce = true;
analytics.track('Order Completed', payload);
analytics.assert(spy.calledOnce);
});
it('should track all product at once once if `trackProductsOnce` is set', function() {
analytics.stub(window.amplitude.getInstance(), 'logEvent');
amplitude.options.trackProductsOnce = true;
analytics.track('Order Completed', payload);
analytics.called(
window.amplitude.getInstance().logEvent,
'Order Completed',
{
checkoutId: 'fksdjfsdjfisjf9sdfjsd9f',
orderId: '50314b8e9bcf000000000000',
affiliation: 'Google Store',
total: 30,
revenue: 25,
shipping: 3,
tax: 2,
discount: 2.5,
coupon: 'hasbros',
currency: 'USD',
products: [
{
productId: '507f1f77bcf86cd799439011',
sku: '45790-32',
name: 'Monopoly: 3rd Edition',
price: 19,
quantity: 1,
category: 'Games'
},
{
productId: '505bd76785ebb509fc183733',
sku: '46493-32',
name: 'Uno Card Game',
price: 3,
quantity: 2,
category: 'Games'
}
]
}
);
});
});

@@ -767,0 +832,0 @@

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