# Create an offer event

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


The Create Offer Event API records user interactions with an offer for tracking and analytics purposes.  
Use this API to log user-triggered engagement events such as:

-   `viewed` - when an offer is displayed to the user.
-   `dismissed` - when the user closes or ignores the offer. These events are essential for accurate offer performance reporting and funnel analysis. Make sure to send them as they happen.

**Note:** System-driven events like accepted and fulfilled are captured automatically by the growth system through fulfillment workflows. You do not need to post these.

## Sample Request

#### cURL

```bash
curl  https://{site}.grow.chargebee.com/api/v2/offer_events \
     -u {site_api_key}:\
     --header 'Content-Type: application/json;charset=UTF-8' \
     --data '{
     "type": "viewed",
     "personalized_offer_id": "a52ge40b"
}'
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = OfferEvent.OfferEvents()
		.Type(OfferEvent.TypeEnum.Viewed)
		.PersonalizedOfferId("a52ge40b")
		.Request();
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    offereventAction "github.com/chargebee/chargebee-go/v3/actions/offerevent"
    "github.com/chargebee/chargebee-go/v3/models/offerevent"
    offerEventEnum "github.com/chargebee/chargebee-go/v3/models/offerevent/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := offereventAction.OfferEvents(&offerevent.OfferEventsRequestParams{
        Type : offerEventEnum.TypeViewed,
        PersonalizedOfferId : "a52ge40b",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println(res)
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.OfferEventOfferEventsRequest{
    Type : chargebee.OfferEventTypeViewed,
    PersonalizedOfferId : "a52ge40b",
}
  res, err := client.OfferEvent.OfferEvents(req)
      if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println(res)
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = OfferEvent.offerEvents()
            .type(OfferEvent.Type.VIEWED)
            .personalizedOfferId("a52ge40b")
            .request();

        OfferEvent offerEvent = result.offerEvent();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.offerEvent.params.OfferEventsParams;
import com.chargebee.v4.models.offerEvent.responses.OfferEventsResponse;

public class OfferEvents {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        OfferEventsParams params = OfferEventsParams.builder()
            .type(OfferEventsParams.Type.VIEWED)
            .personalizedOfferId("a52ge40b")
            .build();

        OfferEventsResponse response = client.offerEvents().offerEvents(params);

        System.out.println(response);
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.offerEvent.offerEvents({
        type: "viewed",
        personalized_offer_id: "a52ge40b"
    });

    console.log(result);
    const offerEvent = result.offer_event;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->offerEvent()->offerEvents([
    "type" => "viewed",
    "personalized_offer_id" => "a52ge40b"
]);
$offerEvent = $result->offer_event;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.OfferEvent.offer_events(
    cb_client.OfferEvent.OfferEventsParams(
        type=chargebee.OfferEvent.Type.VIEWED,
        personalized_offer_id="a52ge40b"
    )
)
print(response)
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::OfferEvent.offer_events({
  :type => "VIEWED",
  :personalized_offer_id => "a52ge40b"
})
```

## URL Format

**POST** https://[site].grow.chargebee.com/api/v2/offer_events

## Input Parameters

- `personalized_offer_id` (required, string, max chars=50)
  The ID of the personalized offer the event pertains to.

- `type` (required, enumerated string)
  The type of engagement event to be recorded.
  Possible enum values:
    - `viewed`
      Logged when the user's UI renders or displays the offer
    - `dismissed`
      Logged when the user closes or ignores the offer without accepting

