Track Shopping Carts in Real-Time
We’ll use Presence to track each ShoppingCartChannel and the shopper’s cart item IDs. Each change to a cart will dispatch an update to the CartTracker, and the admin client will automatically receive the changes. Our process for this task will break down into these steps:
- Create a CartTracker module using Phoenix.Presence.
- Connect ShoppingCartChannel to the CartTracker.
- Send cart updates to the CartTracker.
- Configure admin.js to receive Presence updates.
- Aggregate and display the information in the dashboard.
First, create the CartTracker module under the sneakers_23_web/channels directory.
| defmodule Sneakers23Web.CartTracker do |
| use Phoenix.Presence, ... |
Get Real-Time Phoenix now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.