Siftsciex v0.3.1 Siftsciex.Event View Source
The Event module is used for registering events with SiftScience.
Events are the crux of what Sift Science does, they represent user activity in your application. Things like creating a listing, or message as well as initiating a payment or signing up are all Events. Sift Science analyzes the data sent with the Events to build a Risk Score indicating how likely it is that that user is an honest agent.
When delivering Event data you can request an immediate (synchronous) risk score or you can simply deliver the data then either check the Risk score independently or setup Workflows in Sift Science which can deliver Score results to a Webhook in your application if specific criteria are met.
Currently Siftsciex
supports the following Events:
create_account
create_listing
create_message
update_account
update_listing
update_message
The Event
functions all return a Siftsciex.Event.result/0
tuple. The first element in the tuple is an atom indicative of the HTTP transport result. :ok
means that the HTTP delivery was successful (2xx HTTP response). In the case of an :ok
as the first element the second element will be a Siftsciex.Event.Response.t/0
struct.
There are several different :error
possibilities, the following are possible HTTP level errors when it comes to Siftsciex
:
:redirected
:client_error
:server_error
:transport_error
In the case of an :error
response the second element in the tuple will be one of the above and there will be a third element providing a bit more information about the specific error.
Options
All the functions in this module accept an optional opts
argument which can be used to indicate that the given Event shuld be synchronous and the specified abuse scores should be returned.
If provided options should have one key :scores
with a list of Siftsciex.Score.abuse_type/0
values indicating which scores should be returned in the response to the Event report.
Link to this section Summary
Functions
Register a $create_account
Event with Sift Science
Reports a create_content.listing
event to Sift Science
Register a $create_content
.$message
Event with Sift Science
Purges all keys with :empty
values from the given map
Register an $update_account
Event with Sift Science
Reports an $update_content
.$listing
event to Sift Science
Register an $update_content
.$message
Event with Sift Science
Link to this section Types
result() :: {:ok, Siftsciex.Event.Response.t()} | {:error, :redirected, String.t()} | {:error, :client_error, integer()} | {:error, :server_error, integer()} | {:error, :transport_error, any()}
Link to this section Functions
Register a $create_account
Event with Sift Science
Parameters
data
: The account data that should be sent to Sift Scienceopts
: See the Options section in the module description.
Examples
iex> Event.create_account(%{user_id: "bob", user_email: "bob@example.com"})
{:ok, %Siftsciex.Event.Response{}}
Reports a create_content.listing
event to Sift Science
Parameters
data
: The data for the newly created listing seeSiftsciex.Event.Content.listing_data/0
for details on the keys expected.opts
: See the Options section in the module description.
Examples
iex> Event.create_listing(%{user_id: "bob", content_id: "8", status: :draft, listing: %{subject: "Chair", contact_address: %{name: "Walt", city: "Albuquerque"}, listed_items: [%{item_id: "8", price: 3, currency_code: "USD"}]}})
{:ok, %Siftsciex.Event.Response{}}
Register a $create_content
.$message
Event with Sift Science
Parameters
data
: The message data that should be sent to Sift Scienceopts
: See the Options section in the module description.
Examples
iex> Event.create_message(%{user_id: "auth0|bob", content_id: "9f2ebfb3-7dbb-456c-b263-d985f107de07", message: %{body: "Hello"}})
{:ok, %Siftsciex.Event.Response{}}
Purges all keys with :empty
values from the given map.
Parameters
record
: The record that should be purged
Examples
iex> Event.purge_empty(%{"$type": "$create_content", "$ip": :empty})
%{"$type": "$create_content"}
iex> Event.purge_empty(%{"$type": "$create_content", "$listing": %{"$subject": "Table", "$contact_address": :empty}})
%{"$type": "$create_content", "$listing": %{"$subject": "Table"}}
iex> Event.purge_empty(%{"$type": "$create_content", "$listing": %{"$listed_items": [%{"$price": 5000000, "$currency_code": :empty}]}})
%{"$type": "$create_content", "$listing": %{"$listed_items": [%{"$price": 5000000}]}}
Register an $update_account
Event with Sift Science
Parameters
data
: The account data that has been updatedopts
: See the Options section in the module description.
Examples
iex> Event.update_account(%{user_id: "bob", user_email: "bob2@example.com"})
{:ok, %Siftsciex.Event.Response{}}
Reports an $update_content
.$listing
event to Sift Science
Parameters
data
: The data for the updated listingopts
: See the Options section in the module description.
Examples
iex> Event.create_listing(%{user_id: "bob", content_id: "8", status: :draft, listing: %{subject: "Chair", contact_address: %{name: "Walt", city: "Albuquerque"}, listed_items: [%{item_id: "8", price: 3, currency_code: "USD"}]}})
{:ok, %Siftsciex.Event.Response{}}
Register an $update_content
.$message
Event with Sift Science
Parameters
data
: The message data that should be sentopts
: See the Options section in the module description.
Examples
iex> Event.update_message(%{user_id: "auth0|bob", content_id: "9f2ebfb3-7dbb-456c-b263-d985f107de07", message: %{body: "Bye"}})
{:ok, %Siftsciex.Event.Response{}}