Integration of 1C-Bitrix with Flocktory
Flocktory is a platform for post-purchase traffic and viral marketing. Its main mechanics: showing a pop-up with a partner offer immediately after order completion ("I want it!"), referral programs, and contact exchange mechanics. Integration with Bitrix is technically simple and built on two components: transmitting order data through a JavaScript object on the confirmation page and connecting the tracker on all pages.
Connecting the Flocktory Tracker
The tracker is connected once to all pages of the site. In Bitrix template—in footer.php or via addExternalJs:
<!-- Flocktory tracker -->
<div class="i-flocktory" data-fl-action="track" data-fl-site-id="YOUR_SITE_ID"></div>
<script type="text/javascript">
(function(w,d,n,s,t) {
w[n] = w[n] || [];
w[n].push(function() { t = d.createElement(s);
t.type = 'text/javascript'; t.async = true;
t.src = '//api.flocktory.com/v2/loader.js?site_id=<?= FLOCKTORY_SITE_ID ?>';
var sn = d.getElementsByTagName(s)[0];
sn.parentNode.insertBefore(t, sn);
});
w.addEventListener('load', w[n][0]);
})(window, document, '_flocktory_callbacks', 'script');
</script>
FLOCKTORY_SITE_ID—numeric ID from Flocktory personal account. Recommended to extract as a constant via define in bitrix/php_interface/dbconn.php or in settings module.
Transmitting Data After Order Completion
The key integration point—the "Thank you for your order" page. Flocktory shows a post-purchase pop-up only if it receives correct order data. On successful completion page insert a block with data:
// In the order confirmation page template
// Get data from sale.order.checkout component or directly from ORDER_ID
$orderId = (int)$_GET['ORDER_ID'];
$order = \Bitrix\Sale\Order::load($orderId);
if ($order && $order->getUserId() === $USER->GetID()) {
$user = CUser::GetByID($order->getUserId())->Fetch();
$items = [];
foreach ($order->getBasket()->getOrderableItems() as $item) {
$items[] = [
'id' => (string)$item->getProductId(),
'title' => $item->getField('NAME'),
'price' => (float)$item->getPrice(),
'count' => (float)$item->getQuantity(),
];
}
$flData = [
'order' => [
'id' => (string)$orderId,
'price' => (float)$order->getPrice(),
'currency' => $order->getCurrency(),
],
'customer' => [
'name' => trim($user['NAME'] . ' ' . $user['LAST_NAME']),
'email' => $user['EMAIL'],
],
'items' => $items,
];
?>
<div class="i-flocktory"
data-fl-action="purchase"
data-fl-site-id="<?= FLOCKTORY_SITE_ID ?>"
data-fl-user-name="<?= htmlspecialchars($flData['customer']['name']) ?>"
data-fl-user-email="<?= htmlspecialchars($flData['customer']['email']) ?>"
data-fl-transaction-id="<?= $flData['order']['id'] ?>"
data-fl-total-price="<?= $flData['order']['price'] ?>"
data-fl-items='<?= json_encode($flData['items'], JSON_UNESCAPED_UNICODE) ?>'>
</div>
<?php
}
?>
The data-fl-items attribute must contain valid JSON. Flocktory uses this data for post-purchase offer targeting: e.g., if customer bought electronics, partner can show a warranty offer or accessories.
Authorized User Data on All Pages
For personalization, Flocktory must know the authorized user's email on any page:
// In footer.php, after connecting the main tracker
if ($USER->IsAuthorized()) {
$currentUser = CUser::GetByID($USER->GetID())->Fetch();
?>
<div class="i-flocktory"
data-fl-action="push-user"
data-fl-site-id="<?= FLOCKTORY_SITE_ID ?>"
data-fl-user-email="<?= htmlspecialchars($currentUser['EMAIL']) ?>"
data-fl-user-name="<?= htmlspecialchars($currentUser['NAME']) ?>">
</div>
<?php
}
?>
Referral Program (Shaker)
Flocktory Shaker—virality mechanic: after purchase, customer is offered to share a link, friends get a discount, referrer—bonus. Configuration on Flocktory side (in personal account). From Bitrix side, you need:
- When following a referral link—record
utm_source=flocktoryUTM tag - Pass Flocktory promo code to Bitrix discount mechanism
Promo code from link (?flocktory_code=XXX) is applied via standard Bitrix mechanism or custom cart handler.
Integration through Bitrix Events (Alternative Approach)
Instead of HTML blocks, pass data through JavaScript object after server confirmation. OnSaleOrderSaved event handler saves data to session, which is then read on the "Thank you" page:
AddEventHandler('sale', 'OnSaleOrderSaved', function(\Bitrix\Main\Event $event) {
$order = $event->getParameter('ENTITY');
$isNew = $event->getParameter('IS_NEW');
if (!$isNew) return;
$_SESSION['FLOCKTORY_ORDER'] = [
'id' => $order->getId(),
'price' => $order->getPrice(),
];
});
Testing Integration
Flocktory provides debug mode: add ?flocktory_debug=1 to page URL. Browser console shows messages on successful data transmission or mapping errors. Main causes of broken integration—incorrect email (empty, invalid), wrong data-fl-items format (invalid JSON), wrong site_id.
Implementation Timelines
| Scope | Composition | Duration |
|---|---|---|
| Basic (tracker + post-purchase pop-up) | Data block on order page + tracker | 0.5–1 day |
| With push-user on all pages | + authorization on each page | +0.5 day |
| Referral program (promo codes) | + handling referral links + discounts | 2–3 days |







