Skip to content

Commit

Permalink
docs: adds triggers docs
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva committed Feb 24, 2025
1 parent 14eef45 commit 3a9d2e9
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/content/docs/audience-management/segments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ const collection = new CollectionManager({
readAPIKey: '<read_api_key>',
})
await collection.get("<SEGMENT_ID>")
await collection.getSegment("<SEGMENT_ID>")
```
</Tabs>
## Listing all Segments
When inserting one or more segments, you can list all of them to get an overview of your audience.
<Tabs groupId='get' persist items={['cURL', 'JavaScript']}>
<Tabs groupId='getall' persist items={['cURL', 'JavaScript']}>
```bash tab="cURL"
curl http://localhost:8080/v1/collections/{COLLECTION_ID}/segments/all?api-key=<READ_API_KEY>
```
Expand Down
181 changes: 180 additions & 1 deletion docs/content/docs/audience-management/triggers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,189 @@ In OramaCore, triggers are a set of rules that define how to respond to a user b

## Example: Luxury Car Dealership

![Luxury Car Dealership](/docs/triggers/ferrari.jpg)

In the past section ([on user segmentation](/docs/audience-management/segments)), we discussed how we could segment users of a luxury car dealership into three groups:

- Exotic Car Lovers
- Luxury Car Explorers
- Luxury Car Buyers

Now, let's see how we can use triggers to provide them with the best answers based on their needs and interests.
Once you segmented your users, you can decide to reply differently to each group, even if they all ask the same thing. Let's see an example:

| Question | Segment | Reply |
| --- | --- | --- |
| "What's the price of the new Ferrari?" | Exotic Car Lovers | "The new Ferrari is $300,000. Configure yours and share it on your Instagram!" |
| "How much does the new Ferrari cost?" | Luxury Car Explorers | "The new Ferrari is $100,000. Book a test drive and get a free gift!" |
| "New Ferrari cost" | Luxury Car Buyers | "The new Ferrari is $300,000. Buy today to get an exclusive membership to our club!" |

The reasoning behind these three different replies based on the same question is that each segment has different needs and expectations.

As we've seen when discussing segments, **Exotic Car Lovers** may not necessarily have the budget to buy a Ferrari, but they are interested in the brand and the lifestyle associated with it. Therefore, prompting them to configure their own Ferrari and share it on Instagram is a way to engage them and keep them interested in the brand.

**Luxury Car Explorers** are interested in the car but may not be ready to buy yet. It may be convenient to offer them a test drive and a free gift to incentivize them to visit the dealership and experience the car in person.

Finally, **Luxury Car Buyers** are ready to buy and need a little push to make the purchase.

You can apply this logic to any domain and any type of user interaction. Triggers are a powerful tool to personalize the user experience and drive engagement and conversion.

## Creating a Trigger

To create a treigger, you can either use the official SDKs or an API call.

Every trigger is composed of the following fields:

| Field | Description | Mandatory |
|-------------|-----------------------------------------------------------------------------|-----------|
| `name` | The name of the trigger. | Yes |
| `description` | A natural language description of the trigger. It describes the situation in which the trigger should be activated. | Yes |
| `response` | A natural language description of how OramaCore should respond to the trigger. | Yes |
| `segment_id` | The ID of the segment to which the trigger is associated. | No |

While you can create triggers without passing a `segment_id`, we highly recommend you to associate each trigger with a segment. This way, you can provide different responses to different segments, personalizing the user experience and driving engagement and conversion.

<Tabs groupId='insert' persist items={['cURL', 'JavaScript']}>
```bash tab="cURL"
curl -X POST \
http://localhost:8080/v1/collections/{COLLECTION_ID}/triggers/insert \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <write_api_key>' \
-d '{
"name": "Ferrari Price",
"description": "User asks for the price of a luxury car.",
"response": "Give the price of the car, then prompt the user to configure it and share it on social media.",
"segment_id": "<SEGMENT_ID>"
}'
```

```js tab="JavaScript"
import { CollectionManager } from '@orama/core'

