> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stigg.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Reporting raw events

## Overview

A raw usage event typically corresponds to a user-triggered action or measurement from an underlying infrastructure.

When raw events are reported by your application, **Stigg** does the heavy lifting of filtering events and aggregating them to calculate customer usage.

## Dimensions

Reported events should include properties that are required for the filtering and aggregation of those events, referred to in Stigg as **dimensions**.

Event *metadata* can also be reported as an event dimension. There's no limit on the number of dimensions that can be reported on each event; therefore, we encourage you to include as much metadata as possible in reported events to have maximum flexibility on how usage is calculated. Including these dimensions as part of the initial integration will prevent the need to backfill them at later date.

Example dimensions include:

* Cloud region - i.e. us-east-1, eu-central-1, etc.
* Environment - i.e. production, development, etc.
* Compute type - i.e. read, write, etc.

## Event schema

| Field name     | Required                                                               | Type                                       | Description                                                                                                                                    |
| -------------- | ---------------------------------------------------------------------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| idempotencyKey | ✅                                                                      | String                                     | A unique key that's used to ensure that the event is only processed once.                                                                      |
| customerId     | ✅                                                                      | String                                     | The ID of the customer that usage is reported for.                                                                                             |
| resourceId     | Yes, when reporting an event for a product with multiple subscriptions | String                                     | The ID of the resource that the event is reported for. This is mostly relevant when reporting events for products with multiple subscriptions. |
| eventName      | ✅                                                                      | String                                     | The name of that event that's being reported, which usually represents that action that took place.                                            |
| dimensions     | ❌                                                                      | Hash\<String, String \| Number \| Boolean> | User-defined properties about the event, i.e. "region" : "us-east-1"                                                                           |
| timestamp      | ❌                                                                      | Timestamp                                  | The timestamp of the event. When not provided, the Stigg server time (UTC) will be used.                                                       |

<Note>
  The maximum payload size for a raw event is **1 MB**.
</Note>

## Ingestion methods

<Tabs>
  <Tab title="REST API">
    <Card title="REST SDKs" href="/api-and-sdks/api-reference/rest/events-report" horizontal icon="code">
      Send usage data using REST SDKs available for TypeScript, Python, Go, Ruby, C#, and Java.
    </Card>

    <Card title="REST API: Report Events" href="/api-and-sdks/api-reference/rest/events-report" horizontal icon="server">
      Send raw usage events via the REST API.
    </Card>
  </Tab>

  <Tab title="GraphQL (legacy)">
    <Card title="Node.js: Reporting Usage" href="/api-and-sdks/integration/backend/nodejs#reporting-usage-measurements-to-stigg" horizontal>
      <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
        <div
          style={{
        width: 28,
        height: 28,
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        flex: '0 0 28px',
      }}
        >
          <img
            src="https://mintcdn.com/stigg/RZ91VrR8WK9exrsp/images/docs/d96f126-Node.js_logo.svg?fit=max&auto=format&n=RZ91VrR8WK9exrsp&q=85&s=9b69b016f6c0715254fcc864d261f86f"
            alt="Node.js"
            width="28"
            height="28"
            style={{
          display: 'block',
          maxWidth: '100%',
          maxHeight: '100%',
          objectFit: 'contain',
        }}
            data-path="images/docs/d96f126-Node.js_logo.svg"
          />
        </div>

        <span>Send usage data using the Node.js SDK.</span>
      </div>
    </Card>

    <Card title="Python: Reporting Usage" href="/api-and-sdks/integration/backend/python#reporting-usage-measurements-to-stigg" horizontal>
      <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
        <div
          style={{
        width: 28,
        height: 28,
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        flex: '0 0 28px',
      }}
        >
          <img
            src="https://mintcdn.com/stigg/FdQMosJ2Bzlx8vcI/images/docs/7469835-python-original.png?fit=max&auto=format&n=FdQMosJ2Bzlx8vcI&q=85&s=5aafc0be4f9d8245bec7a6910babe3bd"
            alt="Python"
            width="28"
            height="28"
            style={{
          display: 'block',
          maxWidth: '100%',
          maxHeight: '100%',
          objectFit: 'contain',
        }}
            data-path="images/docs/7469835-python-original.png"
          />
        </div>

        <span>Send usage data using the Python SDK.</span>
      </div>
    </Card>

    <Card title="Ruby: Reporting Usage" href="/api-and-sdks/integration/backend/ruby#reporting-usage-measurements-to-stigg" horizontal>
      <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
        <div
          style={{
        width: 28,
        height: 28,
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        flex: '0 0 28px',
      }}
        >
          <img
            src="https://mintcdn.com/stigg/rbfzdbhZ6y5pB9n-/images/docs/9705d6b-ruby-original.png?fit=max&auto=format&n=rbfzdbhZ6y5pB9n-&q=85&s=06c498ccef5cf0868a1393dcc0a1ec77"
            alt="Ruby"
            width="28"
            height="28"
            style={{
          display: 'block',
          maxWidth: '100%',
          maxHeight: '100%',
          objectFit: 'contain',
        }}
            data-path="images/docs/9705d6b-ruby-original.png"
          />
        </div>

        <span>Send usage data using the Ruby SDK.</span>
      </div>
    </Card>

    <Card title="Go: Reporting Usage" href="/api-and-sdks/integration/backend/go#reporting-usage-measurements-to-stigg" horizontal>
      <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
        <div
          style={{
        width: 28,
        height: 28,
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        flex: '0 0 28px',
      }}
        >
          <img
            src="https://mintcdn.com/stigg/zZAY_sXPTSVMcwio/images/docs/ccb79d0-go-original-wordmark.png?fit=max&auto=format&n=zZAY_sXPTSVMcwio&q=85&s=fca43821e3669faf1be1157cc5d235a8"
            alt="Go"
            width="28"
            height="28"
            style={{
          display: 'block',
          maxWidth: '100%',
          maxHeight: '100%',
          objectFit: 'contain',
        }}
            data-path="images/docs/ccb79d0-go-original-wordmark.png"
          />
        </div>

        <span>Send usage data using the Go SDK.</span>
      </div>
    </Card>

    <Card title="GraphQL: Reporting Usage" href="/api-and-sdks/integration/backend/graphql#reporting-usage-measurements-to-stigg" horizontal>
      <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
        <div
          style={{
        width: 28,
        height: 28,
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'center',
        flex: '0 0 28px',
      }}
        >
          <img
            src="https://mintcdn.com/stigg/fP4soQQ7PxwZeQ0V/images/docs/e088aed-image.png?fit=max&auto=format&n=fP4soQQ7PxwZeQ0V&q=85&s=07e5bfb75fc24b7916389b826ea73585"
            alt="GraphQL"
            width="28"
            height="28"
            style={{
          display: 'block',
          maxWidth: '100%',
          maxHeight: '100%',
          objectFit: 'contain',
        }}
            data-path="images/docs/e088aed-image.png"
          />
        </div>

        <span>Send usage data via the GraphQL API.</span>
      </div>
    </Card>
  </Tab>
