Device Segments
Create dynamic device groups from filter rules — platform, country, language, app version, custom metadata. Use with immediate sends.
Create dynamic groups based on device attributes for targeted messaging.
Available Filter Fields#
platformandroid, ios, web
userIdUser identifier
appVersionApp version string
countryCountry code
languageDevice language
metadata.*Custom fields
Create a Segment#
Node.js SDK
import { AbrovaPush } from '@abrova/push-node';
const abrovaPush = new AbrovaPush({
apiKey: 'ab_live_your_api_key',
serverSecret: 'ab_srv_your_server_secret',
});
const segment = await abrovaPush.segments.create({
name: 'Premium iOS Users',
description: 'iOS users with premium subscription',
filters: [
{ field: 'platform', operator: 'equals', value: 'ios' },
{ field: 'metadata.tier', operator: 'equals', value: 'premium' },
],
});REST API
curl -X POST "https://push-api.abrova.ir/segments" \
-H "x-api-key: ab_live_your_api_key" \
-H "x-server-secret: ab_srv_your_server_secret" \
-H "Content-Type: application/json" \
-d '{
"name": "Premium iOS Users",
"description": "iOS users with premium subscription",
"filters": [
{ "field": "platform", "operator": "equals", "value": "ios" },
{ "field": "metadata.tier", "operator": "equals", "value": "premium" }
]
}'Response
{
"id": "seg_abc123",
"name": "Premium iOS Users",
"description": "iOS users with premium subscription",
"color": "#6366f1",
"filters": [
{ "field": "platform", "operator": "equals", "value": "ios" },
{ "field": "metadata.tier", "operator": "equals", "value": "premium" }
],
"deviceCount": 850,
"createdAt": "2024-01-15T10:00:00Z"
}Filter Operators#
| Operator | Description |
|---|---|
| equals | Exact match (platform = "ios") |
| not_equals | Not equal to (platform != "web") |
| contains | String contains (appVersion contains "2.") |
| not_contains | String does not contain |
| greater_than | Numeric greater than (metadata.age > 18) |
| less_than | Numeric less than (metadata.age < 65) |
| in | In list of values (country in ["US", "CA", "GB"]) |
| not_in | Not in list of values |
| exists | metadata.* key is present (value true) or missing (value false) — metadata.vip exists true |
| starts_with | String starts with — top-level fields only (not metadata.*) |
| greater_than_or_equal | Greater than or equal — top-level fields only (not metadata.*) |
| less_than_or_equal | Less than or equal — top-level fields only (not metadata.*) |
Filters are combined with AND. Comparisons on appVersion are version-aware (2.10.0 > 2.9.0), and platform values are matched in lowercase. starts_with, greater_than_or_equal and less_than_or_equal are not in the Node SDK's SegmentFilterOperator type yet.
The dashboard auto-discovers which metadata.* keys and values your devices actually send — the segment builder suggests real keys from your project, and operator choices adapt to each key's inferred type (string, number, boolean). You can still type any custom metadata.* key you plan to write from your SDK later.
Example Segments#
Android Users in US/Canada
{
"name": "North American Android",
"filters": [
{ "field": "platform", "operator": "equals", "value": "android" },
{ "field": "country", "operator": "in", "value": ["US", "CA"] }
]
}VIP Users (Custom Metadata)
{
"name": "VIP Members",
"filters": [
{ "field": "metadata.vip", "operator": "equals", "value": true },
{ "field": "metadata.totalSpent", "operator": "greater_than", "value": 1000 }
]
}Beta Testers on Latest Version
{
"name": "Beta Testers",
"filters": [
{ "field": "metadata.betaTester", "operator": "equals", "value": true },
{ "field": "appVersion", "operator": "contains", "value": "3." }
]
}Send to Segment#
Send to a segment with an immediate push. Scheduled messages can't target segments; send to a segment immediately.
Node.js SDK
// Send to segment immediately
await abrovaPush.push.sendToSegment({
segmentId: 'seg_abc123',
title: 'Exclusive for Premium!',
body: 'Check out your member benefits',
});REST API
curl -X POST "https://push-api.abrova.ir/push/send-to-segment" \
-H "x-api-key: ab_live_your_api_key" \
-H "x-server-secret: ab_srv_your_server_secret" \
-H "Content-Type: application/json" \
-d '{
"segmentId": "seg_abc123",
"title": "Exclusive for Premium!",
"body": "Check out your member benefits"
}'Preview Segment#
Get the match count + a small device sample for a set of filters without saving them. Useful for validating filter logic before creating a segment.
The dashboard's segment builder shows this preview live in the right panel as you edit — no code needed there. The API + SDK below are for programmatic use (CI checks, batch jobs, custom UIs).
Node.js SDK
const { count, preview } = await abrovaPush.segments.preview({
filters: [
{ field: 'platform', operator: 'equals', value: 'ios' },
{ field: 'metadata.tier', operator: 'equals', value: 'premium' },
],
limit: 10, // optional, default 20, max 50
});
console.log(`${count} devices match`);
preview.forEach((d) => console.log(d.deviceId, d.userId));REST API
curl -X POST "https://push-api.abrova.ir/segments/preview?limit=10" \
-H "x-api-key: ab_live_your_api_key" \
-H "x-server-secret: ab_srv_your_server_secret" \
-H "Content-Type: application/json" \
-d '{
"filters": [
{ "field": "platform", "operator": "equals", "value": "ios" },
{ "field": "metadata.tier", "operator": "equals", "value": "premium" }
]
}'Response
{
"count": 1250,
"preview": [
{
"deviceId": "dev_abc...",
"platform": "ios",
"userId": "user_1",
"topics": ["news", "promos"],
"metadata": { "tier": "premium", "country": "US" }
},
{
"deviceId": "dev_def...",
"platform": "ios",
"userId": "user_2",
"topics": null,
"metadata": { "tier": "premium" }
}
]
}Long metadata string values are truncated to 200 characters (with an ellipsis) in the preview response to keep payloads small.