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

Commit 93671ef

Browse files
authored
Update mapper and tests (#82)
1 parent 63abd51 commit 93671ef

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lib/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ GA.prototype.productListViewedEnhanced = function(track) {
940940
var opts = this.options;
941941

942942
this.loadEnhancedEcommerce(track);
943+
943944
each(products, function(product) {
944945
// If we don't have an ID/SKU or name, return - GA will reject the impression.
945946
var item = new Track({ properties: product });
@@ -955,6 +956,8 @@ GA.prototype.productListViewedEnhanced = function(track) {
955956
position: products.map(function(x) { return x.product_id; }).indexOf(item.productId()) + 1
956957
};
957958

959+
impressionObj = extend(impressionObj, metrics(item.properties(), opts));
960+
958961
for (var prop in impressionObj) {
959962
if (impressionObj[prop] === undefined) delete impressionObj[prop];
960963
}
@@ -998,6 +1001,9 @@ GA.prototype.productListFilteredEnhanced = function(track) {
9981001
price: item.price(),
9991002
position: products.map(function(x) { return x.product_id; }).indexOf(item.productId()) + 1
10001003
};
1004+
1005+
impressionObj = extend(impressionObj, metrics(item.properties(), opts));
1006+
10011007
for (var prop in impressionObj) {
10021008
if (impressionObj[prop] === undefined) delete impressionObj[prop];
10031009
}

test/index.test.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -1087,14 +1087,14 @@ describe('Google Analytics', function() {
10871087
it('should send product impression data via product list viewed', function() {
10881088
// If using addImpression ever becomes optional, will need to add a setting modification here.
10891089
ga.options.setAllMappedProps = false;
1090-
ga.options.dimensions = { testDimension: 'dimension1' };
1091-
ga.options.metrics = { testMetric: 'metric1' };
1090+
ga.options.dimensions = { testDimension: 'dimension1', productDimension: 'dimension2' };
1091+
ga.options.metrics = { testMetric: 'metric1', productMetric: 'metric2' };
10921092

10931093
analytics.track('Product List Viewed', {
10941094
category: 'cat 1',
10951095
list_id: '1234',
10961096
products: [
1097-
{ product_id: '507f1f77bcf86cd799439011' }
1097+
{ product_id: '507f1f77bcf86cd799439011', productDimension: 'My Product Dimension', productMetric: 'My Product Metric' }
10981098
],
10991099
testDimension: true,
11001100
testMetric: true
@@ -1105,7 +1105,9 @@ describe('Google Analytics', function() {
11051105
id: '507f1f77bcf86cd799439011',
11061106
category: 'cat 1',
11071107
list: '1234',
1108-
position: 1
1108+
position: 1,
1109+
dimension2: 'My Product Dimension',
1110+
metric2: 'My Product Metric'
11091111
}]);
11101112
analytics.deepEqual(toArray(window.ga.args[3]), ['send', 'event', 'cat 1', 'Product List Viewed', {
11111113
dimension1: 'true',
@@ -1117,8 +1119,8 @@ describe('Google Analytics', function() {
11171119
it('should send product impression data via product list filtered', function() {
11181120
// If using addImpression ever becomes optional, will need to add a setting modification here.
11191121
ga.options.setAllMappedProps = false;
1120-
ga.options.dimensions = { testDimension: 'dimension1' };
1121-
ga.options.metrics = { testMetric: 'metric1' };
1122+
ga.options.dimensions = { testDimension: 'dimension1', productDimension: 'dimension2' };
1123+
ga.options.metrics = { testMetric: 'metric1', productMetric: 'metric2' };
11221124

11231125
analytics.track('Product List Filtered', {
11241126
category: 'cat 1',
@@ -1136,7 +1138,7 @@ describe('Google Analytics', function() {
11361138
value: 'desc'
11371139
}],
11381140
products: [
1139-
{ product_id: '507f1f77bcf86cd799439011' }
1141+
{ product_id: '507f1f77bcf86cd799439011', productDimension: 'My Product Dimension', productMetric: 'My Product Metric' }
11401142
],
11411143
testDimension: true,
11421144
testMetric: true
@@ -1148,7 +1150,9 @@ describe('Google Analytics', function() {
11481150
category: 'cat 1',
11491151
list: '1234',
11501152
position: 1,
1151-
variant: 'department:beauty,price:under::price:desc'
1153+
variant: 'department:beauty,price:under::price:desc',
1154+
dimension2: 'My Product Dimension',
1155+
metric2: 'My Product Metric'
11521156
}]);
11531157
analytics.deepEqual(toArray(window.ga.args[3]), ['send', 'event', 'cat 1', 'Product List Filtered', {
11541158
dimension1: 'true',

0 commit comments

Comments
 (0)