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 code will set the roistat_visit variable containing a visit ID into the cookie. Once you have successfully installed the tracking code on your website, the Promo Code functionality will be available.

Secondly, it's necessary to customize deal export from Roistat to amoCRM 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 completes the target action on the web page, 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 place more than one counter in a page to prevent inaccurate data entry.

Step 2. Add roistat field in amoCRM

AmoCRM deals should be characterized among others by visitor IDs in order to be linked to visits. This requires the roistat field to be added to amoCRM lead cards.

To do this, navigate to Settings Custom fields, add a new text field and name it "roistat".

 Interface before being redesigned

In amoCRM, open any lead.  Add a new field and name it "roistat":

Step 3. Configure Roistat access to amoCRM

Open SettingsIntegrations and choose amoCRM from the Available integrations drop-down menu. Click Select to save the integration type.

Enter your amoCRM project URL into the corresponding field; the URL usually looks like http://<project>.amocrm.com

Enter your amoCRM username into the corresponding field to be automatically logged in amoCRM.

Enter the API token into the API Token field for Roistat to be automatically logged in API. You can copy it from your amoCRM account settings.

 Interface before being redesigned
Open User profile and copy the key from the Use your API key for integration field.


The user account you integrate with Roistat should have the right to create deals.

Once you have specified all the information needed and saved it by clicking Save, amoCRM deal statuses will be imported to Roistat.

Step 4. Arrange statuses

Once your amoCRM has 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.

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

Step 5. Automatic deals export

 If deals are already created automatically

In this case, the roistat field should contain the value of the roistat_visit cookie.

Below is an example of the string that contains the value of this cookie:

$roistatVisitId = array_key_exists('roistat_visit', $_COOKIE) ? $_COOKIE['roistat_visit'] : "unknown"

When created deals should be automatically exported from your website to amoCRM. For this to happen, we offer you a complete solution: deal proxying.

When a deal is created on your website, it is automatically created in amoCRM as well, and a backup copy of this deal data is stored in your Roistat account. Keeping this in mind, you will not have to worry that amoCRM can be off-line sometimes. In any case, all the data is stored and then re-exported to amoCRM some time later.

To set up deal proxying, insert the following code snippet into the file that process deal forms on your website (e.g. send data to some e-mail):

// Data should be encoded in UTF-8! Otherwise it can cause an error.
// If Windows-1251 is used, you can convert all variables through $value = iconv("Windows-1251", "UTF-8", $value);
// Or you can specify the encoding of your website through the 'charset' key, in additional fields; the Roistat server will convert all data from the encoding specified to UTF-8.
// ...
// the current lead creation function, e.g. mail(), is called somewhere here
// ...
$roistatData = array(
 'roistat' => isset($_COOKIE['roistat_visit']) ? $_COOKIE['roistat_visit'] : null,
 'key'  => 'SECRET_KEY', // Instead of SECRET KEY insert the secret key itself which you can copy by clicking the Integration key: show link at the bottom of the page Settings -> Integrations -> amoCRM
 'title'   => 'Deal title',
 'comment' => 'Deal commentary',
 'name' => 'Client's name',
 'email'   => 'client@email.com',
 'phone'   => '79111234567',
 'fields'  => array(
 // An  array with some additional fields if needed or just an empty array.
 // Examples:
        "price" => 123, // The budget field in amoCRM
        "responsible_user_id" => 3, // A person responsible for a deal
        "1276733" => "Тext" // A custom field with ID=1276733
 // For more detailed information please read the amoCRM developers documentation: https://developers.amocrm.ru/rest_api/#lead
 // You can consult our support service about amoCRM custom fields as well.
        "charset" => "Windows-1251", // The server will convert fields' values from the encoding specified to UTF-8
file_get_contents("https://cloud.roistat.com/api/proxy/1.0/leads/add?" . http_build_query($roistatData));

Verify the integration

When a client completes some target action (completes application form, places an order etc.), a new deal is created in amoCRM and characterized among others by the roistat field. The field must be non-empty.

You can view deals from Roistat as well by clicking the corresponding link:

  • No labels