Server-side Tracking

Sending orders via a JSON webhook

Another way to report orders to us is by creating a Webhook. Usually this option requires a greater amount of development work since you’ll be “posting” order information to us directly from your server.

There are two requirements for this implementation:

  1. Sending us a cart_id using a short JavaScript code on your “thank you” page so that we may reference any future Webhook reported to the session.
  2. An HTTP POST of the actual order information from your server, which contains the previously reported cart_id.

The cart_id value

When we receive any Webhooks, we must associate it with a previously captured browser session. However, since Webhooks are reported from the server-side and not the browser-side, we can not access the relevant customer’s session information. For this reason, we use the cart_id value as a common identifier that we can reference. We ask you to report a cart_id on your “thank you” page where we store session information and then a second time in the Webhook so that we may associate it with the aforementioned browser session from the JavaScript call.

Simple chart of thank you and cart pages linked with arrows pointing to cart ID and saying it must match on both

The cart_id may be any string value up to 255 characters.

For security, make sure that cart_id is not sequential or may be easily guessed such as a session ID or an encrypted version of several strings.


<script src="//"></script>
<script>_refersion(function(){ _rfsn._addCart("YOUR-CART-ID"); });</script>

You must replace pub_0123456787DEMO.js you your account’s public API key. You must also replace “YOUR-CART-ID” with the actual cart_id value from your site. Please make sure to include the double quotes.

In order to function properly, the click tracking code described in Step 1 and this code must run on the same domain and security level (http/https).

Posting the Webhook

Data must be reported as JSON string which contains the order data as well as the cart_id. You Refersion API keys (public and secret) should be sent in the header of the request.

Please visit our Orders API reference for more information on sending order webhooks to Refersion.