const collection = new CollectionManager({
url: 'http://localhost:8080',
collectionID: '<COLLECTION_ID>'
writeAPIKey: '<write_api_key>',
})

await collection.insertTrigger({
name: 'Ferrari Price',
description: 'User asks for the price of a luxury car.',
response: 'Give the price of the car, then prompt the user to configure it and share it on social media.',
segmentID: '<SEGMENT_ID>'
})
```
</Tabs>

## Getting a Trigger

After inserting a trigger, you'll receive its ID in the response. You can use this ID to retrieve the trigger details.

<Tabs groupId='get' persist items={['cURL', 'JavaScript']}>
```bash tab="cURL"
curl http://localhost:8080/v1/collections/{COLLECTION_ID}/triggers/get?id=<SEGMENT_ID>&api-key=<READ_API_KEY>
```

```js tab="JavaScript"
import { CollectionManager } from '@orama/core'

const collection = new CollectionManager({
url: 'http://localhost:8080',
collectionID: '<COLLECTION_ID>'
readAPIKey: '<read_api_key>',
})

await collection.getTrigger("<SEGMENT_ID>")
```
</Tabs>

## Listing all triggers

When inserting one or more triggers, you can list all of them to get an overview of your audience.

<Tabs groupId='getall' persist items={['cURL', 'JavaScript']}>
```bash tab="cURL"
curl http://localhost:8080/v1/collections/{COLLECTION_ID}/triggers/all?api-key=<READ_API_KEY>
```

```js tab="JavaScript"
import { CollectionManager } from '@orama/core'

const collection = new CollectionManager({
url: 'http://localhost:8080',
collectionID: '<COLLECTION_ID>'
readAPIKey: '<read_api_key>',
})

await collection.getAllTriggers()
```
</Tabs>

## Update a Trigger

<Callout type='warn'>
**Beware**: You can not change the `segment_id` of a trigger once it has been created. If you need to change the segment, you should delete the trigger and create a new one.
</Callout>

To update a trigger, you can use the following API call:

<Tabs groupId='insert' persist items={['cURL', 'JavaScript']}>
```bash tab="cURL"
curl -X POST \
http://localhost:8080/v1/collections/{COLLECTION_ID}/triggers/update \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <write_api_key>' \
-d '{
"id": "<TRIGGER_ID>",
"name": "Ferrari Price",
"description": "User asks for the price of a luxury car.",
"response": "Give the price of the car, then prompt the user to configure it and share it on social media."
"segment_id": "<SEGMENT_ID>"
}'
```

```js tab="JavaScript"
import { CollectionManager } from '@orama/core'

const collection = new CollectionManager({
url: 'http://localhost:8080',
collectionID: '<COLLECTION_ID>'
writeAPIKey: '<write_api_key>',
})

await collection.updateTrigger({
id: '<TRIGGER_ID>',
name: 'Ferrari Price',
description: 'User asks for the price of a luxury car.',
response: 'Give the price of the car, then prompt the user to configure it and share it on social media.',
segmentID: '<SEGMENT_ID>'
})
```
</Tabs>

## Delete a Trigger

You can always delete a trigger if you don't need it anymore. The trigger will be removed from the collection, and you won't be able to retrieve it anymore.

<Tabs groupId='insert' persist items={['cURL', 'JavaScript']}>
```bash tab="cURL"
curl -X POST \
http://localhost:8080/v1/collections/{COLLECTION_ID}/triggers/delete \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <write_api_key>' \
-d '{ "id": "<TRIGGER_ID>" }'
```

```js tab="JavaScript"
import { CollectionManager } from '@orama/core'

const collection = new CollectionManager({
url: 'http://localhost:8080',
collectionID: '<COLLECTION_ID>'
writeAPIKey: '<write_api_key>',
})

await collection.deleteTrigger({
id: '<TRIGGER_ID>'
})
```
</Tabs>
Binary file added docs/public/docs/triggers/ferrari.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3a9d2e9

Please sign in to comment.