Skip to content

Commit

Permalink
Merge branch 'agriess-feature/ARGO-1096'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemanja Popovic committed Aug 26, 2016
2 parents 65e19a4 + 9a59b90 commit 7d83d60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
9 changes: 7 additions & 2 deletions public/js/app/shared/directives/y-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ angular.module('ds.ytracking', [])
*/
var cartUpdated = function (cart) {
var i = 0;

//Check if there is some item that is removed in new cart??
if (!!internalCart.items) {
if (!!cart.items) {
Expand Down Expand Up @@ -366,6 +365,8 @@ angular.module('ds.ytracking', [])
}

//Records the cart for this visit
var cartId = getCartId(cart);
$window._paq.push(['setCustomVariable', 1, 'cart_id', cartId, 'page']);
$window._paq.push(['trackEcommerceCartUpdate', !!cart.totalPrice ? cart.totalPrice.amount : 0]); // (required) Cart amount

//Save previous state for later comparasion (checking if objects are removed from cart)
Expand Down Expand Up @@ -395,7 +396,7 @@ angular.module('ds.ytracking', [])
$timeout(function () {
setCustomUrl();

var cartId = !!cart.id ? cart.id : '';
var cartId = getCartId(cart);
$window._paq.push(['setCustomVariable', 1, 'cart_id', cartId, 'page']);
$window._paq.push(['trackLink', 'ProceedToCheckoutEvent', 'action_name']);
});
Expand Down Expand Up @@ -426,6 +427,10 @@ angular.module('ds.ytracking', [])
$window._paq.push(['trackPageView', 'CustomerLogin']);
}
};

var getCartId = function(cart) {
return !!cart.id ? cart.id : '';
};

return {
cartUpdated: cartUpdated,
Expand Down
18 changes: 11 additions & 7 deletions test/unit/shared/y-tracking-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('ytracking', function () {

var order = {
cart: {
id : 123,
items: [{
product: {
id: '02318421',
Expand Down Expand Up @@ -289,11 +290,6 @@ describe('ytracking', function () {
expect(lengthAfter > lengthBefore).toBeTruthy();
});






/*Cart updated*/
it('should call cartUpdated when user added/removed something from cart', function () {

Expand All @@ -317,12 +313,20 @@ describe('ytracking', function () {

$scope.$emit('cart:updated', order);


var lengthAfter = $window._paq.length;
expect(lengthAfter > lengthBefore).toBeTruthy();

var found = false;
for (var i = 0; i < lengthAfter; i++) {
if (JSON.stringify($window._paq[i]) === JSON.stringify(['setCustomVariable', 1, 'cart_id', 123, 'page'])) {
found = true;
}
}
expect(found).toBeTruthy();

});


});

});
});

0 comments on commit 7d83d60

Please sign in to comment.