</Tabs>

### Cloud

<Card title="Amazon S3: Ingestion" href="./ingestion-from-cloud-storage" horizontal>
  <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
    <div
      style={{
    width: 28,
    height: 28,
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    flex: '0 0 28px',
  }}
    >
      <img
        src="https://mintcdn.com/stigg/fP4soQQ7PxwZeQ0V/images/docs/f0203a7-Amazon-S3-Logo.svg.png?fit=max&auto=format&n=fP4soQQ7PxwZeQ0V&q=85&s=c459c9b17b49d3acdf06e2f0c9f96422"
        alt="Amazon S3"
        width="28"
        height="28"
        style={{
      display: 'block',
      maxWidth: '100%',
      maxHeight: '100%',
      objectFit: 'contain',
    }}
        data-path="images/docs/f0203a7-Amazon-S3-Logo.svg.png"
      />
    </div>

    <span>Ingest usage data from Amazon S3.</span>
  </div>
</Card>

<Card title="Google Cloud Pub/Sub: Ingestion" href="./ingestion-from-gcp" horizontal>
  <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
    <div
      style={{
    width: 28,
    height: 28,
    display: 'flex',
    alignItems: 'center',
    justifyContent: 'center',
    flex: '0 0 28px',
  }}
    >
      <img
        src="https://mintcdn.com/stigg/KDLt6IBFr9faql2Z/images/docs/060018d-google-cloud-pub-sub-logo.svg?fit=max&auto=format&n=KDLt6IBFr9faql2Z&q=85&s=184e590a3f2869cb918ac26279b32d6d"
        alt="Google Cloud Pub/Sub"
        width="28"
        height="28"
        style={{
      display: 'block',
      maxWidth: '100%',
      maxHeight: '100%',
      objectFit: 'contain',
    }}
        data-path="images/docs/060018d-google-cloud-pub-sub-logo.svg"
      />
    </div>

    <span>Ingest usage data from Google Cloud Pub/Sub.</span>
  </div>
</Card>

## Supported aggregation methods

Stigg currently supports the following aggregation methods:

1. Count
2. Count unique
3. Sum
4. Maximum
5. Minimum
6. Average

All aggregation methods besides `count` require you to specify the [dimension](#dimensions) that will be used for the aggregation, for example: when calculating a `sum` using what dimension the sum will be calculated.

## Event deduplication

To prevent duplicate event ingestion, we've implemented a deduplication process that ensures each unique event is counted only once, removing any concerns when reporting events and assuring accurate data ingestion.

Two events are considered duplicates when **all** of the following properties match:

1. Timestamp
2. Customer ID
3. ResourceID
4. Event name
5. Idempotency key

## Example use-cases

### Active users

When a customer logs into your application or performs an action, report an event to Stigg with the customer ID. If you already leverage an analytics solution, this can be a simple as reporting an event to Stigg whenever the `track` method of the analytics solution is called.

[Create an event-based metered feature](../../modeling-your-pricing-in-stigg/features/creating-features/metered-features), and select the `count unique` aggregation method while specifying the `customerId` property as the dimension that will be used for computation of the aggregation.

### Used bandwidth

Whenever a resource is accessed, report an event to Stigg with the resource file size dimension.

[Create an event-based metered feature](../../modeling-your-pricing-in-stigg/features/creating-features/metered-features), and select the `sum` aggregation method while specifying the resource file size property as the dimension that will be used for computation of the aggregation.
