Skip to content

Tracking Code Installation

About Tracking Code

The tracking code allows you to collect data about user visits to the website: advertising source, keyword, landing page, city, device, browser, page where the lead was generated, and some other parameters. The tracking code associates all these parameters with the visit number assigned to each website visitor. How does it work? The tracking code sets the roistat_visit parameter in the visitor's browser cookie. Each unique visitor is assigned a unique visit number, which is passed to the roistat_visit variable.

All cookies used by Roistat are specific to the domain you are working with and are not considered third party cookies. Restrictions related to the use of third-party cookies do not affect the operation of the service.

Also, the tracking code is required for the operation of the Lead Hunter and Calltracking.

The tracking code data is used for analytics in Roistat. All visits to the website are recorded by the tracking code and displayed in the Analytics section. However, until you connect an advertising channel and CRM to your project, reports will only contain basic information about visits (landing page, city, device, etc.) and the Visits indicator. Other indicators are calculated based on data from CRM and advertising platforms.

The Roistat tracking code runs in the background and does not affect the website loading speed.

How to Find the Tracking Code

The tracking code is displayed in the Settings section on the Tracking code tab:


The tracking code contains a key that is unique for each project. It is located in the following line: (window, document, 'script', '', 'tracking code key'). The key from the tracking code cannot be deleted in the Roistat interface.

If you installed the tracking code on a website that is not related to your Roistat project, you can do one of the following:

  • Create a ticket to delete the key, if this key is a part of your tracking code.
  • If the key is additional, delete it in the Roistat interface.
  • Add the website URL to the blacklist.

Roistat has a European IP mirror: If you need to use it, replace with in the tracking code:

(function(w, d, s, h, id) {
    w.roistatProjectId = id; w.roistatHost = h;
    var p = d.location.protocol == "https:" ? "https://" : "http://";
    var u = /^.*roistat_visit=[^;]+(.*)?$/.test(d.cookie) ? "/dist/module.js" : "/api/site/1.0/"+id+"/init?referrer="+encodeURIComponent(d.location.href);
    var js = d.createElement(s); js.charset="UTF-8"; js.async = 1; js.src = p+h+u; var js2 = d.getElementsByTagName(s)[0]; js2.parentNode.insertBefore(js, js2);
})(window, document, 'script', '', 'tracking code key');

After replacing the tracking code, data will continue to be sent to your project. To work in the project, you can use both the standard address and the mirror

How to Install the Tracking Code on the Webite

There are three ways to install the Roistat tracking code on the website:

  • Add the tracking code to the source code of the website manually.
  • Add the tracking code using the CMS interface or website constructor.
  • Add the tracking code using the Google Tag Manager.

Please note:

Make sure the tracking code is not inside <noscript></noscript> tags. Otherwise, the code will not work.

If the Webiste Is Self-Hosted

Place the tracking code in the source code of the site pages before the closing </body> tag. The tracking code must be added on all pages where you want to collect data.


Please note:

  • In order for the data to be collected correctly, do not install more than one tracking code on the website pages.
  • Some websites and website builders (such as CMS systems or GTM) do not allow you to change the <body> tag. In this case, add the Roistat tracking code inside the <head> tag.

If the Website Is Made Using CMS

In CMS, the tracking code is often added to the field for user scripts or to special files.

The path to the required file or field usually looks like this: Administrator panel → System → Design / Configuration / Template → Settings.

Example for Magento CMS:


If the Website Is Made in a Website Builder

In the landing page builders, the tracking code can be added in the settings or in the landing editor.

  • Go to the landing page settings and find the section called tracking code, counters, or scripts.

    If there is no such section in the settings, add the tracking code in the landing editor.

  • Open the landing editor and add a code block. Find an object with the words HTML block, script. Add the tracking code to the appropriate block.

If You Use Google Tag Manager

  1. Make sure you have created a container for your site in Google Tag Manager. Open container settings in your account:


  2. In the New tag block, click Add a new tag:


  3. Click on the Tag Configuration block and select the Custom HTML tag type:


  4. In the HTML field, paste the tracking code:


    Please note:

    Make sure the tracking code is not inside <noscript></noscript> tags. Otherwise, the code will not work.

    Then, open the Advanced Settings section and select Unlimited in the Tag firing options drop-down list:


  5. Click on the Triggering block and select the All pages trigger:


  6. Specify the tag title and save the settings:


  7. Publish changes (Submit → Version Name → Publish):


Please note:

If the Roistat tracking code is installed via Google Tag Manager, its performance depends on the Tag Manager operation. If the Tag Manager fails, Roistat will not be able to receive data from the tracking code.

Testing the Tracking Code Performance

You can test the tracking code performance in the Roistat interface and the browser cookie list.

In the Roistat Interface

  1. Open Settings → Tracking code.

  2. Enter your website address in the Checking the tracking code section and click Check tracking code:


  3. The tracking code is installed correctly if a success message appears.

  1. Go to the website and open the developer panel in the browser. In Google Chrome, it is called Developer Tools:


  2. The tracking code is installed correctly if the cookie list contains the roistat_visit parameter with the visit number:


Frequently Asked Questions

Why can't I find the tracking code in the project?

The tracking code may not be available if you do not have enough permissions in the project. If you need the tracking code, contact the project owner or users with appropriate permissions. To view all permissions, go to the Projects list page.

What should I do if I use redirects or switching to another domain from my main website?

In such cases, the tracking code assigns the visit number incorrectly. You can find the solution in this instruction.

My website has a slow loading speed. Could this be related to the Roistat tracking code operation?

The Roistat tracking code does not affect page loading speed. It is loaded in a separate thread and runs in the background without delaying the loading of the page content. The reasons for the long loading can be different: large images, inefficient scripts, etc. Use Google PageSpeed Insights to see recommendations for your website.