Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ALEJ4NDRO2025/urban-store/llms.txt

Use this file to discover all available pages before exploring further.

RFM (Recency, Frequency, Monetary) segmentation groups your registered customers by how recently they purchased, how often they purchase, and how much they spend. This endpoint scans all purchase events from authenticated users over the last 90 days and assigns each customer to one of four actionable segments. Use the output to drive targeted retention campaigns, loyalty rewards, or win-back sequences.

Endpoint

GET /api/analytics/rfm/

Authentication

Bearer token required with is_admin: true in the JWT payload. Returns 403 if the user is not an admin.

Analysis Window

The lookback period is always the last 90 days from the time of the request. Only purchase events where user_id is not null are included — anonymous sessions are excluded because they cannot be attributed to a specific customer.

Segmentation Rules

Segments are evaluated in priority order. A customer is placed in the highest matching segment.
SegmentCriteria
VIPRecency ≤ 7 days AND Frequency ≥ 2 purchases AND Monetary ≥ 100,000 COP
LealRecency ≤ 30 days AND Frequency ≥ 1 purchase
En riesgoRecency ≤ 60 days
PerdidoRecency > 60 days
  • Recency — days since the customer’s most recent purchase event.
  • Frequency — total number of purchase events in the 90-day window.
  • Monetary — sum of the price field across all purchase events in the window, in COP.

Response

rfm
array
Array of customer segment objects, sorted by recency ascending (most recent purchasers first).
start_date
string
ISO 8601 timestamp of the start of the 90-day window.
end_date
string
ISO 8601 timestamp representing now (end of the window).

Example

curl -X GET https://api.urbanstore.co/api/analytics/rfm/ \
  -H "Authorization: Bearer <admin_token>"
{
  "rfm": [
    {
      "visitor_id": "ana@ejemplo.com",
      "recency": 2,
      "frequency": 4,
      "monetary": 756000,
      "segmento": "VIP"
    },
    {
      "visitor_id": "pedro@ejemplo.com",
      "recency": 18,
      "frequency": 1,
      "monetary": 189000,
      "segmento": "Leal"
    },
    {
      "visitor_id": "luisa@ejemplo.com",
      "recency": 55,
      "frequency": 1,
      "monetary": 95000,
      "segmento": "En riesgo"
    },
    {
      "visitor_id": "carlos@ejemplo.com",
      "recency": 82,
      "frequency": 1,
      "monetary": 210000,
      "segmento": "Perdido"
    }
  ],
  "start_date": "2024-02-22T15:00:00+00:00",
  "end_date": "2024-05-22T15:00:00+00:00"
}

Build docs developers (and LLMs) love