Order tracking

Here you will find integration instructions for orders tracking. Order tracking allows us to understand whether your customers actually add to cart and checkout (order) the size we recommended.

NOTE that no sensitive customer data is accessed by Easysize nor is any sensitive data transmitted.

Requirements

Implementation

Add to cart

Whenever an item is added to cart, it should be saved in the cookies as an object with the following structure:

{
  "product_id": "<easysize_pageview_id>"
}

Where:

Here is how the cookie might look like, if the user added three items to cart:

{
  "123": 777321,
  "213": 777322,
  "321": 777323
}

Checkout

Once a purchase is made (was paid for), you should be able to access all the items that were bought. Save them to a variable (order in given example).

Also retrieve the cookie of the add to cart object you implemented before (items_added_to_cart in given example).

items_added_to_cart_keys = items_added_to_cart.keys(); // [123, 213, 321]
orders = order.items; // [<Product>,..]
order_id = order.id; // 9999

for(var i = 0; i < orders.length; i++) {
    for(var y = 0; y < items_added_to_cart_keys.length; y++) {
        if(orders[i].product_id == items_added_to_cart_keys[y]) {
             // If we get here, the item that was added to cart was actually purchased

             // We need to send a GET request to Easysize servers telling that, with the size of the item that was purchased.
             // Look below for explanation of the request query parameters

             size = orders[i].item_size;
             pageview = items_added_to_cart[items_added_to_cart_keys[y]];

             // example request url
             // https://popup.easysize.me/collect?a=24&v=Medium&pv=777321&v3=9999
        }
    }
}

In the given example we have two loops and compare whether the item that was added to cart was actually bought. If it was, we then send tracking information to Easysize servers.

Request breakdown

[GET] https://popup.easysize.me/collect

Parameters:

PHP Example

NOTE If you copy the code, do not forget to update the variables to fit to your system.

Add to cart

if($_COOKIE['espageview']) {
    if($_COOKIE['es_cart_items']) {
        $items_in_cart = json_decode($_COOKIE['es_cart_items']);
    } else {
        $items_in_cart = new stdClass();
    }

    $items_in_cart->$product['id'] = $_COOKIE['espageview']; // $product['id'] might look different in your system
    setcookie('es_cart_items', json_encode($items_in_cart), time() + 60 * 60 * 24 * 7, "/");
}

Checkout

// Get all products in order. Note that these variables might look different in your system!
$products_in_order = $_SESSION['order'];
$order_id = $_SESSION['order_id'];
$user_id = $_SESSION['user_id'];

if($_COOKIE['es_cart_items']) {
    $items_added_to_cart = json_decode($_COOKIE['es_cart_items']);
    foreach ($products_in_order as $product) {
        if($product['id'] && isset($items_added_to_cart->$product['id'])) {
            // $product['size']['name'] is the purchased item size. It might look different in your system!
            $curl = curl_init("https://popup.easysize.me/collect?a=24&v={$product['size']['name']}&v3={$order_id}&v4={$user_id}&pv={$items_added_to_cart->$product['id']}");
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_exec($curl);
            curl_close($curl);
        }
    }

    // Do not forget to remove the cookie
    unset($_COOKIE['es_cart_items']);
    setcookie('es_cart_items', '', time() - 3600, '/');
}

Remember, if you encounter a problem, reach out to us at info@easysize.me, our team is always ready to help you out!