Mobi2Go Analytics API

Mobi2Go makes available an Analytics API which allows you to listen for various events, and then trigger JavaScript to make calls to your analytics service.

Below are some examples of how this API can be used:

 
// When a store is selected
Mobi2Go.Analytics.bind({
    IDENTIFY_LOCATION: function(location) {
        // Google tag manager
        dataLayer.push({'event': 'store_selected', 'location': location});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('store_selected', {name: location.name});
    }
});

// When a customer has logged in
Mobi2Go.Analytics.bind({
    IDENTIFY_CUSTOMER: function(customer) {
        // Google tag manager
        dataLayer.push({'event': 'customer_login', 'location': customer});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('customer_login', {name: customer.email});
    }
});

// When the last order is loaded
Mobi2Go.Analytics.bind({
    LAST_ORDER_LOADED: function(lastOrderState) {
        // Google tag manager
        dataLayer.push({'event': 'last_order', 'lastOrderState': lastOrderState});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('last_order', {method: lastOrderState[0].method});
    }
});

// When a product menu category is viewed
Mobi2Go.Analytics.bind({
    VIEWED_PRODUCT_CATEGORY: function(menu_category) {
        // Google tag manager
        dataLayer.push({'event': 'opened_category', 'menu_category': menu_category});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('opened_category', {method: menu_category[0].name});
    }
});

// When the product menu is viewed
Mobi2Go.Analytics.bind({
    VIEWED_PRODUCT_MENU: function(menu) {
        // Google tag manager
        dataLayer.push({'event': 'opened_product_menu', 'menu': menu});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('opened_product_menu', {name: menu.name});
    }
});

// When a product is viewed
Mobi2Go.Analytics.bind({
    VIEWED_PRODUCT: function(product) {
        // Google tag manager
        dataLayer.push({'event': 'opened_product', 'product': product});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('opened_product', {name: product.name});
    }
});

// When a product is added to the cart
Mobi2Go.Analytics.bind({
    ADDED_PRODUCT: function(product) {
        // Google tag manager
        dataLayer.push({'event': 'add_product', 'product': product});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('add_product', {name: product.name, price: product.price.toFloat()});
    }
});

// When a product is in the cart is edited
Mobi2Go.Analytics.bind({
    EDITED_PRODUCT: function(product) {
        // Google tag manager
        dataLayer.push({'event': 'edit_product', 'product': product});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('edit_product', {name: product.name});
    }
});

// When a product is in the cart is removed
Mobi2Go.Analytics.bind({
    REMOVED_PRODUCT: function(product) {
        // Google tag manager
        dataLayer.push({'event': 'remove_product', 'product': product});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('remove_product', {name: product.name});
    }
});

// When a user clicks the 'Next step' button
Mobi2Go.Analytics.bind({
    EVENTS.STARTED_CHECKOUT: function() {
        // Google tag manager
        dataLayer.push({'event': 'start_checkout'});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('start_checkout');
    }
});

// When a user clicks the 'Pay Now' button
Mobi2Go.Analytics.bind({
    STARTED_PAYMENT: function(order) {
        // Google tag manager
        dataLayer.push({'event': 'start_payment', 'order': order});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('start_payment', {total: order.getTotal().toFloat()});
    }
});

// When the order is confirmed (paid for)
Mobi2Go.Analytics.bind(
    CONFIRMED_ORDER: function(order) {
        // Google tag manager
        dataLayer.push({'event': 'purchase', 'order': order});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('purchase', {total: order.getTotal().toFloat()});
    }
);

// When the credit card details are saved after order confirmation
Mobi2Go.Analytics.bind({
    CREDIT_CARD_SAVED: function(order) {
        // Google tag manager
        dataLayer.push({'event': 'card_saved', 'order': order});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('card_saved');
    }
});

Note that event bindings can be combined, and if using ES6, you can use the Mobi2Go.Analytics.EVENTS enumerated properties, e.g.

let Analytics = Mobi2Go.Analytics;
let Events = Mobi2Go.Analytics.Events;

// When a store is selected
Analytics.bind({
    [EVENTS.IDENTIFY_LOCATION]: function(location) {
        // Google tag manager
        dataLayer.push({'event': 'store_selected', 'location': location});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('store_selected', {name: location.name});
    },
    [EVENTS.LAST_ORDER_LOADED]: function(lastOrderState) {
        // Google tag manager
        dataLayer.push({'event': 'last_order', 'lastOrderState': lastOrderState});

        // Generic analytic service (such as Google Analytics)
        acme_tracker.track('last_order', {method: lastOrderState[0].method});
    }
});
Have more questions? Submit a request

Comments