BentoSdk.Events (BentoSDK v0.1.0)
View SourceFunctions for tracking events in Bento.
The Events API allows you to track user behavior and trigger automations in Bento. Events will create new users if they don't already exist in your account.
Summary
Functions
Import events in bulk.
Track an event for a subscriber.
Validates event details. Raises an ArgumentError if the details are invalid.
Validates an email address. Raises an ArgumentError if the email is invalid.
Validates an event. Raises an ArgumentError if the event is invalid.
Validates event fields. Raises an ArgumentError if the fields are invalid.
Validates an event type. Raises an ArgumentError if the type is invalid.
Functions
Import events in bulk.
Parameters
events
- A list of event maps, each with the following keys:email
- The email address of the subscribertype
- The type of eventfields
- Key-value pairs of data for the event (optional, should not be nested)details
- Key-value pairs of data for the event (optional, can be nested)
Examples
BentoSdk.Events.import_events([
%{
email: "user1@example.com",
type: "page_viewed",
fields: %{
"page" => "/products",
"referrer" => "https://google.com"
}
},
%{
email: "user2@example.com",
type: "$purchase",
fields: %{
"first_name" => "Jane"
},
details: %{
"value" => %{
"currency" => "USD",
"amount" => 4999
}
}
}
])
{:ok, %{
"results" => 2,
"failed" => 0
}}
Track an event for a subscriber.
Parameters
email
- The email address of the subscribertype
- The type of event (e.g., "page_viewed", "product_added_to_cart")fields
- Key-value pairs of data for the event (should not be nested)details
- Key-value pairs of data for the event (can be nested)
Examples
# Basic event
BentoSdk.Events.track("user@example.com", "page_viewed")
{:ok, %{
"results" => 1,
"failed" => 0
}}
# Event with fields
BentoSdk.Events.track(
"user@example.com",
"page_viewed",
%{
"page" => "/products",
"referrer" => "https://google.com"
}
)
{:ok, %{
"results" => 1,
"failed" => 0
}}
# Complex event with fields and details
BentoSdk.Events.track(
"user@example.com",
"$purchase",
%{
"first_name" => "Jesse"
},
%{
"unique" => %{
"key" => "order_123"
},
"value" => %{
"currency" => "USD",
"amount" => 8000
},
"cart" => %{
"items" => [
%{
"product_sku" => "SKU123",
"product_name" => "Test Product",
"quantity" => 1
}
],
"abandoned_checkout_url" => "https://example.com/cart"
}
}
)
{:ok, %{
"results" => 1,
"failed" => 0
}}
Validates event details. Raises an ArgumentError if the details are invalid.
Parameters
details
- The event details to validate
Validates an email address. Raises an ArgumentError if the email is invalid.
Parameters
email
- The email address to validate
Validates an event. Raises an ArgumentError if the event is invalid.
Parameters
event
- The event to validate
Validates event fields. Raises an ArgumentError if the fields are invalid.
Parameters
fields
- The event fields to validate
Validates an event type. Raises an ArgumentError if the type is invalid.
Parameters
type
- The event type to validate