Tutorials Tracking Anonymous User Activity

Tracking Anonymous User Activity

When a user takes anonymous actions

If your application uses JavaScript, add our snippet and make sure to set _user_id to the empty string.

When the anonymous user takes an action you send an Events API event for, set the $user_id value to an empty string. Set $session_id to match the value provided in the JavaScript snippet (if applicable)

Here is a sample $add_item_to_cart event:

{
  "$type"       : "$add_item_to_cart",
  "$api_key"    : "YOUR_API_KEY",
  "$session_id" : "gigtleqddo84l8cm15qe4il",
  "$user_id"    : "",     // Blank because the $user_id is still unknown          
  "$item"       : {
    // item info
  }
}
import sift

client = sift.Client(api_key='{apiKey}', account_id='{accountId}')

properties = {
  # Required Fields
  "$user_id"    : "",     #  Blank because the $user_id is still unknown
  "$session_id" : "gigtleqddo84l8cm15qe4il",
  "$item"       : {
    # item info
  }
}

response = client.track("$add_item_to_cart", properties)
require "sift"

client = Sift::Client.new(:api_key => "YOUR_API_KEY")

properties = {
  "$user_id"    => "",     # Blank because the $user_id is still unknown
  "$session_id" => "gigtleqddo84l8cm15qe4il",
  "$item"       => {
    # item info
  }
}

response = client.track("$add_item_to_cart", properties)
require 'sift-php/lib/Services_JSON-1.0.3/JSON.php';
require 'sift-php/lib/SiftRequest.php';
require 'sift-php/lib/SiftResponse.php';
require 'sift-php/lib/SiftClient.php';
require 'sift-php/lib/Sift.php';

$client = new SiftClient(array('api_key' => 'YOUR_API_KEY'));

$properties = array(
  '$user_id'    => '',      // Blank because the $user_id is still unknown
  '$session_id' => 'gigtleqddo84l8cm15qe4il',
  '$item'       => array(
    // item info
  )
);

$response = $client->track('$add_item_to_cart', $properties);

At login, account creation, or the event you need a score on

Once a user logs in, creates an account, or takes an anonymous action you need a risk assessment on (such as placing an order), send an Events API event with the same session id value you've been passing for the anonymous activity as well as a value for $user_id. In cases where you don't have a concept of a user id, you can pass another unique identifier for the entity you need a risk assessment on (e.g., email address or order/transaction id). Once we see an event with both the user and session id, we'll tie the anonymous activity together with that event.

Notes:

  • You must provide an event with a $user_id value before you can get a risk assessment.
  • If you use email as the value, you should also pass it in the $user_email field if the event has one.

Here is a sample $create_order event:

// Sample $create_order event
{
  "$type"             : "$create_order",
  "$api_key"          : "YOUR_API_KEY",
  "$user_id"          : "billy_jones_301",
  "$session_id"       : "gigtleqddo84l8cm15qe4il",
  "$order_id"         : "ORDER-28168441",
  "$user_email"       : "bill@gmail.com",
  // other fields...
}
import sift

client = sift.Client(api_key='{apiKey}', account_id='{accountId}')

properties = {
  "$user_id"          : "billy_jones_301",
  "$session_id"       : "gigtleqddo84l8cm15qe4il",
  "$order_id"         : "ORDER-28168441",
  "$user_email"       : "bill@gmail.com",
  # other fields
}

response = client.track("$create_order", properties)
require "sift"

client = Sift::Client.new(:api_key => "YOUR_API_KEY")

properties = {
  "$user_id"          => "billy_jones_301",
  "$session_id"       => "gigtleqddo84l8cm15qe4il",
  "$order_id"         => "ORDER-28168441",
  "$user_email"       => "bill@gmail.com",
  # other fields...
}

response = client.track("$create_order", properties)
require 'sift-php/lib/Services_JSON-1.0.3/JSON.php';
require 'sift-php/lib/SiftRequest.php';
require 'sift-php/lib/SiftResponse.php';
require 'sift-php/lib/SiftClient.php';
require 'sift-php/lib/Sift.php';

$client = new SiftClient(array('api_key' => 'YOUR_API_KEY'));

$properties = array(
  '$user_id'          => 'billy_jones_301',
  '$session_id'       => 'gigtleqddo84l8cm15qe4il',
  '$order_id'         => 'ORDER-28168441',
  '$user_email'       => 'bill@gmail.com',
  // other fields ...
);

$response = $client->track('$create_order', $properties);