Features

Ecommerce

Track the complete purchase journey — product views, cart activity, checkout steps, completed orders, refunds, wishlists, and SaaS subscriptions — all with one-line fg.track() calls, the recommended way to send ecommerce events.

Overview

Every ecommerce event is sent through fg.track() on the fg instance you created in the SDK Quickstart. The key payload types you'll use:

types.ts
1import type { Product, Cart, CartItem, Order } from "flowgrid-sdk/types"; 2 3// Product — used in views, cart adds, impressions 4const product: Product = { 5 productId: "sku_shirt_blue_L", 6 name: "Classic T-Shirt", 7 price: 29.99, 8 currency: "USD", 9 category: "apparel/tops", 10 variant: "Blue / L", 11 quantity: 1, 12}; 13 14// CartItem extends Product + adds quantity + lineTotal 15const cartItem: CartItem = { ...product, quantity: 2, lineTotal: 59.98 }; 16 17// Order — passed to purchases.complete() 18const order: Order = { 19 orderId: "ord_abc123", 20 items: [cartItem], 21 subtotal: 59.98, 22 discountTotal: 0, 23 shippingTotal: 5.00, 24 taxTotal: 4.80, 25 total: 69.78, 26 currency: "USD", 27};

Tip

Every event below also has an equivalent typed namespace shortcut (fg.cart.add(), fg.purchases.complete(), …) that produces an identical payload. Prefer fg.track()— it's one consistent API across the whole SDK.

Product views & impressions

Track when a user opens a product detail page, when a product appears in a list, and when they click a product in a list.

products.ts
1import { fg } from "@/lib/flowgrid"; 2 3// Product detail page opened 4await fg.track("product_view", { 5 productId: "sku_shirt_blue_L", 6 name: "Classic T-Shirt", 7 price: 29.99, 8 currency: "USD", 9 category: "apparel/tops", 10}); 11 12// Products appeared in a list (e.g. search results, category page) 13await fg.track("product_impression", { 14 list: { 15 listId: "search-results", 16 listName: "Search Results", 17 products: [ 18 { productId: "sku_shirt_blue_L", name: "Classic T-Shirt", price: 29.99, currency: "USD" }, 19 { productId: "sku_pants_black_M", name: "Chino Pants", price: 59.99, currency: "USD" }, 20 ], 21 }, 22}); 23 24// User clicked a product from the list 25await fg.track("product_click", { 26 productId: "sku_shirt_blue_L", 27 name: "Classic T-Shirt", 28 price: 29.99, 29 currency: "USD", 30 listId: "search-results", // list ID 31 position: 1, // position in list 32});

Cart

Track every cart mutation — adds, removals, quantity changes, and cart views.

cart.ts
1import { fg } from "@/lib/flowgrid"; 2 3const shirt = { 4 productId: "sku_shirt_blue_L", 5 name: "Classic T-Shirt", 6 price: 29.99, 7 currency: "USD", 8}; 9 10// Add to cart 11await fg.track("add_to_cart", { ...shirt, quantity: 2, cartId: "cart_xyz" }); 12 13// Remove from cart 14await fg.track("remove_from_cart", { ...shirt, quantity: 1, cartId: "cart_xyz" }); 15 16// Update quantity (2 → 3) 17await fg.track("update_cart_item", { 18 ...shirt, previousQuantity: 2, newQuantity: 3, cartId: "cart_xyz", 19}); 20 21// Cart page opened 22await fg.track("view_cart", { 23 cart: { 24 cartId: "cart_xyz", 25 items: [{ ...shirt, quantity: 3, lineTotal: 89.97 }], 26 subtotal: 89.97, 27 discountTotal: 0, 28 total: 89.97, 29 currency: "USD", 30 }, 31});

Checkout

Track each stage of your checkout funnel to identify exactly where users drop off.

checkout.ts
1import { fg } from "@/lib/flowgrid"; 2 3const cart = { 4 cartId: "cart_xyz", 5 items: [{ productId: "sku_shirt_blue_L", name: "Classic T-Shirt", price: 29.99, currency: "USD", quantity: 1, lineTotal: 29.99 }], 6 subtotal: 29.99, 7 discountTotal: 0, 8 total: 29.99, 9 currency: "USD", 10}; 11 12// User clicked "Proceed to checkout" 13await fg.track("begin_checkout", { cart }); 14 15// User moved to the shipping step 16await fg.track("checkout_step", { step: "shipping", stepNumber: 1, cart }); 17 18// User entered shipping details 19await fg.track("add_shipping_info", { 20 cart, 21 shipping: { 22 method: "standard", 23 carrier: "fedex", 24 cost: 5.00, 25 currency: "USD", 26 estimatedDays: 5, 27 }, 28});

Purchase

Fire fg.track("purchase", …) once the order is confirmed — typically on the order-confirmation page or in a server-side webhook.

