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.

Fire this endpoint from the browser or mobile app whenever a meaningful user action occurs. Events are stored in the analytics_events MongoDB collection and power the dashboard, funnel, RFM, and alert views. No authentication is required, but including a JWT in the Authorization header associates the event with the logged-in user’s email (user_id).

Endpoint

POST /api/analytics/track/

Authentication

None required. If a valid Authorization: Bearer <token> header is present, the event is linked to the authenticated user’s email in the user_id field. Anonymous events are stored with user_id: null.

Request Body

event_type
string
required
The type of behavioral event being recorded. See the event types table below.
session_id
string
A stable UUID that identifies the browsing session. Store this in localStorage and reuse it across page loads. If omitted, the server generates a new UUID — meaning session continuity is lost.
product_slug
string
URL slug of the product associated with this event (e.g. "urban-cargo-pants"). Required for meaningful product_view, add_to_cart, and purchase events.
product_name
string
Human-readable product name. Stored alongside product_slug for display in the dashboard.
price
number
Unit price in COP. Used to compute revenue in purchase events. Stored as a string internally.
metadata
object
Arbitrary key-value bag for additional context. For purchase events, include quantity to enable accurate revenue calculations (e.g. {"quantity": 2}).
source
string
Traffic source that brought this user to the store. Examples: "google", "direct", "instagram", "social". Used to populate the traffic sources dashboard widget.
error_message
string
Human-readable error description. Include when firing error event types such as payment_error, checkout_error, payment_confirmation_error, or address_error. Stored directly on the event document for debugging in the dashboard.
idempotency_key
string
A client-generated unique key for this specific event fire. If the same key is seen again within 5 seconds, the event is silently discarded and {"status": "duplicate_ignored"} is returned. If omitted, the server generates one from a SHA-256 hash of session_id + event_type + product_slug + timestamp.

Idempotency

To prevent double-counting caused by network retries or React re-renders, generate a unique idempotency_key per event fire (e.g. crypto.randomUUID()). Events with a matching key received within 5 seconds of the original return 200 {"status": "duplicate_ignored"} without writing to the database.

Event Types

Event TypeWhen to fire
page_viewUser loads any page
product_viewProduct detail page is rendered
add_to_cartUser adds an item to their cart
begin_checkoutUser navigates to the checkout flow
purchaseOrder payment is confirmed (fire after confirm-payment succeeds)
checkout_startedCheckout form is opened / mounted
payment_info_enteredUser submits the payment details form
order_completedOrder confirmation page is viewed
payment_errorStripe payment attempt fails
checkout_errorCheckout form validation or submission error
whatsapp_cart_clickUser clicks the “Comprar por WhatsApp” button
whatsapp_purchaseWhatsApp purchase is manually confirmed

Response — 201 Created

{
  "status": "ok"
}

Response — 200 OK (duplicate)

{
  "status": "duplicate_ignored"
}

JavaScript Fetch Example

const sessionId = localStorage.getItem("session_id") ?? (() => {
  const id = crypto.randomUUID();
  localStorage.setItem("session_id", id);
  return id;
})();

await fetch("https://api.urbanstore.co/api/analytics/track/", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    // Include if user is logged in:
    // "Authorization": `Bearer ${token}`,
  },
  body: JSON.stringify({
    event_type: "add_to_cart",
    session_id: sessionId,
    product_slug: "urban-cargo-pants",
    product_name: "Urban Cargo Pants",
    price: 189000,
    metadata: { quantity: 1 },
    source: "google",
    idempotency_key: crypto.randomUUID(),
  }),
});

Build docs developers (and LLMs) love