Geofencing Notifications Setup for 1C-Bitrix
Geofencing — trigger firing when user enters or exits defined geographic zone. In Bitrix context, typically mobile app push: "You're near our store — 10% discount today."
Solution Components
Geofencing doesn't implement via Bitrix alone. Three components needed:
- Mobile app (iOS/Android) with background geolocation monitoring — registers zones, sends events to server
- Server API on Bitrix — receives enter/exit events, decides on notification send
- Push infrastructure — Firebase Cloud Messaging (FCM) for Android, APNs for iOS
Browser geofencing via Geolocation API works only with open tab, so full notifications require mobile app.
Zone Registration on App Side
Native SDKs support geofencing:
-
Android:
com.google.android.gms.location.GeofencingClient -
iOS:
CLLocationManagerwithstartMonitoring(for: CLCircularRegion)
App loads zone list on startup from Bitrix server, registers in system. On enter/exit, OS generates event — app sends POST to your API.
Bitrix API
Create REST endpoint /local/ajax/geofence-event.php:
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php';
$data = json_decode(file_get_contents('php://input'), true);
$userId = (int)$data['user_id'];
$zoneId = (int)$data['zone_id'];
$eventType = $data['event']; // 'enter' or 'exit'
$deviceToken = $data['device_token'];
if ($eventType === 'enter') {
\Local\Geofence\NotificationService::sendEnterZoneNotification(
$userId,
$zoneId,
$deviceToken
);
}
Zone Storage
Use HL-infoblock GeoZones:
| Field | Type | Description |
|---|---|---|
UF_NAME |
String | Zone name |
UF_LAT |
Float | Center latitude |
UF_LNG |
Float | Center longitude |
UF_RADIUS |
Integer | Radius in meters |
UF_NOTIFICATION_TEXT |
Text | Push text |
UF_ACTIVE |
Flag | Zone active |
Push Send via FCM
namespace Local\Geofence;
class NotificationService {
private const FCM_URL = 'https://fcm.googleapis.com/fcm/send';
public static function sendEnterZoneNotification(
int $userId,
int $zoneId,
string $deviceToken
): void {
$zone = \Local\Geofence\GeoZoneTable::getById($zoneId)->fetch();
if (!$zone || $zone['UF_ACTIVE'] !== true) return;
$payload = [
'to' => $deviceToken,
'notification' => [
'title' => 'You're near us',
'body' => $zone['UF_NOTIFICATION_TEXT'],
],
];
$http = new \Bitrix\Main\Web\HttpClient();
$http->setHeader('Authorization', 'key=' . FCM_SERVER_KEY);
$http->setHeader('Content-Type', 'application/json');
$http->post(self::FCM_URL, json_encode($payload));
}
}
Limits and Antispam
Without limits, user passing store multiple times daily gets same notifications. Add cooldown: log sent notifications in table, don't resend if last notification for this zone < N hours ago.
| Stage | Time |
|---|---|
| Zone structure and API design | 3–4 h |
| Server API development | 6–10 h |
| FCM / APNs setup | 2–3 h |
| Mobile app integration | 8–16 h |
| Cooldown and antispam | 2–4 h |







