1C-Bitrix Integration with Carrot Quest
Carrot Quest is a platform that combines live chat, email marketing, pop-ups, and user behavior analytics in a single tool. Unlike simple chat widgets, user identification is critical here: every event (product view, add to cart, order placement) is tied to a profile. Without that linkage, Carrot Quest becomes just an expensive live chat.
Installing the Tracking Code
The Carrot Quest code is inserted into the site template before </body>:
// In the Bitrix template
(function(){ /* ... standard Carrot Quest snippet ... */ })();
carrotquest.connect('YOUR_API_KEY');
Identifying Users from Bitrix
The key operation is carrotquest.identify(). Without it, all events are anonymous and do not accumulate in a profile.
<?php if ($USER->IsAuthorized()):
$userId = $USER->GetID();
$userEmail = $USER->GetEmail();
$userName = $USER->GetFullName();
// Hash for server-side verification in Carrot Quest
$hash = hash_hmac('sha256', $userId, 'YOUR_SECRET_KEY');
?>
<script>
carrotquest.identify({
'$user_id': <?= json_encode($userId) ?>,
'$email': <?= json_encode($userEmail) ?>,
'$name': <?= json_encode($userName) ?>,
'$phone': <?= json_encode(getUserPhone($userId)) ?>,
'orders_count': <?= getUserOrdersCount($userId) ?>,
'total_spent': <?= getUserTotalSpent($userId) ?>,
}, <?= json_encode($hash) ?>);
</script>
<?php endif; ?>
The hash parameter is an HMAC-SHA256 of the user_id with the secret key. This verifies the authenticity of the data on the Carrot Quest side and prevents ID spoofing.
Sending Events from the Bitrix Catalog
Carrot Quest delivers the most analytical value when it receives events from across the entire funnel. Events are sent via carrotquest.track():
Product page view (in the catalog.element template):
carrotquest.track('Product Viewed', {
product_id: <?= $arResult['ID'] ?>,
product_name: <?= json_encode($arResult['NAME']) ?>,
price: <?= $arResult['CATALOG_PRICE_1'] ?? 0 ?>,
category: <?= json_encode($sectionName) ?>,
});
Add to cart (button handler):
// After a successful AJAX add-to-cart
carrotquest.track('Product Added to Cart', {
product_id: productId,
product_name: productName,
price: price,
quantity: quantity,
});
Order placed (in the sale.order.ajax template, event after order creation):
carrotquest.track('Order Placed', {
order_id: <?= $orderId ?>,
total_price: <?= $orderTotal ?>,
items_count: <?= $itemsCount ?>,
payment_method: <?= json_encode($paymentMethod) ?>,
});
User Segmentation via Attributes
After carrotquest.identify(), user attributes can be updated on every visit — this allows building segments in Carrot Quest for triggered messages:
// Update on every login
carrotquest.identify({
'last_visit': new Date().toISOString(),
'cart_value': <?= $basketTotal ?>,
'cart_items_count': <?= $basketCount ?>,
'loyalty_level': <?= json_encode($loyaltyLevel) ?>,
});
Integration via Carrot Quest PHP API
In addition to JS tracking, Carrot Quest has a REST API for server-side use. This is needed when an event occurs outside the browser — for example, an order status change:
// On order status change — notify Carrot Quest
\Bitrix\Main\EventManager::getInstance()->addEventHandler(
'sale', 'OnSaleStatusOrder',
function (\Bitrix\Main\Event $event) {
$order = $event->getParameter('ENTITY');
$userId = $order->getUserId();
$userEmail = getUserEmail($userId);
$statusId = $order->getField('STATUS_ID');
$payload = [
'id' => $userEmail,
'id_type' => 1, // 1 = email
'event' => 'Order Status Changed',
'params' => [
'order_id' => $order->getId(),
'new_status' => $statusId,
],
];
$ch = curl_init('https://api.carrotquest.io/v1/users/events');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Token YOUR_API_KEY', 'Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
}
);
Automated Messages Based on Events
Once tracking is configured, triggered sequences are built in the Carrot Quest interface:
- User viewed product X → did not add to cart within 30 minutes → chat message "Need help choosing?"
- Order created → status "Delivered" → 7 days later email "Leave a review"
- User has not visited in 60 days → email with a discount
All of this is configured in the Carrot Quest interface without code — provided that events arrive correctly.
Debugging Tracking
Use the browser console: when configured correctly, carrotquest.track() and carrotquest.identify() print confirmation to the console in development mode. In the Carrot Quest admin panel, Analytics → Events shows incoming events in real time.
Scope of work: code installation and user identification — 1 day. Tracking all funnel events — 2–3 days. Server-side API for order status changes — another 1 day. Setting up triggered sequences — 1–2 days after initial data accumulates.







