Page tree
Skip to end of metadata
Go to start of metadata

How it works

The tracking code serves to collect and send visitors' data to Roistat from a website.

Firstly, the tracking code should be placed on each web page you wish to track. Having added the tracking code will set the roistat_visit variable containing a visit ID into the cookie. Once you have successfully installed it on your website, the Promo Code functionality will be available.

Secondly, it's necessary to customize deal export from Roistat to Custom CRM by adding the value of the roistat_visit cookie to the deal. We developed an easy-to-manage module for data export. It won't take you a lot to set it up.

In summary, when a visitor creates some request on your website, a new deal is created and characterized among others by the visit ID (the roistat_visit variable) contained in the roistat field. Otherwise, if a client is calling, a manager asks him/her for a promotional code and puts it down to a deal card.

Step 1. Set up tracking code

To view the Roistat tracking code, navigate to Settings  Tracking Code:

Insert the code between the <body></body> tag of your web pages. It can be placed next to the Google Analytics counter or any others.

The tracking code must be placed into the HTML code of every page of your website.

Consequently, all visits will be counted and analyzed in Analytics.

Do not insert more than one counter in a page to prevent inaccurate data entry.

When the tracking code has been installed, it will be displayed for the users as a promo code on your website. It is used for call tracking.

To view and customize the style of the promo code form, click the Promocode appearance settings link or navigate to Calltracking Promo Code.

Refer to Promo Code documentation to learn how you can set up the promo code form.

Step 2. Add roistat field to your CRM

Every deal must be associated to a site visit. To do this, add the roistat field to your CRM deals.

Refer to any other integration guides to learn how to add the roistat field.

Step 3. Configure deals import from your site to a CRM

With Roistat you can send your deals directly to your CRM.

A new deal will be sent to your CRM with the roistat field value copied from the cookie field roistat_visit.

Refer to Integrate with CRM to learn how you can configure deals import to a CRM.

Verify the integration

When a client creates some request on your website, a new deal is created in a CRM and characterized among others by the roistat field. The field must be non-empty.

Step 4. Create a page to export deals

You should create a page that would export deals data in JSON format after having received the GET request with the parameters.

The Roistat server makes a GET request:


The GET request parameters are listed below:

dateThe date since which clients data will be exported (the UNIX-time format)

Username (specified in the integration settings)

tokenmd5 ( $username . $password )
actionAction type

Statuses and other deal parameters must be exported if changed: new status, new price or new values of additional fields.


