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.

Urban Store ships a purpose-built analytics engine that records every meaningful shopper interaction as an immutable event in MongoDB. Those events feed four admin-only API views: a comprehensive dashboard with over a dozen KPIs, a step-by-step conversion funnel, an RFM customer segmentation model, and a real-time smart alerts system that flags anomalies before they hurt revenue.

Event Tracking System

Every event is persisted as an Event document in the analytics_events MongoDB collection, backed by the MongoEngine model defined in analytics/models.py. Each document carries the following fields:
FieldTypeDescription
user_idStringEmail of the authenticated user, or null for guests
session_idStringStable identifier from localStorage (required)
event_typeStringThe action being recorded (see table below)
product_slugStringSlug of the relevant product, if applicable
product_nameStringDisplay name of the product
priceStringUnit price at the time of the event
metadataDictArbitrary extra data, e.g. { "quantity": 2 }
sourceStringTraffic source, e.g. google, instagram, direct
idempotency_keyStringUnique key to deduplicate events in a 5-second window
error_messageStringError detail for error-type events
created_atDateTimeUTC timestamp, indexed for range queries
To record an event from the frontend (public, no auth required):
POST /api/analytics/track/
Content-Type: application/json

{
  "session_id": "abc-123",
  "event_type": "add_to_cart",
  "product_slug": "camiseta-oversize-negra",
  "product_name": "Camiseta Oversize Negra",
  "price": "79900",
  "metadata": { "quantity": 1 },
  "source": "instagram"
}

Tracked Event Types

Event TypeWhen Fired
page_viewUser loads any page
product_viewUser opens a product detail page
add_to_cartUser adds an item to the cart
begin_checkoutUser starts the checkout flow
purchaseOrder successfully paid via Stripe
checkout_startedCheckout form is opened
payment_info_enteredPayment details are submitted
order_completedOrder confirmation page is viewed
payment_errorStripe payment fails
checkout_errorCheckout form validation error
payment_confirmation_errorError confirming payment after submission
address_errorShipping address validation error
whatsapp_cart_clickUser clicked the WhatsApp buy button
whatsapp_purchaseWhatsApp purchase confirmed

Dashboard Stats

GET /api/analytics/dashboard-stats/?mode=total
Authorization: Bearer <admin_token>
The optional mode query parameter accepts total (default) or unique. All metrics cover the last 7 days. The response object contains the following metrics:
FieldDescription
modeThe aggregation mode used — total or unique
total_salesNumber of purchase events
total_revenueSum of price × quantity across all purchases
average_order_valuetotal_revenue / total_sales
top_productsTop 5 products by units sold
top_viewed_productsTop 5 products by views (unique sessions in unique mode)
sales_by_dayPurchase count per calendar day
abandonment_rate% of begin_checkout identifiers that never reached purchase
event_countsRaw or unique counts for product_view, add_to_cart, begin_checkout, purchase
conversion_ratesvisit_to_cart, cart_to_checkout, checkout_to_purchase percentages
checkout_started_countCount of checkout_started events
payment_info_entered_countCount of payment_info_entered events
order_completed_countCount of order_completed events
conversion_checkout_to_paymentCheckout-started → payment-entered conversion %
conversion_payment_to_orderPayment-entered → order-completed conversion %
error_countsCounts for payment_error, checkout_error, payment_confirmation_error
product_performanceTop 10 products with views, add-to-carts, purchases, and conversion rate
events_timelineDay-by-day breakdown of all key event types
errors_timelineDay-by-day error counts
session_statsUnique sessions, average events per session, sessions with purchase
retention_metricsRepurchase rate and recurrent customer counts over a 90-day window
traffic_sourcesSession counts grouped by source field
whatsapp_sessionsUnique sessions that clicked the WhatsApp button
whatsapp_purchasesUnique sessions with a whatsapp_purchase event
whatsapp_sessions_listLast 10 session IDs that clicked the WhatsApp button

Conversion Funnel

GET /api/analytics/funnel/
Authorization: Bearer <admin_token>
Returns the count of unique sessions that reached each step in the standard e-commerce funnel:
page_view → product_view → add_to_cart → begin_checkout → purchase
Query parameters:
ParameterFormatDescription
startYYYY-MM-DDStart of the date range (default: 30 days ago)
endYYYY-MM-DDEnd of the date range (default: now)
sourcestringFilter to a specific traffic source, e.g. google
Example response:
{
  "funnel": [
    { "step": "page_view",      "count": 1842 },
    { "step": "product_view",   "count": 940  },
    { "step": "add_to_cart",    "count": 312  },
    { "step": "begin_checkout", "count": 98   },
    { "step": "purchase",       "count": 67   }
  ],
  "start_date": "2024-05-01T00:00:00",
  "end_date":   "2024-05-31T23:59:59"
}

RFM Segmentation

GET /api/analytics/rfm/
Authorization: Bearer <admin_token>
Segments registered customers based on their purchase history over the last 90 days using the Recency / Frequency / Monetary model. Only customers with a non-null user_id on their purchase events are included. Segment rules (applied in order):
SegmentSpanish LabelRule
VIPVIPRecency ≤ 7 days and frequency ≥ 2 and monetary ≥ 100,000
LoyalLealRecency ≤ 30 days and frequency ≥ 1
At RiskEn riesgoRecency ≤ 60 days
LostPerdidoRecency > 60 days
Example response:
{
  "rfm": [
    {
      "visitor_id": "customer@example.com",
      "recency": 3,
      "frequency": 4,
      "monetary": 318000,
      "segmento": "VIP"
    }
  ],
  "start_date": "2024-03-02T00:00:00",
  "end_date":   "2024-05-31T23:59:59"
}

Smart Alerts

GET /api/analytics/alerts/
Authorization: Bearer <admin_token>
Runs five real-time diagnostic rules against recent event data and returns a list of active alerts. If no rules trigger, a single all_clear alert is returned.
Alert TypeSeverityTrigger Condition
high_abandonmentcriticalAbandonment rate > 70% in the last 24 h, with ≥ 3 checkouts
popular_no_conversionwarningProduct with > 10 unique views in 7 days and zero purchases
payment_errorscriticalAny payment_error event in the last 1 hour
carts_abandonedwarning≥ 5 cart sessions with no checkout start in the last 6 hours
stuck_sessionsinfoSessions with > 15 events in 24 hours and no purchase
Each alert object includes type, message, severity, and timestamp.

mode=total vs mode=unique

The mode query parameter on the dashboard endpoint controls how event counts are aggregated.
ModeBehavior
totalCounts every raw event occurrence — a user refreshing a product page 10 times adds 10 to product_view
uniqueCounts distinct session_id values — the same user counts once per step regardless of repetitions
Use mode=unique when analyzing your conversion funnel. Unique-session counts eliminate noise from page refreshes and back-navigation, giving you a truer picture of how many distinct shoppers progressed through each stage.

Build docs developers (and LLMs) love