Analytics

The Analytics API provides insights and metrics about your loyalty program's performance.

Endpoints

Get Analytics

Retrieve analytics and insights for your loyalty program.

Endpoint: GET /analytics

Query Parameters:

Parameter
Type
Required
Description

startDate

string

No

ISO 8601 date string (default: 30 days ago)

endDate

string

No

ISO 8601 date string (default: now)

metric

string

No

Specific metric to retrieve

Example Request:

curl -X GET "https://api.monterosa.cloud/loyalty/v1/analytics?startDate=2025-09-01&endDate=2025-10-01" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "X-Monterosa-Org-ID: YOUR_ORG_UUID"

Example Response:

{
  "success": true,
  "data": {
    "orgId": "550e8400-e29b-41d4-a716-446655440000",
    "period": {
      "start": "2025-09-05T17:46:13.830Z",
      "end": "2025-10-05T17:46:13.830Z"
    },
    "metrics": {
      "totalTransactions": 1523,
      "byType": {
        "points": 1024,
        "xp": 312,
        "coins": 187
      },
      "totalAmount": {
        "points": 102400,
        "xp": 31200,
        "coins": 18700
      },
      "averagePerTransaction": {
        "points": 100,
        "xp": 100,
        "coins": 100
      },
      "uniqueUsers": 456
    },
    "topCampaigns": [
      {
        "campaignId": "campaign-001",
        "transactions": 823
      },
      {
        "campaignId": "campaign-002",
        "transactions": 456
      },
      {
        "campaignId": "campaign-003",
        "transactions": 244
      }
    ],
    "recentActivity": [
      {
        "transactionId": "txn_59e6dd71-4ac6-4284-8df7-787d575e60b3",
        "userId": "user123",
        "type": "points",
        "amount": 100,
        "createdAt": "2025-10-05T17:33:33.907Z"
      }
    ],
    "generatedAt": "2025-10-05T17:46:14.092Z"
  }
}

Response Fields

Period

The time range for the analytics data:

  • start - Beginning of the analytics period (ISO 8601)

  • end - End of the analytics period (ISO 8601)

Metrics

Aggregated metrics across all transactions:

Field
Description

totalTransactions

Total number of transactions in the period

byType

Breakdown of transaction counts by type (points, xp, coins)

totalAmount

Sum of all amounts by type

averagePerTransaction

Average transaction amount by type

uniqueUsers

Number of unique users with transactions

Top Campaigns

List of campaigns with the most transaction activity (limited to top 5):

  • campaignId - Campaign identifier

  • transactions - Number of transactions for this campaign

Recent Activity

The 10 most recent transactions, including:

  • transactionId - Transaction identifier

  • userId - User identifier

  • type - Transaction type

  • amount - Transaction amount

  • createdAt - Transaction timestamp

Use Cases

Performance Dashboard

Display key metrics on your admin dashboard:

Campaign Performance

Identify your best-performing campaigns:

User Engagement Tracking

Monitor user engagement over time:

Transaction Type Analysis

Understand which reward types are most popular:

Performance Considerations

  • Analytics are calculated in real-time from transaction data

  • Large date ranges may take longer to process

  • Results are limited to 1000 transactions for performance

  • Consider caching analytics data for frequently accessed date ranges

Error Responses

400 Bad Request:

500 Internal Server Error:

Best Practices

  1. Date Ranges: Use reasonable date ranges (1-90 days) for optimal performance

  2. Caching: Cache analytics data for 15-30 minutes to reduce API calls

  3. Pagination: For detailed analysis, use the Transactions API with pagination

  4. Trending: Track metrics over time to identify trends

  5. Alerts: Set up alerts for unusual metric changes

  6. Reporting: Export analytics data regularly for long-term analysis


Recent Activity Endpoint

Get a detailed, multi-source activity feed for your organisation's loyalty program. Perfect for powering admin dashboards, activity timelines, and audit logs.

Get Recent Activity

Retrieve recent activities across all loyalty program components.

Endpoint: GET /v1/activity/recent

Query Parameters:

Parameter
Type
Required
Description

limit

number

No

Number of activities to return (default: 50, max: 100)

type

string

No

Filter by activity type (see types below)

userId

string

No

Filter activities for a specific user

cursor

string

No

Pagination cursor for fetching older activities

Activity Types:

  • transaction_created - Points, XP, or coins awarded/deducted

  • campaign_created - New campaign created

  • campaign_activated - Campaign went live

  • segment_created - New user segment created

  • product_created - New reward product added

  • user_tier_upgraded - User moved to a higher tier

  • webhook_triggered - Webhook delivery sent

  • code_redeemed - Individual code redeemed by user

Example Request:

Example Response:

Activity Object Structure

Each activity contains:

Field
Type
Description

activityId

string

Unique identifier for this activity

type

string

Activity type (see types above)

timestamp

string

ISO 8601 timestamp when activity occurred

data

object

Activity-specific data (varies by type)

user

object|null

Enriched user details if activity has userId

User Enrichment

Activities that involve a user automatically include enriched user data:

User details are batch-fetched for performance (up to 100 users per request).

Pagination

Use the nextCursor to fetch older activities:

The cursor is base64-encoded and represents the timestamp of the last activity in the current page.

Filtering Examples

Get only transactions:

Get activity for specific user:

Get tier upgrades only:

Use Cases

1. Admin Activity Dashboard

Display real-time activity across your loyalty program:

2. User Activity History

Show a user's complete activity history:

3. Real-time Activity Feed

Create a live-updating activity feed:

4. Activity Type Statistics

Analyze activity patterns:

Performance Considerations

  • Multi-Source Aggregation: Queries 7 different tables (transactions, campaigns, products, segments, webhooks, codes, users)

  • Batch User Lookup: User details fetched in batches of 100 for efficiency

  • Limit Optimization: Keep limit ≤ 50 for fastest response times

  • Caching: Consider caching results for 30-60 seconds for high-traffic dashboards

  • Filtering: Use type and userId filters to reduce query scope

Error Responses

400 Bad Request:

500 Internal Server Error:

Best Practices

  1. Polling Interval: Poll every 10-30 seconds for real-time feeds

  2. Pagination: Use cursor-based pagination for loading historical data

  3. Type Filtering: Filter by type when you only need specific activities

  4. User Context: Use userId filter for user-specific activity pages

  5. Display Formatting: Format timestamps and activity descriptions for readability

  6. Error Handling: Handle missing user data gracefully (user may be deleted)

Last updated