<img src="https://secure.leadforensics.com/84962.png" style="display:none;">

Event tracking

When users interact with the products, the site must notify the engine of this, partly in order for it to learn from the users, but also to provide statistics and metrics. You do this by creating a request to "CreateEvents" and provide a collection of event objects. There are generally 3 types of events (although more can be configured in custom implementations):

  • Click
  • AddToCart
  • Purchase

How it works

When a user searches with Loop54, the user ID (as provided by the request, se Libraries for more info) is recorded in an engine table, along with the search query and the products that were presented.  

When a subsequent event is recieved by the engine, it performs a lookup in the table to find which previous search query is most probable to be the search query that led to the event. The engine does this using different heuristics such as what products were displayed, time between search and event, and HTTP data like Referer and Url. This way, the engine kan count the number of clicks, purchases etc for each product given a search query, both aggregated and personalized.

Code examples
SHOW INSTRUCTIONS FOR: PHP JSON JAVA .NET
//click event (can be called on the product page)
$e = new Loop54_Event();
$e->type = "Click";
$e->entity = new Loop54_Entity("Product", "1");
$request = new Loop54_Request("CreateEvents");
$request->setValue("Events",array($e));
$response = Loop54_RequestHandling::getResponse("http://helloworld.54proxy.com", $request);
if (!$response->success)
{
    echo $response->requestId; //log this
}
//addtocart event (call this when a customer adds a product to cart)
$e = new Loop54_Event();
$e->type = "AddToCart";
$e->entity = new Loop54_Entity("Product", "1");
$request = new Loop54_Request("CreateEvents");
$request->setValue("Events",array($e));
$response = Loop54_RequestHandling::getResponse("http://helloworld.54proxy.com", $request);
if (!$response->success)
{
    echo $response->requestId; //log this
}
//purchase events (can be called when an order is processed, or on the "thank you" page)
$productLine = new stdClass();
$productLine->productId="1";
$productLine->quantity=5;
$products = array($productLine);

//create one event for each unique product in the order
$events = array();
foreach($products as $productLine)
{
    $e = new Loop54_Event();
    $e->type = "Purchase";
    $e->orderId = "13t09j1g";    
    $e->quantity = $productLine->quantity;
    $e->entity = new Loop54_Entity("Product", $productLine->productId); //1

    $events[]=$e;
}
$request = new Loop54_Request("CreateEvents");
$request->setValue("Events",$events);
$response = Loop54_RequestHandling::getResponse("http://helloworld.54proxy.com", $request);
if (!$response->success)
{
    echo $response->requestId; //log this
}
//click event (can be called on the product page)
POST to helloworld.54proxy.com/createevents
{
    "UserId" : "helloworlduser",
    "IP" : "127.0.0.1",
    "Events" : [{
            "Type" : "Click",
            "Entity" : {
                "EntityType" : "Product",
                "ExternalId" : "1"
            }
        }
    ]
}
//addtocart event
POST to helloworld.54proxy.com/createevents
{
    "UserId" : "helloworlduser",
    "IP" : "127.0.0.1",
    "Events" : [{
            "Type" : "AddToCart",
            "Entity" : {
                "EntityType" : "Product",
                "ExternalId" : "1"
            }
        }
    ]
}
//purchase events (can be called when an order is processed, or on the "thank you" page)
POST to helloworld.54proxy.com/createevents
{
    "UserId" : "helloworlduser",
    "IP" : "127.0.0.1",
    "Events" : [{
            "Type" : "Purchase",
            "OrderId" : "13t09j1g",
            "Quantity" : 5,
            "Entity" : {
                "EntityType" : "Product",
                "ExternalId" : "1"
            }
        }
    ]
}
//click event (can be called on the product page)
Event clickEvent = new Event();
clickEvent.type = "Click";
clickEvent.entity = new Entity("Product", "1");
Request loopClickRequest = new Request("CreateEvents",request,response);
loopClickRequest.setValue("Events",new Event[]{clickEvent});
Response loopClickResponse = RequestHandling.getResponse("http://helloworld.54proxy.com", loopClickRequest);
if (!loopClickResponse.success)
{
    response.getWriter().print("ERROR: " + loopClickResponse.requestId); //keep track of unsuccessful requests
}
//addtocart event (call this when a customer adds a product to cart)
Event addToCartEvent = new Event();
addToCartEvent.type = "AddToCart";
addToCartEvent.entity = new Entity("Product", "1");
Request loopAddToCartRequest = new Request("CreateEvents",request,response);
loopAddToCartRequest.setValue("Events",new Event[]{addToCartEvent});
Response loopAddToCartResponse = RequestHandling.getResponse("http://helloworld.54proxy.com", loopAddToCartRequest);
if (!loopAddToCartResponse.success)
{
    response.getWriter().print("ERROR: " + loopAddToCartResponse.requestId); //keep track of unsuccessful requests
}
//purchase events (can be called when an order is processed, or on the "thank you" page)  
ProductLine[] products = new ProductLine[]{new ProductLine("1",5)}; 