The response formats:

  JSON format example
	"fields": [
		{"id": "1", "name": "Delivery method"},
		{"id": "2", "name": "Manager"}
    "statuses": [
        {"id": "1", "name": "New"},
        {"id": "2", "name": "Processing"}
    "orders": [
            "id": "123",
			"name": "New deal",
            "date_create": "1393673200",
            "status": "0",
            "price": "2331",
            "cost": "1220",
            "roistat": "3121512",
			"client_id": "1",
            "fields": {
                "Delivery method": "Collection by a customer",
                "Manager": "John Doe"
            "id": "124",
            "date_create": "1393673220",
            "status": "1",
            "price": "4123",
            "cost": "2220",
            "roistat": "3121514",
			"client_id": "2",
            "fields": {
                "1": "Courier delivery",
                "2": "Jane Doe"
 XML format example
		  <name>Payment received</name>
		  <name>New deal</name>
		  <date_create>2014-09-01 23:58:12</date_create>


Types of array objects are not essential; usually they are str, int. The float type is often used for order price or first cost.

The statuses array contains the parameters of statuses for all orders (id, name).

The statuses array objects are listed below:

idStatus ID. Used in the orders array
nameHuman readable status name. Used in the Roistat interface

The orders array contains deals data updated within a specified time interval from date (a GET-parameter that we've sent) to the current date.

The orders array objects are listed below:

ObjectDescriptionRequired object
idStatus IDYes
nameHuman readable status name. Used in the Roistat interfaceNo
date_createDeal creation date in the format: UNIX-time or YYYY-MM-DD HH:MMYes
statusStatus ID from the statuses arrayYes
priceDeal price Used to calculate Revenue in RoistatNo
costDeal first cost Used for First cost in RoistatNo

Visit number that is associated to a deal. The value of the roistat_visit cookie. Used to trace

the deal source

client_idClient IDNo
fieldsOptional field that contains an array with additional deal fieldsNo

Below is an example of PHP code supposing it was exported from the database:

// If you want to restrict access to the page, setup username and password
$user     = 'login';
$password = 'password';
$token = isset($_GET['token']) ? $_GET['token'] : null;
if ($token !== md5($user.$password)) {
    exit('Invalid token');
//The date parameter is applied to filter deals by update date. It is sent from the Roistat server
$editDate = isset($_GET['date']) ? (int)$_GET['date'] : time() - 31*24*60*60;
$response = array('orders' => array(), 'statuses' => array());
$query = "SELECT * FROM `orders` WHERE `edit_date` > {$editDate}";
$dbResult = $db->query($query);
foreach ($dbResult as $row) {
    $response['orders'][] = array(
        'id'            => $row['id'],      //deal ID
		'name'          => $row['order_name'], // Human readable status name. Used in the Roistat interface
        'date_create'   => $row['date_create'], //deal creation date
        'status'        => $row['status'],  //order status ID
        'price'         => $row['price'],   //order price
        'cost'          => $row['cost'],    //it's an optional field; order first cost, used to calculate ROI
        'roistat'       => $row['roistat'], //user ID from the Roistat server; it's included into deal data, from the 'roistat_visit' cookie
		'client_id'     => $row['client_id'], //ID of the user who placed the order (Contact) 
        'fields'        => array(   //optional field, contains custom fields to describe a deal
            'delivery method' => $row['delivery_type'],
//add description of the statuses
$query = "SELECT * FROM `statuses`";
$dbResult = $db->query($query);
foreach ($dbResult as $row) {
    $response['statuses'][] = array(
        'id'    => $row['id'],
        'name'  => $row['name'],
echo json_encode($response);

Step 5. Create a page to export clients

The same link which is used to export deals data can be applied to export clients’ data. The Roistat server makes the similar GET request, only the action=export_clients parameter is different:


The GET request parameters are listed below:

dateThe date since which clients’ data will be exported (the UNIX-time format)
userUsername (specified in the integration settings)
tokenmd5 ( $username . $password )
actionAction type: export_clients

The response format:
 JSON format example
	"clients": [
			"id": "1",
			"name": "John Doe",
			"phone": "71111111111",
			"email": "john@client.com",
			"company": "Company1",
			"birth_date": "1990-04-15",
			"fields": {
				"Troublesome": "Yes",
				"Manager": "Mr Smith"
			"id": "2",
			"name": "Jane Doe",
			"phone": "3311111111, 3311111222",
			"email": "jd@books.com, inbox@books.com",
			"company": "",
			"birth_date": "1828-02-08",
			"fields": {
				"Manager": "Mrs Smith"
 XML format example
			<name>John Doe</name>
				<Manager>Mr Smith</Manager>
			<name>Jane Doe</name>
			<phone>3311111111, 3311111222</phone>
				<Manager>Mrs Smith</Manager>

The clients array objects are listed below:

ObjectDescriptionRequired object
idClient IDYes
nameClient nameYes
phonePhone numberYes
emailE-mail addressYes
companyCompany nameNo
birth_dateDate of birth (in the Y-m-d format)No
fieldsOptional field that contains an array with extra deal fieldsNo

Step 6. Configure deals upload

Now, you should integrate Roistat with the page that store your CRM deals data.

To do this, open SettingsIntegrations and select Custom from the Available integrations drop-down menu.

Then specify access to your system:

Page URL: full URL used to upload deals from your CRM.

Login and Password: specify the login and password to access the upload page if needed.

If you fill in these fields, Roistat will add the token parameter when accessing the URL from the Page URL field, where $token = md5($user.$password);

Verify the integration

After you click the Save button, all deal statuses from the statuses array (see Step 4) will be displayed in the Status groups section.

Step 7. Arrange statuses

Once your CRM have integrated with Roistat, you'll need to arrange the statuses uploaded:

  • Not registered: waste leads or duplicate deals. Do not delete such deals to provide reliable statistics.  You can gather them all in one status, e.g. Waste.

  • Processing: deals being in process, not completed, e.g. negotiations or product packaging.

  • Paid: deals that are paid or very likely to be paid.

  • Rejected: when a client rejects the purchase or requests a refund.

Just drag and drop a status to the box you wish.

Do not import the status to Roistat in case you want it to be classified as Not registered.

Roistat will track your achievements (the Paid group) and forecast possible achievements (the Processing and Paid groups) basing on the grouping principle.

  • No labels