checkoutStarted()

in src/web-ui/src/analytics/AnalyticsHandler.js [760:845]


    checkoutStarted(user, cart, cartQuantity, cartTotal) {
        if (user) {
            AmplifyAnalytics.record({
                name: 'CheckoutStarted',
                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: 'CheckoutStarted',
                    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('CheckoutStarted', eventProperties);
        }

        if (this.mParticleEnabled()) {
            let totalAmount = 0;
            var checkoutList = [];
            for (var z = 0; z < cart.items.length; z++) {
                var checkoutItem = cart.items[z];
                var checkoutDetails = window.mParticle.eCommerce.createProduct(
                    checkoutItem.product_name,
                    checkoutItem.product_id,
                    parseFloat(checkoutItem.price),
                    parseInt(checkoutItem.quantity)
                );
                totalAmount = totalAmount + parseFloat(checkoutItem.price);
                checkoutList.push(checkoutDetails);
            }
    
            let transactionAttributes = {
                Id: cart.id,
                Revenue: totalAmount,
                Tax: totalAmount * .10
            };
            window.mParticle.eCommerce.logProductAction(window.mParticle.ProductActionType.Checkout, checkoutList, {mpid: window.mParticle.Identity.getCurrentUser().getMPID()}, {}, transactionAttributes);
        }

        if (this.amplitudeEnabled()) {
            Amplitude.getInstance().logEvent('CheckoutStarted', 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('begin_checkout', {
                "value": +cartTotal.toFixed(2),
                "currency": "USD",
                "items": gaItems
            });
        }
    },