//create one event for each unique product in the order
List events = new ArrayList();
for(ProductLine productLine: products)
{
    Event purchaseEvent = new Event();
    purchaseEvent.type = "Purchase";
    purchaseEvent.orderId = "13t09j1g";  
    purchaseEvent.entity = new Entity("Product", productLine.productId); //1
    purchaseEvent.quantity = productLine.quantity; //quantity of this product
    events.add(purchaseEvent);
}
Request loopPurchaseRequest = new Request("CreateEvents",request,response);
loopPurchaseRequest.setValue("Events",events);
Response loopPurchaseResponse = RequestHandling.getResponse("http://helloworld.54proxy.com", loopPurchaseRequest);
if (!loopPurchaseResponse.success)
{
    response.getWriter().print("ERROR: " + loopPurchaseResponse.requestId); //keep track of unsuccessful requests
}
//click event (can be called on the product page)
var clickEvent = new Loop54.Model.Event();
clickEvent.Type = "Click";
clickEvent.Entity = new Loop54.Model.Entity("Product", "1");

var clickRequest = new Loop54.Request("CreateEvents");
clickRequest.SetValue("Events", new[] { clickEvent });

var clickResponse = Loop54.RequestHandling.GetResponse("http://helloworld.54proxy.com", clickRequest);

if (!clickResponse.Success)
{
    Response.Write("ERROR: " + clickResponse.RequestId + Environment.NewLine);

//addtocart event (call this when a customer adds a product to cart)
var addToCartEvent = new Loop54.Model.Event();
addToCartEvent.Type = "AddToCart";
addToCartEvent.Entity = new Loop54.Model.Entity("Product", "1");

var addToCartRequest = new Loop54.Request("CreateEvents");
addToCartRequest.SetValue("Events", new[] { addToCartEvent });

var addToCartResponse = Loop54.RequestHandling.GetResponse("http://helloworld.54proxy.com", addToCartRequest);

if (!addToCartResponse.Success)
{
    Response.Write("ERROR: " + addToCartResponse.RequestId + Environment.NewLine);
}
//purchase events (can be called when an order is processed, or on the "thank you" page)  
var products = new[] {new {ProductId = "1", Quantity = 5}};

//create one event for each unique product in the order
var events = new List();
foreach (var productLine in products)
{
    var purchaseEvent = new Loop54.Model.Event();
    purchaseEvent.Type = "Purchase";
    purchaseEvent.OrderId = "13t09j1g";
    purchaseEvent.Entity = new Loop54.Model.Entity("Product", productLine.ProductId); //1
    purchaseEvent.Quantity = productLine.Quantity; //quantity of this product
    events.Add(purchaseEvent);
}
var purchaseRequest = new Loop54.Request("CreateEvents");
purchaseRequest.SetValue("Events", events);
var purchaseResponse = Loop54.RequestHandling.GetResponse("http://helloworld.54proxy.com", purchaseRequest);
if (!purchaseResponse.Success)
{
    Response.Write("ERROR: " + purchaseResponse.RequestId + Environment.NewLine);
}