Track Event

Record a custom event for analytics and audience segmentation

Record a custom event for analytics and audience segmentation.

Endpoint

text
POST /events

Authentication

Required: Bearer token in Authorization header

text
Authorization: Bearer YOUR_API_KEY

Request Body

json
{
  "event_name": "purchase_completed",
  "user_id": "user_123",
  "properties": {
    "amount": 29.99,
    "currency": "USD",
    "product_id": "premium_plan"
  },
  "ip": "192.168.1.1",
  "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
}

Parameters

Parameter Type Required Description
event_name string Yes Name of the event to track
user_id string Yes Your unique identifier for the user
properties object No Additional event attributes as key-value pairs
ip string No User's IP address for analytics tracking
ua string No User agent string for device/browser tracking

Response

json
{
  "success": true,
  "event_id": "evt_789",
  "message": "Event tracked successfully"
}

Examples

For client-side tracking in web browsers, use the Appizer Web SDK which handles authentication and user identification automatically:

javascript
// Initialize the SDK once
AppizerWeb.init({
  appId: 'YOUR_APP_ID',
  autoEvents: true, // Automatic page view tracking (including SPAs)
  autoHook: true    // Automatic form submission tracking
});

// Track a custom event
AppizerWeb.trackEvent('purchase_completed', {
  amount: 29.99,
  currency: 'USD',
  product_id: 'premium_plan'
});

// User ID is automatically managed by the SDK
// To set a custom user ID (e.g., after login):
AppizerWeb.setUserId('user_123');

Automatic User Identification

The Web SDK automatically generates and persists user IDs in localStorage, eliminating the need to manually manage user identification in the browser. Authentication is handled via domain validation - no API keys needed in client-side code.

JavaScript (Server-Side or Direct API)

For server-side tracking or direct API calls:

javascript
const response = await fetch('https://api.appizer.com/v1/events', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    event_name: 'purchase_completed',
    user_id: 'user_123',
    properties: {
      amount: 29.99,
      currency: 'USD',
      product_id: 'premium_plan'
    }
  })
});

const data = await response.json();
console.log(data);

Python

python

response = requests.post(
    'https://api.appizer.com/v1/events',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'event_name': 'purchase_completed',
        'user_id': 'user_123',
        'properties': {
            'amount': 29.99,
            'currency': 'USD',
            'product_id': 'premium_plan'
        }
    }
)

print(response.json())

cURL

bash
curl -X POST https://api.appizer.com/v1/events \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "event_name": "purchase_completed",
    "user_id": "user_123",
    "properties": {
      "amount": 29.99,
      "currency": "USD",
      "product_id": "premium_plan"
    }
  }'

Error Responses

Status Code Description
400 Bad Request - Invalid request body or missing required fields
401 Unauthorized - Invalid or missing API key
429 Too Many Requests - Rate limit exceeded
500 Internal Server Error - Something went wrong on our end

Best Practices

  • Use descriptive event names (e.g., purchase_completed instead of event1)
  • Include relevant properties for better segmentation
  • Track events as close to the action as possible
  • Use consistent naming conventions across your app
On this page