<img height="1" width="1" style="display:none" src="https://q.quora.com/_/ad/ad9bc6b5b2de42fb9d7cd993ebb80066/pixel?tag=ViewContent&amp;noscript=1">

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
  • Add-To-Cart
  • Purchase

How it works

When a user searches with Loop54, the user ID (as provided by the request, see Libraries for more info) is recorded in an engine table, along with the search query and the products that were presented.  
 
All libraries have built in user tracking, using cookies. We recommend that you use our libraries to automatically keep track of users. However, it is possible to use any unique string as User ID, as long as it is persistent so that the same user gets the same ID over multiple sessions. To use a custom User ID instead of the built-in ID handling, use the request parameter "UserId".

When a subsequent event is received 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 Referrer and URL. This way, the engine can 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"
            }
        }
    ]
}
The API V2X-based Java Connector is no longer supported. 
You can view code examples for the V3-based Connector at
https://github.com/LoopFiftyFour/Java-Connector
The API V2X-based .NET Connector is no longer supported.
You can view code examples for the V3-based Connector at
https://github.com/LoopFiftyFour/.NET-Connector