Usage Tracking Demo

This demo shows how to track usage events with Usagey. Fill out the form below to send a usage event.

Track Usage Event

Metadata (Optional)

Result

Submit the form to see the result

How It Works

This demo uses the Usagey SDK to track usage events. The implementation follows these steps:

  1. Import the trackEvent function from our client library
  2. Collect event details through a form (event type, quantity, metadata)
  3. Call trackEvent() with the provided parameters
  4. Display the API response, which includes confirmation and usage statistics

Server-Side Code Example

const { trackEvent } = require('../lib/usagey-client');

// Route handler
router.post('/track', async (req, res) => {
  try {
    const { event_type, quantity = 1, metadata = {} } = req.body;
    
    // Track a usage event
    const result = await trackEvent(
      event_type,   // Event type
      quantity,     // Quantity
      metadata      // Optional metadata
    );
    
    res.status(200).json(result);
  } catch (error) {
    res.status(500).json({ error: error.message });
  }
});