Analytics

The analytics endpoint empowers administrators to gain comprehensive insights into their performance effortlessly. Through this feature, admins can access crucial metrics such as total sales, overall orders, and identify the top-selling products. With seamless access to such analytics, administrators can make informed decisions to optimize their strategies, enhance user experiences, and drive business growth effectively.

Fields

  • Name
    totalUsers
    Type
    int
    Description

    Total number of users created.

  • Name
    totalProducts
    Type
    int
    Description

    Total number of products created.

  • Name
    totalOrders
    Type
    int
    Description

    Total number of orders created.

  • Name
    totalSales
    Type
    int
    Description

    The total revenue of sales.

  • Name
    mostSoldProduct
    Type
    product
    Description

    The most sold product, included with the total income, quantity, and ordered count of the product.

  • Name
    usersWithMostOrders
    Type
    users[]
    Description

    The users with the most orders.


GET/analytics

Retrieve analytics

ONLY ADMIN

This endpoint facilitates retrieval of analytics data, offering insights into various metrics and trends.

Required attributes

  • Name
    user_id
    Type
    ObjectId
    Description

    The _id of the user, given in token from the Authorization header.

Optional attributes

  • Name
    users
    Type
    int
    Description

    The number of users with the most orders to retrieve. Default: 3.

Request

GET
/analytics
curl -G https://lets-go-phi.vercel.app \
  -H "Authorization: Bearer {token}" \

Response

{
  "totalUsers": 9,
  "totalProducts": 36,
  "totalOrders": 20,
  "totalSales": 2414600,
  "mostSoldProduct": {
    "_id": "6633a1bcecb94dd849192101",
    "totalQuantity": 11,
    "totalIncome": 385000,
    "count": 7,
    "product": {
        "_id": "6633a1bcecb94dd849192101",
        "name": "LEGO Star Wars AT-AT™ TESZT AT.",
        "price": 35000,
        //...
    }
  },
  "usersWithMostOrders": [
    {
        "_id": "662c20da7f42e1de734fe684",
        "totalOrders": 11,
        "totalAmount": 946000,
        "user": {
            "_id": "662c20da7f42e1de734fe684",
            "name": "Boyd Labadie",
            "email": "123@gmail.com"
        }
    },
    //...
  ]
}

Was this page helpful?