Tracking Rebuy's Smart Cart in Google Analytics

Updated on 2024-01-22

One of Rebuy's most popular products is the Smart Cart, which adds upsell and promotional potential to Shopify.

If your store uses the Smart Cart here's a simple way to track who is interacting with the cart and, in conjunction with Littledata's Google Analytics tracking for Shopify, how this leads to purchasing.

Tracking Rebuy Smart Cart

Using the integration below you can move beyond Rebuy's own analytics to track interactions with the Smart Cart.

In Google Analytics you can use the events tracked to:

  1. See how many users open the Smart Cart
  2. See if users who switch to subscription go on to checkout that subsciption product
  3. See if users who selected an upsell in the Smart Cart have a higher Average Order Value
  4. See how many products sold came from quantity increases in the Smart Cart

Events tracked

After added the script below to your store, you will see these useful events to Google Analytics:

Google Analytics Event NameAction
rebuy_smartcart_shownSmart Cart is shown / opened
rebuy_smartcart_hiddenSmart Cart is hidden / closed
rebuy_smartcart_item_increaseAn item quantity has been increased
rebuy_smartcart_item_decreaseAn item quantity has been decreased
rebuy_smartcart_item_removedA customer removes an item from the Smart Cart
rebuy_smartcart_switched_to_subscriptionAn item is switched to subscription
rebuy_smartcart_switched_to_onetimeAn item is switched to one-time
tip:

Adds to Cart and Remove from Cart that happen outside of the Smart Cart are already tracked by Littledata tracking for Shopify.

You'll be able to see those events using a Google Analytics debugger on the browser:

Rebuy events in Google Analytics

Using the events in Google Analytics

You'll be able to see chat events in the realtime reports for testing, and under Reports > Engagement > Events within 24 hours.

If you want to see how many people who viewed the Smart Cart went on to purchase you can build a customer segment of those that have a rebuy_smartcart_shown event and compare with those users which did not.

Or look at the volume of events received and whether a certain volume of messaging drives purchasing.

Adding the script

note:

You'll need developer access to the Shopify theme to add this integration currently. Please get in touch if you need help implementing this.

You need to paste this script anywhere into the Shopify theme.liquid file, or assets loaded from the theme. It listens for the Smart Cart events, and passes those events onto Google Analytics using the gtag library.

If the gtag library has not yet loaded the events will be queued until Google Analytics is ready.

<script>
const eventsToTrack = [
  { rebuy: "rebuy:smartcart.show", ga: "rebuy_smartcart_shown" },
  { rebuy: "rebuy:smartcart.hide", ga: "rebuy_smartcart_hidden" },
  {
    rebuy: "rebuy:smartcart.line-item-increase",
    ga: "rebuy_smartcart_item_increase",
  },
  {
    rebuy: "rebuy:smartcart.line-item-decrease",
    ga: "rebuy_smartcart_item_decrease",
  },
  {
    rebuy: "rebuy:smartcart.line-item-removed",
    ga: "rebuy_smartcart_item_removed",
  },
  {
    rebuy: "rebuy:smartcart.item-switch-to-subscription",
    ga: "rebuy_smartcart_switched_to_subscription",
  },
  {
    rebuy: "rebuy:smartcart.item-switch-to-one-time",
    ga: "rebuy_smartcart_switched_to_onetime",
  },
];
eventsToTrack.forEach(function (event) {
  document.addEventListener(event.rebuy, function (props) {
    let params = {};
    const item = props?.detail?.item;

    if (item) {
      const { sku, product_id, variant_id, product_title } = item;
      params = {
        ...params,
        sku,
        product_id,
        variant_id,
        product_title,
      };
    }
    gtag && gtag("event", event.ga, params);
  });
});
</script>