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

Link to this type error_map() View Source
error_map() :: %{required(String.t()) => String.t()}
Link to this type result() View Source
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

Link to this function create_account(data, opts \\ []) View Source
create_account(map(), Keyword.t()) :: result()

Register a $create_account Event with Sift Science

Parameters

  • data: The account data that should be sent to Sift Science
  • opts: 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{}}
Link to this function create_listing(data, opts \\ []) View Source
create_listing(map(), Keyword.t()) :: result()

Reports a create_content.listing event to Sift Science

Parameters

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{}}
Link to this function create_message(data, opts \\ []) View Source
create_message(map(), Keyword.t()) :: result()

Register a $create_content.$message Event with Sift Science

Parameters

  • data: The message data that should be sent to Sift Science
  • opts: 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{}}
Link to this function purge_empty(record) View Source
purge_empty(map() | list()) :: map()

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}]}}
Link to this function update_account(data, opts \\ []) View Source
update_account(map(), Keyword.t()) :: result()

Register an $update_account Event with Sift Science

Parameters

  • data: The account data that has been updated
  • opts: 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{}}
Link to this function update_listing(data, opts \\ []) View Source
update_listing(map(), Keyword.t()) :: result()

Reports an $update_content.$listing event to Sift Science

Parameters

  • data: The data for the updated listing
  • 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{}}
Link to this function update_message(data, opts \\ []) View Source
update_message(map(), Keyword.t()) :: result()

Register an $update_content.$message Event with Sift Science

Parameters

  • data: The message data that should be sent
  • opts: 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{}}