Server-SideREST API

REST API Overview

Direct HTTP integration with Audiencelab's server-to-server API

The Audiencelab REST API provides direct HTTP endpoints for server-to-server integration. Use these endpoints when you need maximum flexibility or when working with languages without an official SDK.

Base URL

All API requests should be made to your assigned base URL. The React Web SDK uses:

https://analytics.geeklab.app

If your organization was provisioned a different base URL, use that value instead.

API Flow Overview

The REST API follows a specific flow for tracking user events. Understanding when to call each endpoint is crucial for accurate attribution and analytics.

SDK-Aligned Flow

┌─────────────────┐     ┌────────────────────┐     ┌──────────────────────┐
│  App Initialize │ ──> │ Fetch Token        │ ──> │ Send Webhook Events  │
│ (API key ready) │     │ (device-metrics)   │     │ (retention/custom)   │
└─────────────────┘     └────────────────────┘     └──────────────────────┘
  1. Fetch Token - Send device metrics and receive a token
  2. Send Webhook Events - Post retention and custom events using /webhook

Optional Checks

  • Verify Token - Validate a token when needed
  • Check Data Collection Status - Verify collection is enabled for the API key

Available Endpoints

EndpointMethodDescriptionWhen to Call
/fetch-tokenPOSTSend device metrics and receive a tokenOn app init (cache the token)
/verify-tokenPOSTVerify a tokenWhen you need to validate a token
/check-data-collection-statusGETCheck if data collection is enabledOn startup or diagnostics
/webhookPOSTSend retention, purchase, ad, or custom eventsDuring sessions and user actions

Request Format

All requests must:

  • Include Content-Type: application/json header (except for GET)
  • Include geeklab-api-key header with your API key
  • Send JSON-encoded body for POST requests

Example Request Structure

curl -X POST https://analytics.geeklab.app/fetch-token \
  -H "Content-Type: application/json" \
  -H "geeklab-api-key: your_api_key" \
  -d '{
    "type": "device-metrics",
    "created_at": "2024-10-10T10:15:00.000Z",
    "data": {
      "device_name": "MacBook Pro",
      "device_model": "MacBookPro18,3",
      "os_system": "macOS 14.5",
      "timezone": "America/Los_Angeles"
    }
  }'

Response Format

All successful responses return JSON with a 200 OK status. For example, /fetch-token responds with a token:

{
  "token": "abc123def456"
}

Error responses include an error message:

{
  "error": "Error description"
}

Quick Start

  1. Get your API key from the Audiencelab dashboard
  2. Fetch a token using /fetch-token (cache it)
  3. Send a retention event using /webhook
  4. Track purchases and ad views as they occur via /webhook

Continue to Authentication to learn about API authentication.