Skip to content
This repository was archived by the owner on Aug 14, 2019. It is now read-only.

Commit 36879a9

Browse files
authored
[PLATFORM-2311] Add "position" to product data (#76)
* Track field position * Release commit
1 parent 0b185fc commit 36879a9

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

HISTORY.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.14.0 / 2018-03-28
2+
=================
3+
4+
* Support position property as part of product data.
5+
16
2.13.0 / 2018-02-26
27
=================
38

lib/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,12 @@ function enhancedEcommerceTrackProduct(track, trackerName, opts) {
10301030
currency: track.currency()
10311031
};
10321032

1033+
// https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-data
1034+
// GA requires an integer but our specs says "Number", so it could be a float.
1035+
if (props.position != null) {
1036+
product.position = Math.round(props.position);
1037+
}
1038+
10331039
// append coupon if it set
10341040
// https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#measuring-transactions
10351041
var coupon = track.proxy('properties.coupon');

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-google-analytics",
33
"description": "The Google Analytics analytics.js integration.",
4-
"version": "2.13.0",
4+
"version": "2.14.0",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

test/index.test.js

+44-2
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,8 @@ describe('Google Analytics', function() {
891891
category: 'cat 1',
892892
sku: 'p-298',
893893
testDimension: true,
894-
testMetric: true
894+
testMetric: true,
895+
position: 4
895896
});
896897

897898
analytics.assert(window.ga.args.length === 5);
@@ -906,7 +907,48 @@ describe('Google Analytics', function() {
906907
variant: undefined,
907908
currency: 'CAD',
908909
metric1: 'true',
909-
dimension1: 'true'
910+
dimension1: 'true',
911+
position: 4
912+
}]);
913+
analytics.deepEqual(toArray(window.ga.args[3]), ['ec:setAction', 'add', {}]);
914+
analytics.deepEqual(toArray(window.ga.args[4]), ['send', 'event', 'cat 1', 'product added', {
915+
dimension1: 'true',
916+
metric1: 'true',
917+
nonInteraction: 1
918+
}]);
919+
});
920+
921+
it('should handle float positions for product data', function() {
922+
ga.options.setAllMappedProps = false;
923+
ga.options.dimensions = { testDimension: 'dimension1' };
924+
ga.options.metrics = { testMetric: 'metric1' };
925+
926+
analytics.track('product added', {
927+
currency: 'CAD',
928+
quantity: 1,
929+
price: 24.75,
930+
name: 'my product',
931+
category: 'cat 1',
932+
sku: 'p-298',
933+
testDimension: true,
934+
testMetric: true,
935+
position: 4.5
936+
});
937+
938+
analytics.assert(window.ga.args.length === 5);
939+
analytics.deepEqual(toArray(window.ga.args[1]), ['set', '&cu', 'CAD']);
940+
analytics.deepEqual(toArray(window.ga.args[2]), ['ec:addProduct', {
941+
id: 'p-298',
942+
name: 'my product',
943+
category: 'cat 1',
944+
quantity: 1,
945+
price: 24.75,
946+
brand: undefined,
947+
variant: undefined,
948+
currency: 'CAD',
949+
metric1: 'true',
950+
dimension1: 'true',
951+
position: 5
910952
}]);
911953
analytics.deepEqual(toArray(window.ga.args[3]), ['ec:setAction', 'add', {}]);
912954
analytics.deepEqual(toArray(window.ga.args[4]), ['send', 'event', 'cat 1', 'product added', {

0 commit comments

Comments
 (0)