purchase.ts
1import { fg } from "@/lib/flowgrid"; 2 3await fg.track("purchase", { 4 order: { 5 orderId: "ord_abc123", 6 items: [{ productId: "sku_shirt_blue_L", name: "Classic T-Shirt", price: 29.99, currency: "USD", quantity: 1, lineTotal: 29.99 }], 7 subtotal: 29.99, 8 discountTotal: 0, 9 shippingTotal: 5.00, 10 taxTotal: 2.40, 11 total: 37.39, 12 currency: "USD", 13 }, 14});

Tip

For server-side confirmation (webhook from Stripe, Shopify, etc.), use a server-side FlowGrid instance so the event fires even when the user has closed the tab.

Wishlist

wishlist.ts
1import { fg } from "@/lib/flowgrid"; 2 3const shirt = { productId: "sku_shirt_blue_L", name: "Classic T-Shirt", price: 29.99, currency: "USD" }; 4 5await fg.track("add_to_wishlist", { ...shirt, wishlistId: "wl_abc" }); 6await fg.track("remove_from_wishlist", { ...shirt, wishlistId: "wl_abc" }); 7await fg.track("wishlist_to_cart", { ...shirt, wishlistId: "wl_abc" }); 8await fg.track("share_wishlist", { wishlistId: "wl_abc", method: "link" });

Subscriptions SaaS / recurring billing

Track the full SaaS subscription lifecycle — new plans, upgrades, downgrades, cancellations, renewals, and trial conversions.

subscriptions.ts
1import { fg } from "@/lib/flowgrid"; 2 3// New subscription started 4await fg.track("subscription_start", { 5 subscriptionId: "sub_abc", userId: "u_123", plan: "pro", 6 mrr: { amount: 79, currency: "USD" }, billingCycle: "monthly", 7}); 8 9// Plan upgrade 10await fg.track("subscription_change", { 11 subscriptionId: "sub_abc", userId: "u_123", 12 previousPlan: "pro", newPlan: "enterprise", 13 previousMrr: { amount: 79, currency: "USD" }, 14 newMrr: { amount: 299, currency: "USD" }, 15 changeType: "upgrade", 16}); 17 18// Cancellation (immediate: false = cancel at period end) 19await fg.track("subscription_cancel", { 20 subscriptionId: "sub_abc", userId: "u_123", plan: "enterprise", 21 lostMrr: { amount: 299, currency: "USD" }, immediate: false, 22}); 23 24// Trial → paid conversion 25await fg.track("trial_converted", { 26 subscriptionId: "sub_abc", userId: "u_123", plan: "pro", 27 mrr: { amount: 79, currency: "USD" }, 28});

Full purchase flow

Putting it all together — every event from product view to order confirmation:

full-flow.ts
1import { fg } from "@/lib/flowgrid"; 2 3const product = { productId: "sku_1", name: "T-Shirt", price: 29.99, currency: "USD" }; 4const cartId = "cart_xyz"; 5const cart = { 6 cartId, currency: "USD", 7 items: [{ ...product, quantity: 1, lineTotal: 29.99 }], 8 subtotal: 29.99, discountTotal: 0, total: 29.99, 9}; 10 11// 1. Product page opened 12await fg.track("product_view", product); 13 14// 2. Added to cart 15await fg.track("add_to_cart", { ...product, quantity: 1, cartId }); 16 17// 3. Checkout began 18await fg.track("begin_checkout", { cart }); 19 20// 4. Shipping entered 21await fg.track("add_shipping_info", { cart, shipping: { method: "standard", carrier: "ups", cost: 5, currency: "USD", estimatedDays: 5 } }); 22 23// 5. Order confirmed (server-side preferred for reliability) 24await fg.track("purchase", { 25 order: { 26 orderId: "ord_1", items: cart.items, 27 subtotal: 29.99, discountTotal: 0, shippingTotal: 5, taxTotal: 2.40, total: 37.39, 28 currency: "USD", 29 }, 30});

All ecommerce events

Every event name you can pass to fg.track(), grouped by area.

AreaCoversEvent names
ProductsProduct views, list impressions, list clicksproduct_view, product_impression, product_click
CartAdd, remove, update, view cartadd_to_cart, remove_from_cart, update_cart_item, view_cart
CheckoutBegin checkout, steps, shipping, paymentbegin_checkout, checkout_step, add_shipping_info
PurchaseCompleted orderspurchase
RefundsFull or partial refundsrefund, refund_requested, refund_approved, refund_denied, refund_completed
WishlistAdd, remove, view, move to cart, shareadd_to_wishlist, remove_from_wishlist, view_wishlist, wishlist_to_cart, share_wishlist
SubscriptionsSaaS plan lifecyclesubscription_start, subscription_change, subscription_cancel, subscription_renew, trial_converted, trial_expired
PromotionsCoupon & promotion views / applicationspromotion_view, promotion_click, coupon_used