Roistat Integration

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Roistat Integration

Roistat is cross-channel analytics with a focus on ad spend and ROI. It installs as a single tracker that captures clicks, calls, and leads, linking them to ad expenses from Google Ads, Yandex Direct, and other sources.

How the Tracker Works

The Roistat script writes a visit identifier — a 32-character string — to the roistat_visit cookie. For any target action (form, call, chat), this ID is passed along with the lead, allowing the system to identify the traffic source.

<!-- Basic installation — insert before </head> -->
<script>
(function(w, d, s, r, n) {
  w[n] = w[n] || function() { (w[n].q = w[n].q || []).push(arguments) };
  var f = d.getElementsByTagName(s)[0];
  var j = d.createElement(s);
  j.async = true;
  j.src = 'https://cdn.roistat.com/px.js';
  f.parentNode.insertBefore(j, f);
})(window, document, 'script', null, 'roistat');
roistat('init', { projectId: 'YOUR_PROJECT_ID' });
</script>

Via GTM, this is installed as a "Custom HTML" tag with a "All Pages" trigger.

Sending Visit Data on Form Submission

The form should pass roistat_visit to the backend. The most reliable way is a hidden field filled before submit:

document.querySelectorAll('form').forEach(form => {
  form.addEventListener('submit', () => {
    let input = form.querySelector('[name="roistat_visit"]');
    if (!input) {
      input = document.createElement('input');
      input.type = 'hidden';
      input.name = 'roistat_visit';
      form.appendChild(input);
    }
    input.value = getCookie('roistat_visit') ?? '';
  });
});

function getCookie(name) {
  const m = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
  return m ? decodeURIComponent(m[1]) : null;
}

On the backend, save this value with the lead — it's then sent to the Roistat API as the visit field.

API for Lead Creation

Roistat accepts leads via REST API. Required fields: projectId, visit, and at least one contact field.

curl -X POST 'https://cloud.roistat.com/api/proxy/1.0/project/lead/create' \
  -H 'Content-Type: application/json' \
  -d '{
    "projectId": "YOUR_PROJECT_ID",
    "visit": "abc123def456...",
    "fields": [
      { "name": "name", "value": "John Smith" },
      { "name": "phone", "value": "+79001234567" },
      { "name": "email", "value": "[email protected]" },
      { "name": "order_id", "value": "ORDER-789" }
    ]
  }'

Success response:

{ "status": "ok", "lead_id": 123456 }

Integration via PHP (Laravel / Plain PHP)

// app/Services/RoistatService.php
class RoistatService
{
    private string $projectId;
    private string $apiUrl = 'https://cloud.roistat.com/api/proxy/1.0/project/lead/create';

    public function __construct()
    {
        $this->projectId = config('services.roistat.project_id');
    }

    public function sendLead(array $fields, string $visitId): bool
    {
        $payload = [
            'projectId' => $this->projectId,
            'visit'     => $visitId,
            'fields'    => array_map(
                fn($name, $value) => ['name' => $name, 'value' => $value],
                array_keys($fields),
                array_values($fields)
            ),
        ];

        $response = Http::timeout(5)->post($this->apiUrl, $payload);
        return $response->ok() && $response->json('status') === 'ok';
    }
}

In the controller:

public function store(FormRequest $request, RoistatService $roistat)
{
    $lead = Lead::create($request->validated());

    $roistat->sendLead([
        'name'     => $lead->name,
        'phone'    => $lead->phone,
        'email'    => $lead->email,
        'order_id' => (string) $lead->id,
    ], $request->input('roistat_visit', ''));

    return response()->json(['ok' => true]);
}

Call Tracking

Roistat provides built-in call tracking. After adding numbers in your account, the script automatically replaces phone numbers on the page. No additional JS needed — just ensure numbers are in text or in href="tel:..." attributes.

If a phone number is rendered by a JS framework (React, Vue), ensure the Roistat script initializes after components mount:

// React: call after mount
useEffect(() => {
  if (window.roistat) {
    window.roistat('replacePhones');
  }
}, []);

Verification

  1. Open the site in a browser
  2. In DevTools → Application → Cookies, verify roistat_visit is present and not empty
  3. Submit a test form — in Roistat account → "Leads", a record with source should appear (not "direct")
  4. In console, check for no errors loading px.js

Timeline

Basic tracker installation + visit transfer from forms — 2–4 hours. API lead creation integration on custom backend — 2–3 more hours. Testing and attribution verification across all channels — 1–2 hours.