Skip to main content
Use the same query standards from the SQL Query Library overview: is_order_sm_valid = TRUE for order analyses, sm_store_id scoping for multi-store setups, and your_project placeholders.
These templates cover cohort analysis, payback periods, and repeat purchase behavior. Some use the pre-aggregated cohort table for efficiency. The templates that pick a primary first-order product exclude non-product line items (shipping protection, fees) by matching product_title against a short list. Edit that list to match your catalog.
For fixed 30-, 60-, or 90-day LTV by commerce sales channel (sm_channel), build the cohort from obt_orders. Anchor each customer on their first valid order and count eligible revenue only within the requested elapsed-day horizon. For LTV by marketing acquisition source or medium, use the pre-aggregated cohort table and its monthly months_since_first_order horizons. See Cohort LTV analysis for the calculation and channel distinction.
If you use the cohort LTV table (rpt_cohort_ltv_by_first_valid_purchase_attribute_no_product_filters):
  • Always filter one cohort dimension (e.g., acquisition_order_filter_dimension = 'source/medium')
  • Always include sm_order_line_type = 'all_orders' unless you explicitly want a subset
What you’ll learn: Which cohort dimensions are available in the LTV table. Run this first to see what you can filter by (e.g., source/medium, discount_code, order_type_(sub_vs._one_time)).
What you’ll learn: Which acquisition sources produce customers with the best retention and lifetime value at the 3 and 6 month marks. Use this to optimize ad spend toward channels that deliver long-term value, not just initial conversions. Only cohorts old enough to have a complete month-6 row are included, so young cohorts do not inflate the denominator.
What you’ll learn: Roughly how many months it takes for each acquisition source/medium cohort to “pay back” its CAC (when cohort cumulative net revenue per customer first exceeds cost_per_acquisition). Only interpret rows where your cohort model populates CAC for that cohort. Only cohorts old enough to have a complete month-12 row are included, so every cohort has had the full 12 months to pay back.
What you’ll learn: Whether you’re getting enough 6‑month net revenue per acquired customer relative to CAC (a simple LTV:CAC sanity check). Only interpret rows where your cohort model populates CAC for that cohort.
What you’ll learn: Which discount codes attract customers who stick around and spend more over time. Identify promo codes that bring loyal buyers vs. one-time bargain hunters. Only cohorts old enough to have a complete month-12 row are included, so young cohorts do not inflate the denominator.
What you’ll learn: How customers who start with a subscription compare to one-time buyers in terms of retention and lifetime value. Quantify the LTV advantage (or disadvantage) of your subscription program. Only cohorts old enough to have a complete month-12 row are included, so young cohorts do not inflate the denominator.
What you’ll learn: How quickly customers come back to buy again after their first valid purchase, broken out by acquisition source/medium. This version counts only repeat orders with order_net_revenue > 0 (so $0 replacements/comp orders don’t inflate “purchase” rates). First orders from the last 90 days are excluded so every customer has a full 90-day window.
What you’ll learn: A practical retention proxy for subscription programs: customers whose first valid order was subscription vs one-time, and how quickly they return to buy again. This version counts only repeat orders with order_net_revenue > 0. First orders from the last 90 days are excluded so every customer has a full 90-day window.
What you’ll learn: Whether high-AOV first purchases actually translate into better short-term retention. This version counts only repeat orders with order_net_revenue > 0 so that $0 orders don’t inflate “purchase” rates. First orders from the last 90 days are excluded so every customer has a full 90-day window.
What you’ll learn: Which acquisition source/mediums produce higher 90‑day LTV (including the first order). This is a dynamic alternative to cohort tables when you want a strict “first purchase → next 90 days” window. First orders from the last 90 days are excluded so every customer has a full 90-day window.
What you’ll learn: How 90‑day LTV differs for customers whose first valid order used exactly one discount code vs no code. Customers whose first order has multiple codes are excluded to avoid ambiguity/double counting. Use the “Multiple discount codes prevalence” diagnostic before interpreting results. First orders from the last 90 days are excluded so every customer has a full 90-day window.
What you’ll learn: Which acquisition source/mediums produce higher refund rates on the first valid order (by order count and by revenue). This is a common “traffic quality” question and helps spot channels driving mismatched expectations. First orders from the last 90 days are excluded so every order has had the same 90 days to be refunded.
What you’ll learn: How 90‑day LTV differs by the commerce platform (source_system) and sales channel (sm_channel) of the first valid order. This helps separate marketplace/POS behavior from online DTC without mixing attribution concepts. First orders from the last 90 days are excluded so every customer has a full 90-day window.
What you’ll learn: A sanity check to reconcile precomputed cohort-table LTV (month-offset based) with a dynamic 180-day LTV window from obt_orders. Differences can indicate mismatched cohort definitions or expectation gaps (month buckets vs day windows). The window stops 7 months ago so both sides have a complete 6-month horizon.
What you’ll learn: Which primary first‑order SKU (one SKU per customer, chosen as the highest net‑revenue line item on the first valid order) is associated with higher 90‑day LTV. Use this to identify “starter products” to feature in acquisition campaigns and new customer bundles. First orders from the last 90 days are excluded so every customer has a full 90-day window.
What you’ll learn: Which product types tend to create higher 90‑day customer value when they appear as the “primary” first-order item (one product type per customer, selected by highest first-order net revenue). This is a scalable alternative to SKU-level LTV. First orders from the last 90 days are excluded so every customer has a full 90-day window.
What you’ll learn: Which vendors tend to create higher 90‑day customer value when they appear as the “primary” first-order item (one vendor per customer, selected by highest first-order net revenue). Useful for wholesale/brand partnerships and merchandising. First orders from the last 90 days are excluded so every customer has a full 90-day window.
What you’ll learn: The distribution of days between repeat purchases for non-subscription customers. Use this to time your re-engagement emails and identify the optimal window for replenishment reminders.

Back to the SQL Query Library.

Customers & Retention

Start with customer mix and repeat behavior before cohort analysis.

Orders & Revenue

Connect long-term value to current order economics.

Marketing & Ads

Compare cohort value and payback against acquisition performance.