in src/web-ui/src/analytics/AnalyticsHandler.js [671:758]
cartViewed(user, cart, cartQuantity, cartTotal) {
if (user) {
AmplifyAnalytics.record({
name: 'CartViewed',
attributes: {
userId: user.id,
cartId: cart.id
},
metrics: {
cartTotal: +cartTotal.toFixed(2),
cartQuantity: cartQuantity
}
})
}
if (this.personalizeEventTrackerEnabled()) {
for (var item in cart.items) {
AmplifyAnalytics.record({
eventType: 'CartViewed',
userId: user ? user.id : AmplifyStore.state.provisionalUserID,
properties: {
itemId: cart.items[item].product_id,
discount: "No"
}
}, 'AmazonPersonalize')
AmplifyStore.commit('incrementSessionEventsRecorded');
}
}
let eventProperties = {
cartId: cart.id,
cartTotal: +cartTotal.toFixed(2),
cartQuantity: cartQuantity
};
if (this.segmentEnabled()) {
window.analytics.track('CartViewed', eventProperties);
}
if (this.mParticleEnabled()) {
var cartViewList = [];
let totalAmount = 0;
for (var cartCounter = 0; cartCounter < cart.items.length; cartCounter++) {
var cartViewItem = cart.items[cartCounter];
var cartViewDetails = window.mParticle.eCommerce.createProduct(
cartViewItem.product_name,
cartViewItem.product_id,
parseFloat(cartViewItem.price),
parseInt(cartViewItem.quantity)
);
totalAmount = totalAmount + parseFloat(cartViewItem.price);
cartViewList.push(cartViewDetails);
}
let transactionAttributes = {
Id: cart.id,
Revenue: totalAmount,
Tax: totalAmount * .10
};
window.mParticle.eCommerce.logProductAction(window.mParticle.ProductActionType.Click, cartViewList, {mpid: window.mParticle.Identity.getCurrentUser().getMPID()}, {}, transactionAttributes);
}
if (this.amplitudeEnabled()) {
// Amplitude event
Amplitude.getInstance().logEvent('CartViewed', eventProperties);
}
if (this.googleAnalyticsEnabled()) {
let gaItems = [];
for (var i in cart.items) {
gaItems.push({
"item_id": cart.items[i].product_id,
"item_name": cart.items[i].product_name,
"quantity": cart.items[i].quantity,
"index": gaItems.length + 1,
"currency": "USD",
"price": +cart.items[i].price.toFixed(2)
});
}
Vue.prototype.$gtag.event('view_cart', {
"value": +cartTotal.toFixed(2),
"currency": "USD",
"items": gaItems
});
}
},