Skip to content

Commit

Permalink
Merge pull request #82 from driveback/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ConstantineYurevich authored Jan 28, 2017
2 parents f038bc2 + 93b38e8 commit 465a06c
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 313 deletions.
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
driveback_cdn:
image: kyma/docker-nginx:latest
volumes:
- ./build:/var/www
ports:
- 80
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "digital-data-manager",
"description": "The hassle-free way to integrate Digital Data Layer on your website.",
"author": "Driveback LLC <[email protected]>",
"version": "1.2.10",
"version": "1.2.11",
"license": "MIT",
"main": "dist/dd-manager.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/ddManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function _initializeIntegrations(settings) {

ddManager = {

VERSION: '1.2.10',
VERSION: '1.2.11',

setAvailableIntegrations: (availableIntegrations) => {
_availableIntegrations = availableIntegrations;
Expand Down
41 changes: 25 additions & 16 deletions src/integrations/Criteo.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Criteo extends Integration {
const optionsWithDefaults = Object.assign({
account: '',
noConflict: false,
customDeduplication: false,
userSegmentVar: undefined,
}, options);

Expand Down Expand Up @@ -268,24 +269,32 @@ class Criteo extends Integration {
if (transaction && transaction.lineItems && transaction.lineItems.length > 0) {
const products = lineItemsToCriteoItems(transaction.lineItems);
if (products.length > 0) {
let deduplication = 0;
const context = event.context;
if (
context
&& context.campaign
&& context.campaign.source
&& context.campaign.source.toLocaleLowerCase().indexOf('criteo') >= 0
) {
deduplication = 1;
let customDeduplication = this.getOption('customDeduplication');
let deduplication;

const criteoEvent = {
event: 'trackTransaction',
id: transaction.orderId,
new_customer: (transaction.isFirst) ? 1 : 0,
item: products,
};

if (customDeduplication) {
const context = event.context;
if (
context
&& context.campaign
&& context.campaign.source
&& context.campaign.source.toLocaleLowerCase().indexOf('criteo') >= 0
) {
criteoEvent.deduplication = 1;
} else {
criteoEvent.deduplication = 0;
}
}

this.pushCriteoQueue(
{
event: 'trackTransaction',
id: transaction.orderId,
new_customer: (transaction.isFirst) ? 1 : 0,
deduplication: deduplication,
item: products,
},
criteoEvent,
this.getUserSegment(event)
);
}
Expand Down
67 changes: 23 additions & 44 deletions src/integrations/RetailRocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import Integration from './../Integration.js';
import deleteProperty from './../functions/deleteProperty';
import { getProp } from './../functions/dotProp';
import getVarValue from './../functions/getVarValue';
import throwError from './../functions/throwError';
import each from './../functions/each';
import type from 'component-type';
import format from './../functions/format';

class RetailRocket extends Integration {

Expand Down Expand Up @@ -157,56 +155,51 @@ class RetailRocket extends Integration {
listing = listing || {};
const categoryId = listing.categoryId;
if (!categoryId) {
this.onValidationError('listing.categoryId');
return;
}
window.rrApiOnReady.push(() => {
try {
window.rrApi.categoryView(categoryId);
} catch (e) {
this.onError(e);
// do nothing
}
});
}

onViewedProductDetail(product) {
const productId = this.getProductId(product);
if (!productId) {
this.onValidationError('product.id');
return;
}
window.rrApiOnReady.push(() => {
try {
window.rrApi.view(productId);
} catch (e) {
this.onError(e);
// do nothing
}
});
}

onAddedProduct(product) {
const productId = this.getProductId(product);
if (!productId) {
this.onValidationError('product.id');
return;
}
window.rrApiOnReady.push(() => {
try {
window.rrApi.addToBasket(productId);
} catch (e) {
this.onError(e);
// do nothing
}
});
}

onClickedProduct(listItem) {
if (!listItem) {
this.onValidationError('listItem.product.id');
return;
}
const productId = this.getProductId(listItem.product);
if (!productId) {
this.onValidationError('listItem.product.id');
return;
}
const listId = listItem.listId;
Expand All @@ -221,7 +214,7 @@ class RetailRocket extends Integration {
try {
window.rrApi.recomMouseDown(productId, methodName);
} catch (e) {
this.onError(e);
// do nothing
}
});
}
Expand All @@ -232,36 +225,42 @@ class RetailRocket extends Integration {
return;
}

let areLineItemsValid = true;
const items = [];
const lineItems = transaction.lineItems;
for (let i = 0, length = lineItems.length; i < length; i++) {
if (!this.validateTransactionLineItem(lineItems[i], i)) {
continue;
if (!this.validateTransactionLineItem(lineItems[i])) {
areLineItemsValid = false;
break;
}
const product = lineItems[i].product;
this.overrideProduct(product);
items.push({
id: product.id,
qnt: lineItems[i].quantity,
price: product.unitSalePrice || product.unitPrice,
});
}

if (!areLineItemsValid) {
return;
}

window.rrApiOnReady.push(() => {
try {
window.rrApi.order({
transaction: transaction.orderId,
items: items,
});
} catch (e) {
this.onError(e);
// do nothing
}
});
}

onSubscribed(event) {
const user = event.user || {};
if (!user.email) {
this.onValidationError('user.email');
return;
}

Expand All @@ -284,66 +283,60 @@ class RetailRocket extends Integration {
try {
window.rrApi.setEmail(user.email, rrCustoms);
} catch (e) {
this.onError(e);
// do nothing
}
});
}

onSearched(listing) {
listing = listing || {};
if (!listing.query) {
this.onValidationError('listing.query');
return;
}
window.rrApiOnReady.push(() => {
try {
window.rrApi.search(listing.query);
} catch (e) {
this.onError(e);
// do nothing
}
});
}

validateTransaction(transaction) {
let isValid = true;
if (!transaction.orderId) {
this.onValidationError('transaction.orderId');
isValid = false;
}

const lineItems = transaction.lineItems;
if (!lineItems || !Array.isArray(lineItems) || lineItems.length === 0) {
this.onValidationError('transaction.lineItems');
isValid = false;
}

return isValid;
}

validateLineItem(lineItem, index) {
validateLineItem(lineItem) {
let isValid = true;
if (!lineItem.product) {
this.onValidationError(format('lineItems[%d].product', index));
isValid = false;
}

return isValid;
}

validateTransactionLineItem(lineItem, index) {
let isValid = this.validateLineItem(lineItem, index);
validateTransactionLineItem(lineItem) {
let isValid = this.validateLineItem(lineItem);

const product = lineItem.product;
this.overrideProduct(product);
if (!product.id) {
this.onValidationError(format('lineItems[%d].product.id', index));
isValid = false;
}
if (!product.unitSalePrice && !product.unitPrice) {
this.onValidationError(format('lineItems[%d].product.unitSalePrice', index));
isValid = false;
}
if (!lineItem.quantity) {
this.onValidationError(format('lineItems[%d].quantity', index));
isValid = false;
}

Expand All @@ -352,24 +345,10 @@ class RetailRocket extends Integration {

getProductId(product) {
product = product || {};
let productId;
if (type(product) === 'object') {
productId = product.id;
} else {
productId = product;
}
return productId;
}
this.overrideProduct(product);
const productId = product.id;

onError(err) {
throwError('external_error', format('Retail Rocket integration error: "%s"', err));
}

onValidationError(variableName) {
throwError(
'validation_error',
format('Retail Rocket integration error: DDL or event variable "%s" is not defined or empty', variableName)
);
return productId;
}
}

Expand Down
8 changes: 3 additions & 5 deletions test/integrations/CriteoSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,6 @@ describe('Integrations: Criteo', () => {
event: 'trackTransaction',
id: '123',
new_customer: 1,
deduplication: 0,
item: [
{ id: '123', price: 100, quantity: 1 },
{ id: '234', price: 50, quantity: 2 },
Expand All @@ -886,7 +885,6 @@ describe('Integrations: Criteo', () => {
event: 'trackTransaction',
id: '123',
new_customer: 1,
deduplication: 0,
item: [
{ id: '123', price: 100, quantity: 1 },
{ id: '234', price: 50, quantity: 2 },
Expand All @@ -912,7 +910,6 @@ describe('Integrations: Criteo', () => {
event: 'trackTransaction',
id: '123',
new_customer: 0,
deduplication: 0,
item: [
{ id: '123', price: 100, quantity: 1 },
{ id: '234', price: 50, quantity: 2 },
Expand All @@ -926,6 +923,7 @@ describe('Integrations: Criteo', () => {
});

it('should send trackTransaction event if transaction is completed (deduplication = 1)', (done) => {
criteo.setOption('customDeduplication', true);
window.digitalData.events.push({
name: 'Completed Transaction',
context: {
Expand Down Expand Up @@ -956,7 +954,7 @@ describe('Integrations: Criteo', () => {
});

it('should send trackTransaction event if transaction is completed (deduplication = 0)', (done) => {
criteo.setOption('deduplication', false);
criteo.setOption('customDeduplication', false);
window.digitalData.context = {
campaign: {
name: 'CriTeO'
Expand All @@ -973,12 +971,12 @@ describe('Integrations: Criteo', () => {
event: 'trackTransaction',
id: '123',
new_customer: 0,
deduplication: 0,
item: [
{ id: '123', price: 100, quantity: 1 },
{ id: '234', price: 50, quantity: 2 },
{ id: '345', price: 30, quantity: 1 },
{ id: '456', price: 0, quantity: 1 }

]
});
done();
Expand Down
Loading

0 comments on commit 465a06c

Please sign in to comment.