Build your first segment

Describe a group of people by what they did and who they are, preview it, save it and watch it update.

Embed
Preview of the card
<a href="https://hermeticor.com/guides/first-segment"><img src="https://hermeticor.com/guides/_api/public/orgs/5fcd8b3c-a27c-4688-972f-de710125592f/spaces/9a3da731-ded5-4536-b84f-8c9a61420ff4/pages/54152f81-3388-420f-b8b6-f0621b19b6fb/social-card.svg?v=3e7ae33eec8b" alt="Build your first segment" width="600" height="315"></a>

A segment is a saved rule. People join and leave it by themselves as events and profile changes arrive.

What you need first

  • Some people and events (see Track events).

  • A key with segments:write.

1. Write the rule and preview it

This finds people who signed up but have not sent a first campaign in the last 60 days:

DEF='{"type":"group","op":"and","children":[
  {"type":"event","name":"Signed up"},
  {"type":"event","name":"Sent first campaign","negate":true,"window":{"kind":"last_days","days":60}}]}'

curl -s -X POST "$BASE/v1/segments/preview" \
  -H "Authorization: Bearer $HERMETICA_API_KEY" -H "Content-Type: application/json" \
  -d "{\"definition\":$DEF}"

You get a count and a sample of people.

2. Save it

curl -s -X POST "$BASE/v1/segments" \
  -H "Authorization: Bearer $HERMETICA_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: seg-not-activated" \
  -d "{\"name\":\"Signed up, not activated\",\"folder\":\"Funnel\",\"definition\":$DEF}"

curl -s -X POST "$BASE/v1/segments/<segmentId>/evaluate" \
  -H "Authorization: Bearer $HERMETICA_API_KEY" -H "Content-Type: application/json" -d '{}'
# 202: the first fill runs in the background

3. See who is in it

curl -s "$BASE/v1/segments/<segmentId>/members" -H "Authorization: Bearer $HERMETICA_API_KEY"
curl -s "$BASE/v1/segments/<segmentId>/explain-match/<profileId>" -H "Authorization: Bearer $HERMETICA_API_KEY"

explain-match says why one person is in or out. GET /v1/segments/<id>/translate reads the rule back in plain English.

Other conditions

Want

Condition

A profile field

{"type":"profile_property","field":"attributes.plan","predicate":{"valueType":"string","op":"in","values":["starter","growth"]}}

A tag

{"type":"tag","name":"design-partner"}

Can get marketing email now

{"type":"can_receive_marketing","channel":"email"}

You do not need the last one to protect consent. Every send checks consent and suppression anyway. It is useful for counting who you can reach.

Next: Send your first campaign.

Updated