1C-Bitrix Integration with Pushwoosh
Pushwoosh is a push notification service that operates via its own infrastructure on top of FCM/APNs. Its advantage over direct FCM integration: a unified API for Web Push, Android, iOS, and Huawei; built-in segments, A/B tests, and analytics. The integration with 1C-Bitrix includes a frontend SDK, a PHP client for sending notifications, and linking Pushwoosh devices to Bitrix users.
Integration Structure
Pushwoosh uses the concept of hwid (hardware ID) — a unique device identifier within Pushwoosh. You need to store the mapping: Bitrix USER_ID → hwid[] Pushwoosh. One user may have multiple hwid values (browsers + mobile devices).
Pushwoosh SDK (JS/Android/iOS)
→ Obtains hwid, registers device with Pushwoosh
→ POST /local/api/pushwoosh/register (binding hwid to USER_ID)
→ Bitrix event (order, promotion)
→ PHP → Pushwoosh API (sendMessage/createMessage)
→ Pushwoosh → FCM/APNs → device
Web SDK Initialization
<script src="https://cdn.pushwoosh.com/webpush/v3/pushwoosh-web-notifications.js"></script>
<script>
var Pushwoosh = Pushwoosh || [];
Pushwoosh.push(['init', {
logLevel: 'error',
applicationCode: 'XXXXX-YYYYY', // Application Code from Pushwoosh Dashboard
safariWebsitePushID: 'web.com.example.shop',
defaultNotificationTitle: 'Example Store',
defaultNotificationImage: 'https://example.com/push-icon.png',
autoSubscribe: false, // manage subscription manually
serviceWorkerUrl: '/pushwoosh-service-worker.js',
}]);
Pushwoosh.push(function(api) {
api.onReady(function() {
// Register hwid in Bitrix
api.getHWID().then(function(hwid) {
if (hwid) {
registerPushwooshDevice(hwid);
}
});
});
});
function registerPushwooshDevice(hwid) {
fetch('/local/api/pushwoosh/register', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Bitrix-Csrf-Token': BX.bitrix_sessid()
},
body: JSON.stringify({ hwid: hwid, platform: 'web' })
});
}
// Subscribe button
document.getElementById('subscribe-push').addEventListener('click', function() {
Pushwoosh.push(function(api) {
api.subscribe().then(function() {
Pushwoosh.push(function(api) {
api.getHWID().then(registerPushwooshDevice);
});
});
});
});
</script>
Service Worker /pushwoosh-service-worker.js in the site root:
importScripts('https://cdn.pushwoosh.com/webpush/v3/pushwoosh-service-worker.js');
Storing hwid and the Pushwoosh API PHP Client
class PushwooshService
{
private string $appCode;
private string $apiAccessToken;
private string $apiUrl = 'https://cp.pushwoosh.com/json/1.3/';
public function createMessage(array $recipientHwids, string $content, array $extra = []): array
{
$payload = [
'request' => [
'application' => $this->appCode,
'auth' => $this->apiAccessToken,
'notifications' => [[
'send_date' => 'now',
'ignore_user_timezone' => false,
'content' => $content,
'devices' => $recipientHwids, // array of hwid
'data' => $extra['data'] ?? [],
'ios_title' => $extra['title'] ?? '',
'android_header' => $extra['title'] ?? '',
'link' => $extra['url'] ?? '',
]],
],
];
return $this->request('createMessage', $payload);
}
public function sendMessageToUser(int $userId, string $content, string $title = '', string $url = ''): void
{
$hwids = PushwooshDeviceTable::getHwidsByUserId($userId);
if (empty($hwids)) return;
$this->createMessage($hwids, $content, ['title' => $title, 'url' => $url]);
}
/**
* Bulk send by user tag (segmentation)
* Example: users who purchased a product from category X
*/
public function createMessageByTag(string $tagName, string $tagValue, string $content): array
{
$payload = [
'request' => [
'application' => $this->appCode,
'auth' => $this->apiAccessToken,
'notifications' => [[
'send_date' => 'now',
'content' => $content,
'conditions' => [[$tagName, 'EQ', $tagValue]],
]],
],
];
return $this->request('createMessage', $payload);
}
private function request(string $method, array $data): array
{
$ch = curl_init($this->apiUrl . $method);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
return $response ?? [];
}
}
Pushwoosh Tags for Segmentation
Pushwoosh supports tags — custom device attributes. This allows sending notifications to segments without passing a list of hwid values.
Setting a tag upon registration or when user data changes:
public function setUserTags(string $hwid, int $userId): void
{
$user = \Bitrix\Main\UserTable::getById($userId)->fetch();
$tags = [];
// User groups → tags
$groups = \CUser::GetUserGroup($userId);
if (in_array(7, $groups)) { // Group ID "Gold"
$tags[] = ['tagName' => 'loyalty_level', 'tagValue' => 'gold'];
}
// City
if (!empty($user['PERSONAL_CITY'])) {
$tags[] = ['tagName' => 'city', 'tagValue' => $user['PERSONAL_CITY']];
}
// Purchase history — total amount
$totalOrders = $this->getUserOrdersTotal($userId);
$tags[] = ['tagName' => 'orders_total', 'tagValue' => (int)$totalOrders];
$this->request('setTags', [
'request' => [
'application' => $this->appCode,
'auth' => $this->apiAccessToken,
'tags' => $tags,
'hwid' => $hwid,
],
]);
}
Handling Bitrix Events
// Order status change
AddEventHandler('sale', 'OnSaleStatusOrder', function(string $statusId, \Bitrix\Sale\Order $order) {
$userId = (int)$order->getUserId();
$notifications = [
'O' => ['Order #' . $order->getField('ACCOUNT_NUMBER'), 'Order received, passing to processing'],
'D' => ['Order Shipped', 'Your parcel is on its way — track your delivery'],
'F' => ['Order Completed', 'Thank you for your purchase! Leave a review — your feedback matters'],
];
if (!isset($notifications[$statusId])) return;
[$title, $content] = $notifications[$statusId];
$url = '/personal/order/detail/' . $order->getField('ACCOUNT_NUMBER') . '/';
(new PushwooshService())->sendMessageToUser($userId, $content, $title, $url);
});
Statistics and Inbox
Pushwoosh provides an API for fetching statistics (getStats) and inbox notifications (getInboxMessages) — a list of recent push notifications the user may have missed. The inbox is displayed in the user account as a notification center:
Pushwoosh.push(function(api) {
api.getInboxMessages().then(function(messages) {
// Render the list of unread notifications
renderInbox(messages);
});
});
Timeline
| Task | Duration |
|---|---|
| SDK initialization, saving hwid | 2–3 days |
| PHP API client, device table | 2–3 days |
| Sending on order events | 2–3 days |
| Tags and segmentation | 2–3 days |
| Inbox, statistics, management from account | 3–5 days |
| Full scope (web + mobile) | 3–4 weeks |







