@bentonow/bento-node-sdk 0.2.0 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE → LICENSE.md} +1 -1
- package/README.md +496 -1077
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1273 -5
- package/dist/sdk/batch/enums.d.ts +8 -8
- package/dist/sdk/batch/errors.d.ts +18 -18
- package/dist/sdk/batch/events.d.ts +71 -71
- package/dist/sdk/batch/index.d.ts +55 -55
- package/dist/sdk/batch/types.d.ts +37 -37
- package/dist/sdk/broadcasts/index.d.ts +25 -0
- package/dist/sdk/broadcasts/types.d.ts +28 -0
- package/dist/sdk/client/errors.d.ts +9 -6
- package/dist/sdk/client/index.d.ts +74 -64
- package/dist/sdk/client/types.d.ts +3 -3
- package/dist/sdk/commands/enums.d.ts +12 -12
- package/dist/sdk/commands/index.d.ts +79 -79
- package/dist/sdk/commands/types.d.ts +32 -32
- package/dist/sdk/email-templates/index.d.ts +21 -0
- package/dist/sdk/email-templates/types.d.ts +23 -0
- package/dist/sdk/enums.d.ts +12 -9
- package/dist/sdk/errors.d.ts +2 -2
- package/dist/sdk/experimental/index.d.ts +75 -57
- package/dist/sdk/experimental/types.d.ts +71 -41
- package/dist/sdk/fields/index.d.ts +29 -29
- package/dist/sdk/fields/types.d.ts +17 -17
- package/dist/sdk/forms/index.d.ts +14 -14
- package/dist/sdk/forms/types.d.ts +28 -28
- package/dist/sdk/index.d.ts +11 -8
- package/dist/sdk/interfaces.d.ts +13 -13
- package/dist/sdk/sequences/index.d.ts +13 -0
- package/dist/sdk/sequences/types.d.ts +18 -0
- package/dist/sdk/stats/index.d.ts +24 -0
- package/dist/sdk/stats/types.d.ts +26 -0
- package/dist/sdk/subscribers/index.d.ts +20 -20
- package/dist/sdk/subscribers/types.d.ts +25 -25
- package/dist/sdk/tags/index.d.ts +20 -20
- package/dist/sdk/tags/types.d.ts +17 -17
- package/dist/sdk/types.d.ts +41 -41
- package/dist/sdk/workflows/index.d.ts +13 -0
- package/dist/sdk/workflows/types.d.ts +18 -0
- package/dist/versions/v1/index.d.ts +164 -132
- package/dist/versions/v1/types.d.ts +31 -31
- package/package.json +30 -43
- package/src/sdk/batch/events.ts +1 -1
- package/src/sdk/batch/index.ts +13 -25
- package/src/sdk/broadcasts/index.ts +43 -0
- package/src/sdk/broadcasts/types.ts +34 -0
- package/src/sdk/client/errors.ts +7 -0
- package/src/sdk/client/index.ts +108 -25
- package/src/sdk/commands/index.ts +54 -89
- package/src/sdk/email-templates/index.ts +39 -0
- package/src/sdk/email-templates/types.ts +27 -0
- package/src/sdk/enums.ts +3 -0
- package/src/sdk/experimental/index.ts +44 -26
- package/src/sdk/experimental/types.ts +35 -0
- package/src/sdk/fields/index.ts +1 -3
- package/src/sdk/forms/index.ts +4 -9
- package/src/sdk/forms/types.ts +1 -7
- package/src/sdk/index.ts +3 -0
- package/src/sdk/sequences/index.ts +21 -0
- package/src/sdk/sequences/types.ts +21 -0
- package/src/sdk/stats/index.ts +37 -0
- package/src/sdk/stats/types.ts +28 -0
- package/src/sdk/subscribers/index.ts +5 -15
- package/src/sdk/tags/index.ts +1 -3
- package/src/sdk/types.ts +1 -1
- package/src/sdk/workflows/index.ts +21 -0
- package/src/sdk/workflows/types.ts +21 -0
- package/src/versions/v1/index.ts +59 -10
- package/dist/bento-node-sdk.cjs.development.js +0 -2943
- package/dist/bento-node-sdk.cjs.development.js.map +0 -1
- package/dist/bento-node-sdk.cjs.production.min.js +0 -2
- package/dist/bento-node-sdk.cjs.production.min.js.map +0 -1
- package/dist/bento-node-sdk.esm.js +0 -2935
- package/dist/bento-node-sdk.esm.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,1293 +1,712 @@
|
|
|
1
|
-
# Bento SDK
|
|
1
|
+
# Bento Node SDK
|
|
2
|
+
<img align="right" src="https://app.bentonow.com/brand/logoanim.gif">
|
|
2
3
|
|
|
3
|
-
[!
|
|
4
|
-
|
|
5
|
-
🍱 Simple, powerful analytics for Node.JS projects!
|
|
4
|
+
> [!TIP]
|
|
5
|
+
> Need help? Join our [Discord](https://discord.gg/ssXXFRmt5F) or email jesse@bentonow.com for personalized support.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The Bento Node.js SDK makes it quick and easy to build an excellent analytics experience in your Node.js application. We provide powerful and customizable APIs that can be used out-of-the-box to track your users' behavior and manage subscribers. We also expose low-level APIs so that you can build fully custom experiences.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Get started with our [📚 integration guides](https://docs.bentonow.com), or [📘 browse the SDK reference](https://docs.bentonow.com/subscribers).
|
|
10
10
|
|
|
11
11
|
🐶 Battle-tested by [NativShark](https://nativshark.com) Bento Production (a Bento customer)!
|
|
12
12
|
|
|
13
13
|
❤️ Thank you @HelloKashif from [IPInfo](https://ipinfo.io) for your contribution.
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
- [Get Started](#Get-Started)
|
|
17
|
-
- [Modules](#Modules)
|
|
18
|
-
- [Analytics (Base Module)](#analytics-base-module)
|
|
19
|
-
- [tagSubscriber(parameters: TagSubscriberParameters): Promise\<boolean\>](#tagsubscriberparameters-tagsubscriberparameters-promiseboolean)
|
|
20
|
-
- [addSubscriber(parameters: AddSubscriberParameters): Promise\<boolean\>](#addsubscriberparameters-addsubscriberparameters-promiseboolean)
|
|
21
|
-
- [removeSubscriber(parameters: RemoveSubscriberParameters): Promise\<boolean\>](#removesubscriberparameters-removesubscriberparameters-promiseboolean)
|
|
22
|
-
- [updateFields(parameters: UpdateFieldsParameters\<S\>): Promise\<boolean\>](#updatefieldsparameters-updatefieldsparameterss-promiseboolean)
|
|
23
|
-
- [trackPurchase(parameters: TrackPurchaseParameters): Promise\<boolean\>](#trackpurchaseparameters-trackpurchaseparameters-promiseboolean)
|
|
24
|
-
- [Batch](#Batch)
|
|
25
|
-
- [.importSubscribers(parameters: BatchImportSubscribersParameter\<S\>): Promise\<number\>](#batchimportsubscribersparameters-batchimportsubscribersparameters-promisenumber)
|
|
26
|
-
- [.importEvents(parameters: BatchImportEventsParameter\<S, E\>): Promise\<number\>](#batchimporteventsparameters-batchimporteventsparameters-e-promisenumber)
|
|
27
|
-
- [Commands](#Commands)
|
|
28
|
-
- [.addTag(parameters: AddTagParameters): Promise\<Subscriber\<S\> | null\>](#commandsaddtagparameters-addtagparameters-promisesubscribers--null)
|
|
29
|
-
- [.removeTag(parameters: RemoveTagParameters): Promise\<Subscriber\<S\> | null\>](#commandsremovetagparameters-removetagparameters-promisesubscribers--null)
|
|
30
|
-
- [.addField(parameters: AddFieldParameters\<S\>): Promise\<Subscriber\<S\> | null\>](#commandsaddfieldparameters-addfieldparameterss-promisesubscribers--null)
|
|
31
|
-
- [.removeField(parameters: RemoveFieldParameters\<S\>): Promise\<Subscriber\<S\> | null\>](#commandsremovefieldparameters-removefieldparameterss-promisesubscribers--null)
|
|
32
|
-
- [.subscribe(parameters: SubscribeParameters): Promise\<Subscriber\<S\> | null\>](#commandssubscribeparameters-subscribeparameters-promisesubscribers--null)
|
|
33
|
-
- [.unsubscribe(parameters: UnsubscribeParameters): Promise\<Subscriber\<S\> | null\>](#commandsunsubscribeparameters-unsubscribeparameters-promisesubscribers--null)
|
|
34
|
-
- [Experimental](#Experimental)
|
|
35
|
-
- [.validateEmail(parameters: ValidateEmailParameters): Promise\<boolean\>](#experimentalvalidateemailparameters-validateemailparameters-promiseboolean)
|
|
36
|
-
- [.guessGender(parameters: GuessGenderParameters): Promise\<GuessGenderResponse\>](#experimentalguessgenderparameters-guessgenderparameters-promiseguessgenderresponse)
|
|
37
|
-
- [.geolocate(parameters: GeolocateParameters): Promise\<LocationData | null\>](#experimentalgeolocateparameters-geolocateparameters-promiselocationdata--null)
|
|
38
|
-
- [.checkBlacklist(parameters: BlacklistParameters): Promise\<BlacklistResponse\>](#experimentalcheckblacklistparameters-blacklistparameters-promiseblacklistresponse)
|
|
39
|
-
- [Fields](#Fields)
|
|
40
|
-
- [.getFields(): Promise\<Field[] | null\>](#fieldsgetfields-promisefield--null)
|
|
41
|
-
- [.createField(parameters: CreateFieldParameters): Promise\<Field[] | null\>](#fieldscreatefieldparameters-createfieldparameters-promisefield--null)
|
|
42
|
-
- [Forms](#Forms)
|
|
43
|
-
- [.getResponses(formIdentifier: string): Promise\<FormResponse[] | null\>](#formsgetresponsesformidentifier-string-promiseformresponse--null)
|
|
44
|
-
- [Subscribers](#Subscribers)
|
|
45
|
-
- [.getSubscribers(parameters?: GetSubscribersParameters): Promise\<Subscriber\<S\> | null\>](#subscribersgetsubscribersparameters-getsubscribersparameters-promisesubscribers--null)
|
|
46
|
-
- [.createSubscriber(parameters: CreateSubscriberParameters): Promise\<Subscriber\<S\> | null\>](#subscriberscreatesubscriberparameters-createsubscriberparameters-promisesubscribers--null)
|
|
47
|
-
- [Tags](#Tags)
|
|
48
|
-
- [.getTags(): Promise\<Tag[] | null\>](#tagsgettags-promisetag--null)
|
|
49
|
-
- [.createTag(parameters: CreateTagParameters): Promise\<Tag[] | null\>](#tagscreatetagparameters-createtagparameters-promisetag--null)
|
|
50
|
-
- [Types Reference](#Types-Reference)
|
|
51
|
-
- [TypeScript](#TypeScript)
|
|
52
|
-
- [Generics](#Generics)
|
|
53
|
-
- [S](#s)
|
|
54
|
-
- [E](#e)
|
|
55
|
-
- [Things to Know](#Things-to-Know)
|
|
56
|
-
- [Contributing](#Contributing)
|
|
57
|
-
- [License](#License)
|
|
58
|
-
|
|
59
|
-
## Installation
|
|
60
|
-
|
|
61
|
-
Run the following command in your project folder.
|
|
15
|
+
❤️ Thank you @jonsherrard from [Devular](https://www.devular.com/) for your contribution.
|
|
62
16
|
|
|
63
|
-
|
|
64
|
-
npm install @bentonow/bento-node-sdk --save
|
|
65
|
-
```
|
|
17
|
+
[](https://github.com/bentonow/bento-node-sdk/actions/workflows/main.yml)
|
|
66
18
|
|
|
67
|
-
|
|
19
|
+
Table of contents
|
|
20
|
+
=================
|
|
68
21
|
|
|
69
|
-
To get started with tracking things in Bento, simply initialize the client and run wild!
|
|
70
22
|
|
|
71
|
-
|
|
72
|
-
|
|
23
|
+
* [Features](#features)
|
|
24
|
+
* [Requirements](#requirements)
|
|
25
|
+
* [Getting started](#getting-started)
|
|
26
|
+
* [Installation](#installation)
|
|
27
|
+
* [Integration](#integration)
|
|
28
|
+
* [Modules](#modules)
|
|
29
|
+
* [Type Reference](#types-reference)
|
|
30
|
+
* [Things to know](#things-to-know)
|
|
31
|
+
* [Contributing](#contributing)
|
|
32
|
+
* [License](#license)
|
|
73
33
|
|
|
74
|
-
const bento = new Analytics({
|
|
75
|
-
authentication: {
|
|
76
|
-
publishableKey: 'publishableKey',
|
|
77
|
-
secretKey: 'secretKey',
|
|
78
|
-
},
|
|
79
|
-
logErrors: false, // Set to true to see the HTTP errors logged
|
|
80
|
-
siteUuid: 'siteUuid',
|
|
81
|
-
});
|
|
82
34
|
|
|
83
|
-
|
|
84
|
-
email: 'test@bentonow.com',
|
|
85
|
-
})
|
|
86
|
-
.then(result => console.log(result))
|
|
87
|
-
.catch(error => console.error(error));
|
|
35
|
+
## Features
|
|
88
36
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
})
|
|
96
|
-
.then(result => console.log(result))
|
|
97
|
-
.catch(error => console.error(error));
|
|
37
|
+
* **Simple event tracking**: We make it easy for you to track user events and behavior in your application.
|
|
38
|
+
* **Subscriber management**: Easily add, update, and remove subscribers from your Bento account.
|
|
39
|
+
* **Custom fields**: Track and update custom fields for your subscribers to store additional data.
|
|
40
|
+
* **Purchase tracking**: Monitor customer purchases and calculate lifetime value (LTV) for your subscribers.
|
|
41
|
+
* **Batch operations**: Perform bulk imports of subscribers and events for efficient data management.
|
|
42
|
+
* **TypeScript support**: The SDK is written in TypeScript and provides type definitions for a better development experience.
|
|
98
43
|
|
|
99
|
-
|
|
100
|
-
email: 'test@bentonow.com',
|
|
101
|
-
purchaseDetails: {
|
|
102
|
-
unique: { key: 1234 },
|
|
103
|
-
value: { amount: 100, currency: 'USD' },
|
|
104
|
-
},
|
|
105
|
-
cart: {
|
|
106
|
-
abandoned_checkout_url: '',
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
Read on to see what all you can do with the SDK.
|
|
112
|
-
|
|
113
|
-
# Modules
|
|
114
|
-
|
|
115
|
-
In addition to the top-level Analytics object, we also provide access to other parts of the API behind their corresponding modules. You can access these off of the main `Analytics` object.
|
|
44
|
+
## Requirements
|
|
116
45
|
|
|
117
|
-
The
|
|
46
|
+
The Bento Node.js SDK requires Node.js version 12 or later.
|
|
118
47
|
|
|
119
|
-
|
|
48
|
+
Bento Account for a valid **SITE_UUID**, **BENTO_PUBLISHABLE_KEY** & **BENTO_SECRET_KEY**.
|
|
120
49
|
|
|
121
|
-
|
|
50
|
+
## Getting started
|
|
122
51
|
|
|
123
|
-
|
|
52
|
+
### Installation
|
|
124
53
|
|
|
125
|
-
|
|
54
|
+
Install the Bento SDK in your project folder:
|
|
126
55
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
|
|
56
|
+
```bash
|
|
130
57
|
|
|
131
|
-
|
|
58
|
+
# Using npm
|
|
59
|
+
npm install @bentonow/bento-node-sdk --save
|
|
132
60
|
|
|
133
|
-
|
|
134
|
-
bento
|
|
135
|
-
email: 'test@bentonow.com',
|
|
136
|
-
tagName: 'Test Tag',
|
|
137
|
-
})
|
|
138
|
-
.then(result => console.log(result))
|
|
139
|
-
.catch(error => console.error(error));
|
|
61
|
+
# Using Bun
|
|
62
|
+
bun add @bentonow/bento-node-sdk
|
|
140
63
|
```
|
|
141
64
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
**This TRIGGERS automations!** - If you do not wish to trigger automations, please use the [`Commands.subscribe`](#commandssubscribeparameters-subscribeparameters-promisesubscribers--null) method.
|
|
147
|
-
|
|
148
|
-
Creates a subscriber in the system. If the subscriber already exists, another subscribe event will be sent, triggering any automations that take place upon subscription. Please be aware of the potential consequences.
|
|
65
|
+
### Using Bun (Recommended)
|
|
66
|
+
```bash
|
|
67
|
+
# Install dependencies
|
|
68
|
+
bun install
|
|
149
69
|
|
|
150
|
-
|
|
70
|
+
# Run tests
|
|
71
|
+
bun test
|
|
151
72
|
|
|
152
|
-
|
|
73
|
+
# Run tests with coverage
|
|
74
|
+
bun test:coverage
|
|
153
75
|
|
|
154
|
-
|
|
76
|
+
# Build the package
|
|
77
|
+
bun run build
|
|
155
78
|
|
|
156
|
-
|
|
79
|
+
# Lint code
|
|
80
|
+
bun run lint
|
|
157
81
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
email: 'test@bentonow.com',
|
|
161
|
-
})
|
|
162
|
-
.then(result => console.log(result))
|
|
163
|
-
.catch(error => console.error(error));
|
|
164
|
-
|
|
165
|
-
bento.V1.addSubscriber({
|
|
166
|
-
date: new Date('2021-08-20T01:32:57.530Z'),
|
|
167
|
-
email: 'test@bentonow.com',
|
|
168
|
-
fields: {
|
|
169
|
-
firstName: 'Test',
|
|
170
|
-
lastName: 'Subscriber',
|
|
171
|
-
},
|
|
172
|
-
})
|
|
173
|
-
.then(result => console.log(result))
|
|
174
|
-
.catch(error => console.error(error));
|
|
82
|
+
# Format code
|
|
83
|
+
bun run format
|
|
175
84
|
```
|
|
176
85
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
**This TRIGGERS automations!** - If you do not wish to trigger automations, please use the [`Commands.unsubscribe`](#commandsunsubscribeparameters-unsubscribeparameters-promisesubscribers--null) method.
|
|
86
|
+
### Using npm
|
|
87
|
+
```bash
|
|
88
|
+
# Install dependencies
|
|
89
|
+
npm install
|
|
182
90
|
|
|
183
|
-
|
|
91
|
+
# Run tests
|
|
92
|
+
npm run test:npm
|
|
184
93
|
|
|
185
|
-
|
|
94
|
+
# Run tests with coverage
|
|
95
|
+
npm run test:coverage:npm
|
|
186
96
|
|
|
187
|
-
|
|
97
|
+
# Build the package
|
|
98
|
+
npm run build:npm
|
|
188
99
|
|
|
189
|
-
|
|
100
|
+
# Lint code
|
|
101
|
+
npm run lint
|
|
190
102
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
email: 'test@bentonow.com',
|
|
194
|
-
})
|
|
195
|
-
.then(result => console.log(result))
|
|
196
|
-
.catch(error => console.error(error));
|
|
103
|
+
# Format code
|
|
104
|
+
npm run format
|
|
197
105
|
```
|
|
198
106
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
### `updateFields(parameters: UpdateFieldsParameters<S>): Promise<boolean>`
|
|
107
|
+
### Integration
|
|
202
108
|
|
|
203
|
-
|
|
109
|
+
Initialize the Bento client and start tracking events:
|
|
204
110
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
|
|
208
|
-
|
|
209
|
-
Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
|
|
111
|
+
```javascript
|
|
112
|
+
import { Analytics } from '@bentonow/bento-node-sdk';
|
|
210
113
|
|
|
211
|
-
|
|
114
|
+
const bento = new Analytics({
|
|
115
|
+
authentication: {
|
|
116
|
+
publishableKey: 'bento-publishable-key',
|
|
117
|
+
secretKey: 'bento-secret-key',
|
|
118
|
+
},
|
|
119
|
+
siteUuid: 'bento-site-uuid',
|
|
120
|
+
});
|
|
212
121
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
122
|
+
bento.V1.track({
|
|
123
|
+
email: 'user@example.com',
|
|
124
|
+
type: '$formSubmitted',
|
|
216
125
|
fields: {
|
|
217
|
-
|
|
126
|
+
first_name: 'John',
|
|
127
|
+
last_name: 'Doe',
|
|
218
128
|
},
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
129
|
+
details: {
|
|
130
|
+
fromCustomEvent: true,
|
|
131
|
+
},
|
|
132
|
+
}).then(result => console.log(result));
|
|
222
133
|
```
|
|
223
134
|
|
|
224
|
-
---
|
|
225
135
|
|
|
226
|
-
|
|
136
|
+
## Modules
|
|
137
|
+
The Bento SDK provides several modules for different operations:
|
|
227
138
|
|
|
228
|
-
|
|
139
|
+
### Analytics (Base Module)
|
|
229
140
|
|
|
230
|
-
|
|
141
|
+
Core functionality for tracking events and managing subscribers.
|
|
231
142
|
|
|
232
|
-
|
|
143
|
+
### Convenience Helpers
|
|
144
|
+
#### tagSubscriber
|
|
145
|
+
Tags a subscriber with a specific tag.
|
|
233
146
|
|
|
234
|
-
|
|
147
|
+
```javascript
|
|
148
|
+
bento.V1.tagSubscriber({
|
|
149
|
+
email: 'user@example.com',
|
|
150
|
+
tagName: 'New Customer',
|
|
151
|
+
}).then(result => console.log(result));
|
|
152
|
+
```
|
|
235
153
|
|
|
236
|
-
|
|
154
|
+
#### addSubscriber
|
|
155
|
+
Adds a new subscriber to your Bento account.
|
|
237
156
|
|
|
238
|
-
```
|
|
239
|
-
bento.V1.
|
|
240
|
-
email: '
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
},
|
|
245
|
-
value: {
|
|
246
|
-
amount: 100,
|
|
247
|
-
currency: 'USD',
|
|
248
|
-
},
|
|
157
|
+
```javascript
|
|
158
|
+
bento.V1.addSubscriber({
|
|
159
|
+
email: 'newuser@example.com',
|
|
160
|
+
fields: {
|
|
161
|
+
firstName: 'John',
|
|
162
|
+
lastName: 'Doe',
|
|
249
163
|
},
|
|
250
|
-
})
|
|
251
|
-
.then(result => console.log(result))
|
|
252
|
-
.catch(error => console.error(error));
|
|
164
|
+
}).then(result => console.log(result));
|
|
253
165
|
```
|
|
254
166
|
|
|
255
|
-
|
|
167
|
+
#### removeSubscriber
|
|
168
|
+
Removes a subscriber from your Bento account.
|
|
256
169
|
|
|
257
|
-
|
|
170
|
+
```javascript
|
|
171
|
+
bento.V1.removeSubscriber({
|
|
172
|
+
email: 'user@example.com',
|
|
173
|
+
}).then(result => console.log(result));
|
|
174
|
+
```
|
|
258
175
|
|
|
259
|
-
|
|
176
|
+
#### upsertSubscriber
|
|
177
|
+
Updates existing subscriber or creates a new one if they don't exist:
|
|
260
178
|
|
|
261
|
-
|
|
179
|
+
```javascript
|
|
180
|
+
await analytics.V1.upsertSubscriber({
|
|
181
|
+
email: 'user@example.com',
|
|
182
|
+
fields: {
|
|
183
|
+
firstName: 'John',
|
|
184
|
+
lastName: 'Doe',
|
|
185
|
+
company: 'Acme Inc'
|
|
186
|
+
},
|
|
187
|
+
tags: 'lead,mql',
|
|
188
|
+
remove_tags: 'customer'
|
|
189
|
+
});
|
|
190
|
+
```
|
|
262
191
|
|
|
263
|
-
Because this method uses the batch API, the tag may take between 1 and 3 minutes to appear in the system.
|
|
264
192
|
|
|
265
|
-
Returns `true` if the event was successfully dispatched. Returns `false` otherwise.
|
|
266
193
|
|
|
267
|
-
|
|
194
|
+
#### updateFields
|
|
195
|
+
Updates custom fields for a subscriber.
|
|
268
196
|
|
|
269
|
-
```
|
|
270
|
-
bento.V1.
|
|
271
|
-
email: '
|
|
272
|
-
type: '$custom.event',
|
|
197
|
+
```javascript
|
|
198
|
+
bento.V1.updateFields({
|
|
199
|
+
email: 'user@example.com',
|
|
273
200
|
fields: {
|
|
274
|
-
|
|
275
|
-
lastName: 'Custom Name',
|
|
201
|
+
lastPurchaseDate: new Date(),
|
|
276
202
|
},
|
|
277
|
-
|
|
278
|
-
fromCustomEvent: true,
|
|
279
|
-
},
|
|
280
|
-
})
|
|
281
|
-
.then(result => console.log(result))
|
|
282
|
-
.catch(error => console.error(error));
|
|
203
|
+
}).then(result => console.log(result));
|
|
283
204
|
```
|
|
284
205
|
|
|
285
|
-
|
|
206
|
+
#### track
|
|
207
|
+
Tracks a custom event for a subscriber.
|
|
286
208
|
|
|
287
|
-
|
|
209
|
+
```javascript
|
|
210
|
+
bento.V1.track({
|
|
211
|
+
email: 'user@example.com',
|
|
212
|
+
type: '$pageView',
|
|
213
|
+
details: {
|
|
214
|
+
url: '/products',
|
|
215
|
+
},
|
|
216
|
+
}).then(result => console.log(result));
|
|
217
|
+
```
|
|
288
218
|
|
|
289
|
-
|
|
219
|
+
#### trackPurchase
|
|
220
|
+
Tracks a purchase event for a subscriber.
|
|
290
221
|
|
|
291
|
-
|
|
222
|
+
```javascript
|
|
223
|
+
bento.V1.trackPurchase({
|
|
224
|
+
email: 'user@example.com',
|
|
225
|
+
purchaseDetails: {
|
|
226
|
+
unique: { key: 'order-123' },
|
|
227
|
+
value: { amount: 9999, currency: 'USD' },
|
|
228
|
+
},
|
|
229
|
+
}).then(result => console.log(result));
|
|
230
|
+
```
|
|
292
231
|
|
|
293
|
-
|
|
232
|
+
### Low Level API calls
|
|
233
|
+
### Batch
|
|
294
234
|
|
|
295
|
-
|
|
235
|
+
Perform bulk operations for importing subscribers and events.
|
|
296
236
|
|
|
297
|
-
|
|
237
|
+
#### importSubscribers
|
|
238
|
+
Imports multiple subscribers in a single operation.
|
|
298
239
|
|
|
299
|
-
```
|
|
240
|
+
```javascript
|
|
300
241
|
bento.V1.Batch.importSubscribers({
|
|
301
242
|
subscribers: [
|
|
302
|
-
{
|
|
303
|
-
|
|
304
|
-
age: 21,
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
email: 'test2@bentonow.com',
|
|
308
|
-
some_custom_variable: 'tester-123',
|
|
309
|
-
primary_user: true,
|
|
310
|
-
},
|
|
311
|
-
{
|
|
312
|
-
email: 'test3@bentonow.com',
|
|
313
|
-
name: 'Test User',
|
|
314
|
-
},
|
|
243
|
+
{ email: 'user1@example.com', firstName: 'Alice' },
|
|
244
|
+
{ email: 'user2@example.com', firstName: 'Bob' },
|
|
315
245
|
],
|
|
316
|
-
})
|
|
317
|
-
.then(result => console.log(result))
|
|
318
|
-
.catch(error => console.error(error));
|
|
246
|
+
}).then(result => console.log(result));
|
|
319
247
|
```
|
|
320
248
|
|
|
321
|
-
|
|
249
|
+
#### importEvents
|
|
250
|
+
Imports multiple events in a single operation.
|
|
322
251
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
Creates a batch job to import events into the system. You can pass in between 1 and 100 events to import. Each event must have an email and a type. In addition to this, you my pass in additional data in the `details` property,
|
|
326
|
-
|
|
327
|
-
Returns the number of events that were imported.
|
|
328
|
-
|
|
329
|
-
Reference Types: [BatchImportEventsParameter<S, E>](#batchimporteventsparameterse)
|
|
330
|
-
|
|
331
|
-
```ts
|
|
252
|
+
```javascript
|
|
332
253
|
bento.V1.Batch.importEvents({
|
|
333
254
|
events: [
|
|
334
|
-
{
|
|
335
|
-
|
|
336
|
-
type: BentoEvents.SUBSCRIBE,
|
|
337
|
-
},
|
|
338
|
-
{
|
|
339
|
-
email: 'test@bentonow.com',
|
|
340
|
-
type: BentoEvents.UNSUBSCRIBE,
|
|
341
|
-
},
|
|
342
|
-
{
|
|
343
|
-
email: 'test@bentonow.com',
|
|
344
|
-
type: BentoEvents.REMOVE_TAG,
|
|
345
|
-
details: {
|
|
346
|
-
tag: 'tag_to_remove',
|
|
347
|
-
},
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
email: 'test@bentonow.com',
|
|
351
|
-
type: BentoEvents.TAG,
|
|
352
|
-
details: {
|
|
353
|
-
tag: 'tag_to_add',
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
{
|
|
357
|
-
email: 'test@bentonow.com',
|
|
358
|
-
details: {
|
|
359
|
-
customData: 'Used internally.',
|
|
360
|
-
},
|
|
361
|
-
type: '$custom.myEvent,
|
|
362
|
-
},
|
|
255
|
+
{ email: 'user@example.com', type: '$login' },
|
|
256
|
+
{ email: 'user@example.com', type: '$pageView', details: { url: '/home' } },
|
|
363
257
|
],
|
|
364
|
-
})
|
|
365
|
-
.then(result => console.log(result))
|
|
366
|
-
.catch(error => console.error(error));
|
|
258
|
+
}).then(result => console.log(result));
|
|
367
259
|
```
|
|
368
260
|
|
|
369
|
-
---
|
|
370
|
-
|
|
371
|
-
### `Batch.sendTransactionalEmails(parameters: BatchsendTransactionalEmailsParameter<S, E>): Promise<number>`
|
|
372
261
|
|
|
373
|
-
|
|
262
|
+
### Broadcast Management
|
|
374
263
|
|
|
375
|
-
|
|
264
|
+
#### getBroadcasts
|
|
265
|
+
Retrieves all broadcasts:
|
|
376
266
|
|
|
377
|
-
|
|
267
|
+
```javascript
|
|
268
|
+
const broadcasts = await analytics.V1.Broadcasts.getBroadcasts();
|
|
269
|
+
```
|
|
378
270
|
|
|
379
|
-
|
|
271
|
+
#### createBroadcast
|
|
272
|
+
Creates new broadcast campaigns:
|
|
273
|
+
|
|
274
|
+
```javascript
|
|
275
|
+
const broadcasts = await analytics.V1.Broadcasts.createBroadcast([{
|
|
276
|
+
name: 'Weekly Newsletter',
|
|
277
|
+
subject: 'Your Weekly Update',
|
|
278
|
+
content: '<p>Hi {{ name }},</p>...',
|
|
279
|
+
type: 'html',
|
|
280
|
+
from: {
|
|
281
|
+
name: 'John Doe',
|
|
282
|
+
email: 'john@example.com'
|
|
283
|
+
},
|
|
284
|
+
inclusive_tags: 'lead,mql',
|
|
285
|
+
exclusive_tags: 'unsubscribed',
|
|
286
|
+
segment_id: 'segment_123',
|
|
287
|
+
batch_size_per_hour: 1000
|
|
288
|
+
}]);
|
|
289
|
+
```
|
|
380
290
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
291
|
+
### Transactional Emails
|
|
292
|
+
|
|
293
|
+
#### createEmails
|
|
294
|
+
Creates a new transactional email:
|
|
295
|
+
|
|
296
|
+
```javascript
|
|
297
|
+
const result = await bento.V1.Batch.sendTransactionalEmails({
|
|
298
|
+
emails: [{
|
|
299
|
+
to: 'recipient@example.com', // just the email, recipient name is ignored.
|
|
300
|
+
from: 'sender@example.com', // MUST be an existing Author in your account (Emails -> Authors)
|
|
301
|
+
subject: 'Welcome {{ name }}',
|
|
302
|
+
html_body: '<p>Hello {{ name }}, welcome to our service!</p>',
|
|
303
|
+
transactional: false, // Set to true to send as a transactional email IF you want to ignore if the user has unsubscribed. USE WITH CAUTION!
|
|
304
|
+
personalizations: {
|
|
305
|
+
name: 'John Doe',
|
|
306
|
+
}
|
|
307
|
+
}]
|
|
308
|
+
});
|
|
309
|
+
```
|
|
310
|
+
### Email Structure
|
|
311
|
+
Each email object requires:
|
|
312
|
+
|
|
313
|
+
- **to:** Recipient email address
|
|
314
|
+
- **from:** Sender email address
|
|
315
|
+
- **subject:** Email subject (supports liquid templates)
|
|
316
|
+
- **html_body:** HTML email content (supports liquid templates)
|
|
317
|
+
- **transactional:** true/false: defaults to false, must be true to send to unsubscribed users
|
|
318
|
+
- **personalizations:** Optional object for liquid template variables
|
|
319
|
+
|
|
320
|
+
#### Constraints
|
|
321
|
+
|
|
322
|
+
- **Batch size:** 1-100 emails per request
|
|
323
|
+
- **Errors:** Throws TooFewEmailsError or TooManyEmailsError for invalid counts
|
|
324
|
+
- **Returns:** Number of emails successfully queued
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
### Statistics
|
|
328
|
+
|
|
329
|
+
#### getSiteStats
|
|
330
|
+
Retrieves overall site statistics:
|
|
331
|
+
|
|
332
|
+
```javascript
|
|
333
|
+
const stats = await analytics.V1.Stats.getSiteStats();
|
|
334
|
+
// Returns:
|
|
335
|
+
// {
|
|
336
|
+
// total_subscribers: 1000,
|
|
337
|
+
// active_subscribers: 950,
|
|
338
|
+
// unsubscribed_count: 50,
|
|
339
|
+
// broadcast_count: 25,
|
|
340
|
+
// average_open_rate: 45.5,
|
|
341
|
+
// average_click_rate: 12.3
|
|
342
|
+
// }
|
|
398
343
|
```
|
|
399
344
|
|
|
400
|
-
|
|
345
|
+
#### getSegmentStats
|
|
346
|
+
Retrieves statistics for a specific segment:
|
|
347
|
+
|
|
348
|
+
```javascript
|
|
349
|
+
const segmentStats = await analytics.V1.Stats.getSegmentStats('segment_123');
|
|
350
|
+
// Returns:
|
|
351
|
+
// {
|
|
352
|
+
// segment_id: 'segment_123',
|
|
353
|
+
// subscriber_count: 500,
|
|
354
|
+
// growth_rate: 2.5,
|
|
355
|
+
// engagement_rate: 35.8,
|
|
356
|
+
// last_updated: '2024-01-01T00:00:00Z'
|
|
357
|
+
// }
|
|
358
|
+
```
|
|
401
359
|
|
|
402
|
-
|
|
360
|
+
#### getReportStats
|
|
361
|
+
Retrieves statistics for a specific report:
|
|
362
|
+
|
|
363
|
+
```javascript
|
|
364
|
+
const reportStats = await analytics.V1.Stats.getReportStats('report_123');
|
|
365
|
+
// Returns:
|
|
366
|
+
// {
|
|
367
|
+
// report_id: 'report_123',
|
|
368
|
+
// total_sent: 1000,
|
|
369
|
+
// total_opens: 750,
|
|
370
|
+
// unique_opens: 500,
|
|
371
|
+
// total_clicks: 250,
|
|
372
|
+
// unique_clicks: 200,
|
|
373
|
+
// unsubscribes: 5,
|
|
374
|
+
// spam_reports: 1
|
|
375
|
+
// }
|
|
376
|
+
```
|
|
403
377
|
|
|
404
|
-
**This does not trigger automations!** - If you wish to trigger automations, please use the core module's `tagSubscriber` method.
|
|
405
378
|
|
|
406
|
-
|
|
379
|
+
### Commands
|
|
407
380
|
|
|
408
|
-
|
|
381
|
+
Execute specific commands for subscriber management.
|
|
409
382
|
|
|
410
|
-
|
|
383
|
+
#### addTag
|
|
384
|
+
Adds a tag to a subscriber.
|
|
411
385
|
|
|
412
|
-
```
|
|
386
|
+
```javascript
|
|
413
387
|
bento.V1.Commands.addTag({
|
|
414
|
-
email: '
|
|
415
|
-
tagName: '
|
|
416
|
-
})
|
|
417
|
-
.then(result => console.log(result))
|
|
418
|
-
.catch(error => console.error(error));
|
|
388
|
+
email: 'user@example.com',
|
|
389
|
+
tagName: 'VIP',
|
|
390
|
+
}).then(result => console.log(result));
|
|
419
391
|
```
|
|
420
392
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
### `Commands.removeTag(parameters: RemoveTagParameters): Promise<Subscriber<S> | null>`
|
|
393
|
+
#### removeTag
|
|
394
|
+
Removes a tag from a subscriber.
|
|
424
395
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
Reference Types: [RemoveTagParameters](#RemoveTagParameters), [Subscriber\<S\>](#subscribers)
|
|
428
|
-
|
|
429
|
-
```ts
|
|
396
|
+
```javascript
|
|
430
397
|
bento.V1.Commands.removeTag({
|
|
431
|
-
email: '
|
|
432
|
-
tagName: '
|
|
433
|
-
})
|
|
434
|
-
.then(result => console.log(result))
|
|
435
|
-
.catch(error => console.error(error));
|
|
398
|
+
email: 'user@example.com',
|
|
399
|
+
tagName: 'VIP',
|
|
400
|
+
}).then(result => console.log(result));
|
|
436
401
|
```
|
|
437
402
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
### `Commands.addField(parameters: AddFieldParameters<S>): Promise<Subscriber<S> | null>`
|
|
441
|
-
|
|
442
|
-
**This does not trigger automations!** - If you wish to trigger automations, please use the core module's `updateFields` method.
|
|
443
|
-
|
|
444
|
-
Adds a field to the subscriber with the matching email.
|
|
403
|
+
#### addField
|
|
404
|
+
Adds a custom field to a subscriber.
|
|
445
405
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
Reference Types: [AddFieldParameters\<S\>](#addfieldparameterss), [Subscriber\<S\>](#subscribers)
|
|
449
|
-
|
|
450
|
-
```ts
|
|
406
|
+
```javascript
|
|
451
407
|
bento.V1.Commands.addField({
|
|
452
|
-
email: '
|
|
408
|
+
email: 'user@example.com',
|
|
453
409
|
field: {
|
|
454
|
-
key: '
|
|
455
|
-
value: '
|
|
410
|
+
key: 'favoriteColor',
|
|
411
|
+
value: 'blue',
|
|
456
412
|
},
|
|
457
|
-
})
|
|
458
|
-
.then(result => console.log(result))
|
|
459
|
-
.catch(error => console.error(error));
|
|
413
|
+
}).then(result => console.log(result));
|
|
460
414
|
```
|
|
461
415
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
### `Commands.removeField(parameters: RemoveFieldParameters<S>): Promise<Subscriber<S> | null>`
|
|
465
|
-
|
|
466
|
-
Removes a field to the subscriber with the matching email.
|
|
416
|
+
#### removeField
|
|
417
|
+
Removes a custom field from a subscriber.
|
|
467
418
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
```ts
|
|
419
|
+
```javascript
|
|
471
420
|
bento.V1.Commands.removeField({
|
|
472
|
-
email: '
|
|
473
|
-
fieldName: '
|
|
474
|
-
})
|
|
475
|
-
.then(result => console.log(result))
|
|
476
|
-
.catch(error => console.error(error));
|
|
477
|
-
```
|
|
478
|
-
|
|
479
|
-
---
|
|
480
|
-
|
|
481
|
-
### `Commands.subscribe(parameters: SubscribeParameters): Promise<Subscriber<S> | null>`
|
|
482
|
-
|
|
483
|
-
**This does not trigger automations!** - If you wish to trigger automations, please use the core module's `addSubscriber` method.
|
|
484
|
-
|
|
485
|
-
Subscribes the supplied email to Bento. If the email does not exist, it is created.
|
|
486
|
-
|
|
487
|
-
If the subscriber had previously unsubscribed, they will be re-subscribed.
|
|
488
|
-
|
|
489
|
-
Reference Types: [SubscribeParameters](#SubscribeParameters), [Subscriber\<S\>](#subscribers)
|
|
490
|
-
|
|
491
|
-
```ts
|
|
492
|
-
bento.V1.Commands.subscribe({
|
|
493
|
-
email: 'test@bentonow.com',
|
|
494
|
-
})
|
|
495
|
-
.then(result => console.log(result))
|
|
496
|
-
.catch(error => console.error(error));
|
|
421
|
+
email: 'user@example.com',
|
|
422
|
+
fieldName: 'favoriteColor',
|
|
423
|
+
}).then(result => console.log(result));
|
|
497
424
|
```
|
|
498
425
|
|
|
499
|
-
|
|
426
|
+
### Experimental
|
|
500
427
|
|
|
501
|
-
|
|
428
|
+
Access experimental features (use with caution).
|
|
502
429
|
|
|
503
|
-
|
|
430
|
+
#### validateEmail
|
|
431
|
+
Attempts to validate an email address.
|
|
504
432
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
Reference Types: [UnsubscribeParameters](#UnsubscribeParameters), [Subscriber\<S\>](#subscribers)
|
|
508
|
-
|
|
509
|
-
```ts
|
|
510
|
-
bento.V1.Commands.unsubscribe({
|
|
511
|
-
email: 'test@bentonow.com',
|
|
512
|
-
})
|
|
513
|
-
.then(result => console.log(result))
|
|
514
|
-
.catch(error => console.error(error));
|
|
515
|
-
```
|
|
516
|
-
|
|
517
|
-
---
|
|
518
|
-
|
|
519
|
-
### `Commands.changeEmail(parameters: ChangeEmailParameters): Promise<Subscriber<S> | null>`
|
|
520
|
-
|
|
521
|
-
Updates the email of a user in Bento.
|
|
522
|
-
|
|
523
|
-
Reference Types: [ChangeEmailParameters](#changeemailparameters), [Subscriber\<S\>](#subscribers)
|
|
524
|
-
|
|
525
|
-
```ts
|
|
526
|
-
bento.V1.Commands.changeEmail({
|
|
527
|
-
oldEmail: 'test@bentonow.com',
|
|
528
|
-
newEmail: 'new@bentonow.com',
|
|
529
|
-
})
|
|
530
|
-
.then(result => console.log(result))
|
|
531
|
-
.catch(error => console.error(error));
|
|
532
|
-
```
|
|
533
|
-
|
|
534
|
-
## Experimental
|
|
535
|
-
|
|
536
|
-
### `Experimental.validateEmail(parameters: ValidateEmailParameters): Promise<boolean>`
|
|
537
|
-
|
|
538
|
-
**EXPERIMENTAL** - This functionality is experimental and may change or stop working at any time.
|
|
539
|
-
|
|
540
|
-
Attempts to validate the email. You can provide additional information to further refine the validation.
|
|
541
|
-
|
|
542
|
-
If a name is provided, it compares it against the US Census Data, and so the results may be biased.
|
|
543
|
-
|
|
544
|
-
Reference Types: [ValidateEmailParameters](#ValidateEmailParameters)
|
|
545
|
-
|
|
546
|
-
```ts
|
|
433
|
+
```javascript
|
|
547
434
|
bento.V1.Experimental.validateEmail({
|
|
548
|
-
email: '
|
|
549
|
-
})
|
|
550
|
-
.then(result => console.log(result))
|
|
551
|
-
.catch(error => console.error(error));
|
|
435
|
+
email: 'user@example.com',
|
|
436
|
+
}).then(result => console.log(result));
|
|
552
437
|
```
|
|
553
438
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
### `Experimental.guessGender(parameters: GuessGenderParameters): Promise<GuessGenderResponse>`
|
|
557
|
-
|
|
558
|
-
**EXPERIMENTAL** - This functionality is experimental and may change or stop working at any time.
|
|
439
|
+
#### guessGender
|
|
440
|
+
Attempts to guess the gender based on a given name.
|
|
559
441
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
It is possible for the gender to be unknown if the system cannot confidently conclude what gender it may be.
|
|
563
|
-
|
|
564
|
-
Reference Types: [GuessGenderParameters](#GuessGenderParameters), [GuessGenderResponse](#GuessGenderResponse)
|
|
565
|
-
|
|
566
|
-
```ts
|
|
442
|
+
```javascript
|
|
567
443
|
bento.V1.Experimental.guessGender({
|
|
568
|
-
name: '
|
|
569
|
-
})
|
|
570
|
-
.then(result => console.log(result))
|
|
571
|
-
.catch(error => console.error(error));
|
|
444
|
+
name: 'Alex',
|
|
445
|
+
}).then(result => console.log(result));
|
|
572
446
|
```
|
|
573
447
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
### `Experimental.geolocate(parameters: GeolocateParameters): Promise<LocationData | null>`
|
|
577
|
-
|
|
578
|
-
**EXPERIMENTAL** - This functionality is experimental and may change or stop working at any time.
|
|
448
|
+
is blacklisted:
|
|
579
449
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
bento.V1.Experimental.geolocate({
|
|
586
|
-
ip: '127.0.0.1',
|
|
587
|
-
})
|
|
588
|
-
.then(result => console.log(result))
|
|
589
|
-
.catch(error => console.error(error));
|
|
450
|
+
```javascript
|
|
451
|
+
const blacklistStatus = await analytics.V1.Experimental.getBlacklistStatus({
|
|
452
|
+
domain: 'example.com'
|
|
453
|
+
// or ipAddress: '192.168.1.1'
|
|
454
|
+
});
|
|
590
455
|
```
|
|
591
456
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
457
|
+
#### getContentModeration
|
|
458
|
+
Performs content moderation on text:
|
|
459
|
+
|
|
460
|
+
```javascript
|
|
461
|
+
const moderationResult = await analytics.V1.Experimental.getContentModeration(
|
|
462
|
+
'Content to moderate'
|
|
463
|
+
);
|
|
464
|
+
// Returns:
|
|
465
|
+
// {
|
|
466
|
+
// flagged: boolean,
|
|
467
|
+
// categories: {
|
|
468
|
+
// hate: boolean,
|
|
469
|
+
// 'hate/threatening': boolean,
|
|
470
|
+
// 'self-harm': boolean,
|
|
471
|
+
// ...
|
|
472
|
+
// },
|
|
473
|
+
// category_scores: {
|
|
474
|
+
// hate: number,
|
|
475
|
+
// 'hate/threatening': number,
|
|
476
|
+
// ...
|
|
477
|
+
// }
|
|
478
|
+
// }
|
|
608
479
|
```
|
|
609
480
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
.catch(error => console.error(error));
|
|
481
|
+
#### geoLocateIP
|
|
482
|
+
Gets detailed geolocation information for an IP address:
|
|
483
|
+
|
|
484
|
+
```javascript
|
|
485
|
+
const location = await analytics.V1.Experimental.geoLocateIP('192.168.1.1');
|
|
486
|
+
// Returns:
|
|
487
|
+
// {
|
|
488
|
+
// city_name: 'San Francisco',
|
|
489
|
+
// country_name: 'United States',
|
|
490
|
+
// latitude: 37.7749,
|
|
491
|
+
// longitude: -122.4194,
|
|
492
|
+
// ...
|
|
493
|
+
// }
|
|
624
494
|
```
|
|
625
495
|
|
|
626
|
-
|
|
496
|
+
### Fields
|
|
627
497
|
|
|
628
|
-
|
|
498
|
+
Manage custom fields for your subscribers.
|
|
629
499
|
|
|
630
|
-
|
|
500
|
+
#### getFields
|
|
501
|
+
Retrieves all custom fields defined in your Bento account.
|
|
631
502
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
| `'this is a key'` | `'This Is A Key'` |
|
|
636
|
-
| `'this-is-a-key'` | `'This Is A Key'` |
|
|
637
|
-
| `'this_is_a_key'` | `'This Is A Key'` |
|
|
503
|
+
```javascript
|
|
504
|
+
bento.V1.Fields.getFields().then(fields => console.log(fields));
|
|
505
|
+
```
|
|
638
506
|
|
|
639
|
-
|
|
507
|
+
#### createField
|
|
508
|
+
Creates a new custom field in your Bento account.
|
|
640
509
|
|
|
641
|
-
```
|
|
510
|
+
```javascript
|
|
642
511
|
bento.V1.Fields.createField({
|
|
643
|
-
key: '
|
|
644
|
-
})
|
|
645
|
-
.then(result => console.log(result))
|
|
646
|
-
.catch(error => console.error(error));
|
|
512
|
+
key: 'loyaltyPoints',
|
|
513
|
+
}).then(result => console.log(result));
|
|
647
514
|
```
|
|
648
515
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
### `Forms.getResponses(formIdentifier: string): Promise<FormResponse[] | null>`
|
|
516
|
+
### Forms
|
|
652
517
|
|
|
653
|
-
|
|
518
|
+
Retrieve form responses.
|
|
654
519
|
|
|
655
|
-
|
|
520
|
+
#### getResponses
|
|
521
|
+
Retrieves responses for a specific form.
|
|
656
522
|
|
|
657
|
-
```
|
|
658
|
-
bento.V1.Forms.getResponses('
|
|
659
|
-
.then(result => console.log(result))
|
|
660
|
-
.catch(error => console.error(error));
|
|
523
|
+
```javascript
|
|
524
|
+
bento.V1.Forms.getResponses('form-id-123').then(responses => console.log(responses));
|
|
661
525
|
```
|
|
662
526
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
### `Subscribers.getSubscribers(parameters?: GetSubscribersParameters): Promise<Subscriber<S> | null>`
|
|
527
|
+
### Subscribers
|
|
666
528
|
|
|
667
|
-
|
|
529
|
+
Manage individual subscribers.
|
|
668
530
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
```ts
|
|
672
|
-
bento.V1.Subscribers.getSubscribers({
|
|
673
|
-
uuid: '1234',
|
|
674
|
-
})
|
|
675
|
-
.then(result => console.log(result))
|
|
676
|
-
.catch(error => console.error(error));
|
|
531
|
+
#### getSubscribers
|
|
532
|
+
Retrieves subscriber information.
|
|
677
533
|
|
|
534
|
+
```javascript
|
|
678
535
|
bento.V1.Subscribers.getSubscribers({
|
|
679
|
-
email: '
|
|
680
|
-
})
|
|
681
|
-
.then(result => console.log(result))
|
|
682
|
-
.catch(error => console.error(error));
|
|
536
|
+
email: 'user@example.com',
|
|
537
|
+
}).then(subscriber => console.log(subscriber));
|
|
683
538
|
```
|
|
684
539
|
|
|
685
|
-
|
|
540
|
+
#### createSubscriber
|
|
541
|
+
Creates a new subscriber in your Bento account.
|
|
686
542
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
Creates a subscriber inside of Bento.
|
|
690
|
-
|
|
691
|
-
Reference Types: [CreateSubscriberParameters](#CreateSubscriberParameters), [Subscriber\<S\>](#subscribers)
|
|
692
|
-
|
|
693
|
-
```ts
|
|
543
|
+
```javascript
|
|
694
544
|
bento.V1.Subscribers.createSubscriber({
|
|
695
|
-
email: '
|
|
696
|
-
})
|
|
697
|
-
.then(result => console.log(result))
|
|
698
|
-
.catch(error => console.error(error));
|
|
545
|
+
email: 'newuser@example.com',
|
|
546
|
+
}).then(result => console.log(result));
|
|
699
547
|
```
|
|
700
548
|
|
|
701
|
-
|
|
549
|
+
### Tags
|
|
702
550
|
|
|
703
|
-
|
|
551
|
+
Create and manage tags for subscriber segmentation.
|
|
704
552
|
|
|
705
|
-
|
|
553
|
+
#### getTags
|
|
554
|
+
Retrieves all tags defined in your Bento account.
|
|
706
555
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
```ts
|
|
710
|
-
bento.V1.Tags.getTags()
|
|
711
|
-
.then(result => console.log(result))
|
|
712
|
-
.catch(error => console.error(error));
|
|
556
|
+
```javascript
|
|
557
|
+
bento.V1.Tags.getTags().then(tags => console.log(tags));
|
|
713
558
|
```
|
|
714
559
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
### `Tags.createTag(parameters: CreateTagParameters): Promise<Tag[] | null>`
|
|
560
|
+
#### createTag
|
|
561
|
+
Creates a new tag in your Bento account.
|
|
718
562
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
Reference Types: [Tag](#Tag)
|
|
722
|
-
|
|
723
|
-
```ts
|
|
563
|
+
```javascript
|
|
724
564
|
bento.V1.Tags.createTag({
|
|
725
|
-
name: '
|
|
726
|
-
})
|
|
727
|
-
.then(result => console.log(result))
|
|
728
|
-
.catch(error => console.error(error));
|
|
565
|
+
name: 'Premium Customer',
|
|
566
|
+
}).then(result => console.log(result));
|
|
729
567
|
```
|
|
730
568
|
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
### `AddFieldParameters<S>`
|
|
734
|
-
|
|
735
|
-
The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
736
|
-
|
|
737
|
-
| Property | Type | Default | Required |
|
|
738
|
-
| -------- | ------------------------------ | ------- | -------- |
|
|
739
|
-
| email | `string` | _none_ | ✔️ |
|
|
740
|
-
| field | `{ key: keyof S; value: any }` | _none_ | ✔️ |
|
|
741
|
-
|
|
742
|
-
---
|
|
743
|
-
|
|
744
|
-
### `AddSubscriberParameters<S>`
|
|
745
|
-
|
|
746
|
-
The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
747
|
-
|
|
748
|
-
| Property | Type | Default | Required |
|
|
749
|
-
| -------- | ------------ | ------- | -------- |
|
|
750
|
-
| date | `Date` | _none_ | ❌ |
|
|
751
|
-
| email | `string` | _none_ | ✔️ |
|
|
752
|
-
| fields | `Partial<S>` | _none_ | ❌ |
|
|
753
|
-
|
|
754
|
-
---
|
|
755
|
-
|
|
756
|
-
### `AddTagParameters`
|
|
757
|
-
|
|
758
|
-
| Property | Type | Default | Required |
|
|
759
|
-
| -------- | -------- | ------- | -------- |
|
|
760
|
-
| email | `string` | _none_ | ✔️ |
|
|
761
|
-
| tagName | `string` | _none_ | ✔️ |
|
|
762
|
-
|
|
763
|
-
---
|
|
764
|
-
|
|
765
|
-
### `BatchImportEventsParameter<S, E>`
|
|
766
|
-
|
|
767
|
-
The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
768
|
-
|
|
769
|
-
The `E` from above represents the prefix that is used to define your custom events. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
770
|
-
|
|
771
|
-
| Property | Type | Default | Required |
|
|
772
|
-
| -------- | ----------------------------------------- | ------- | -------- |
|
|
773
|
-
| events | [`BentoEvent<S, E>[]`](#BentoEvent<S, E>) | _none_ | ✔️ |
|
|
774
|
-
|
|
775
|
-
---
|
|
776
|
-
|
|
777
|
-
### `BatchImportSubscribersParameter<S>`
|
|
778
|
-
|
|
779
|
-
The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
780
|
-
|
|
781
|
-
| Property | Type | Default | Required |
|
|
782
|
-
| ----------- | ------------------------------------ | ------- | -------- |
|
|
783
|
-
| subscribers | `({ email: string } & Partial<S>)[]` | _none_ | ✔️ |
|
|
784
|
-
|
|
785
|
-
---
|
|
786
|
-
|
|
787
|
-
### `BentoEvent<S, E>`
|
|
788
|
-
|
|
789
|
-
This type is a discriminated union of a few different types. Each of these types are documented below:
|
|
790
|
-
|
|
791
|
-
#### `BaseEvent<E>`
|
|
792
|
-
|
|
793
|
-
The `E` from above represents the prefix that is used to define your custom events. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
794
|
-
|
|
795
|
-
| Property | Type | Default | Required |
|
|
796
|
-
| -------- | ------------------------ | ------- | -------- |
|
|
797
|
-
| date | `Date` | _none_ | ❌ |
|
|
798
|
-
| details | `{ [key: string]: any }` | _none_ | ✔️ |
|
|
799
|
-
| email | `string` | _none_ | ✔️ |
|
|
800
|
-
| type | `string` | _none_ | ✔️ |
|
|
801
|
-
|
|
802
|
-
#### `PurchaseEvent`
|
|
803
|
-
|
|
804
|
-
| Property | Type | Default | Required |
|
|
805
|
-
| -------- | --------------------------------------- | ------- | -------- |
|
|
806
|
-
| date | `Date` | _none_ | ❌ |
|
|
807
|
-
| details | [`PurchaseDetails`](#PurchaseDetails) | _none_ | ✔️ |
|
|
808
|
-
| email | `string` | _none_ | ✔️ |
|
|
809
|
-
| type | `BentoEvents.PURCHASE` \| `'$purchase'` | _none_ | ✔️ |
|
|
810
|
-
|
|
811
|
-
#### `SubscribeEvent<S>`
|
|
812
|
-
|
|
813
|
-
| Property | Type | Default | Required |
|
|
814
|
-
| -------- | ----------------------------------------- | ------- | -------- |
|
|
815
|
-
| date | `Date` | _none_ | ❌ |
|
|
816
|
-
| email | `string` | _none_ | ✔️ |
|
|
817
|
-
| fields | `Partial<S>` | _none_ | ❌ |
|
|
818
|
-
| type | `BentoEvents.SUBSCRIBE` \| `'$subscribe'` | _none_ | ✔️ |
|
|
819
|
-
|
|
820
|
-
#### `TagEvent`
|
|
821
|
-
|
|
822
|
-
| Property | Type | Default | Required |
|
|
823
|
-
| -------- | ----------------------------- | ------- | -------- |
|
|
824
|
-
| date | `Date` | _none_ | ❌ |
|
|
825
|
-
| details | `{ tag: string }` | _none_ | ✔️ |
|
|
826
|
-
| email | `string` | _none_ | ✔️ |
|
|
827
|
-
| type | `BentoEvents.TAG` \| `'$tag'` | _none_ | ✔️ |
|
|
828
|
-
|
|
829
|
-
#### `UnsubscribeEvent`
|
|
830
|
-
|
|
831
|
-
| Property | Type | Default | Required |
|
|
832
|
-
| -------- | --------------------------------------------- | ------- | -------- |
|
|
833
|
-
| date | `Date` | _none_ | ❌ |
|
|
834
|
-
| email | `string` | _none_ | ✔️ |
|
|
835
|
-
| type | `BentoEvents.UNSUBSCRIBE` \| `'$unsubscribe'` | _none_ | ✔️ |
|
|
836
|
-
|
|
837
|
-
#### `UpdateFieldsEvent<S>`
|
|
838
|
-
|
|
839
|
-
The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
840
|
-
|
|
841
|
-
| Property | Type | Default | Required |
|
|
842
|
-
| -------- | ------------------------------------------------- | ------- | -------- |
|
|
843
|
-
| date | `Date` | _none_ | ❌ |
|
|
844
|
-
| email | `string` | _none_ | ✔️ |
|
|
845
|
-
| type | `BentoEvents.UPDATE_FIELDS` \| `'$update_fields'` | _none_ | ✔️ |
|
|
846
|
-
| fields | `Partial<S>` | _none_ | ✔️ |
|
|
847
|
-
|
|
848
|
-
---
|
|
849
|
-
|
|
850
|
-
### `BlacklistParameters`
|
|
851
|
-
|
|
852
|
-
Note that this takes either `domain` _or_ `ip`, but never both.
|
|
853
|
-
|
|
854
|
-
| Property | Type | Default | Required |
|
|
855
|
-
| -------- | -------- | ------- | -------- |
|
|
856
|
-
| domain | `string` | _none_ | ✔️ |
|
|
857
|
-
|
|
858
|
-
| Property | Type | Default | Required |
|
|
859
|
-
| -------- | -------- | ------- | -------- |
|
|
860
|
-
| ip | `string` | _none_ | ✔️ |
|
|
861
|
-
|
|
862
|
-
---
|
|
863
|
-
|
|
864
|
-
### `BlacklistResponse`
|
|
865
|
-
|
|
866
|
-
The results is an object where the key is the name of the blacklist that was checked, and the value is whether or not the domain/IP appeared on that blacklist.
|
|
867
|
-
|
|
868
|
-
| Property | Type | Default | Required |
|
|
869
|
-
| ----------- | ---------------------------- | ------- | -------- |
|
|
870
|
-
| description | `string` | _none_ | ✔️ |
|
|
871
|
-
| query | `string` | _none_ | ✔️ |
|
|
872
|
-
| results | `{ [key: string]: boolean }` | _none_ | ✔️ |
|
|
873
|
-
|
|
874
|
-
---
|
|
875
|
-
|
|
876
|
-
### `BrowserData`
|
|
877
|
-
|
|
878
|
-
| Property | Type | Default | Required |
|
|
879
|
-
| ---------- | -------- | ------- | -------- |
|
|
880
|
-
| height | `string` | _none_ | ✔️ |
|
|
881
|
-
| user_agent | `string` | _none_ | ✔️ |
|
|
882
|
-
| width | `string` | _none_ | ✔️ |
|
|
883
|
-
|
|
884
|
-
---
|
|
885
|
-
|
|
886
|
-
### `ChangeEmailParameters`
|
|
887
|
-
|
|
888
|
-
| Property | Type | Default | Required |
|
|
889
|
-
| -------- | -------- | ------- | -------- |
|
|
890
|
-
| oldEmail | `string` | _none_ | ✔️ |
|
|
891
|
-
| newEmail | `string` | _none_ | ✔️ |
|
|
892
|
-
|
|
893
|
-
---
|
|
894
|
-
|
|
895
|
-
### `CreateFieldParameters`
|
|
896
|
-
|
|
897
|
-
| Property | Type | Default | Required |
|
|
898
|
-
| -------- | -------- | ------- | -------- |
|
|
899
|
-
| key | `string` | _none_ | ✔️ |
|
|
900
|
-
|
|
901
|
-
---
|
|
902
|
-
|
|
903
|
-
### `CreateSubscriberParameters`
|
|
904
|
-
|
|
905
|
-
| Property | Type | Default | Required |
|
|
906
|
-
| -------- | -------- | ------- | -------- |
|
|
907
|
-
| email | `string` | _none_ | ✔️ |
|
|
908
|
-
|
|
909
|
-
### `CreateTagParameters`
|
|
910
|
-
|
|
911
|
-
| Property | Type | Default | Required |
|
|
912
|
-
| -------- | -------- | ------- | -------- |
|
|
913
|
-
| name | `string` | _none_ | ✔️ |
|
|
914
|
-
|
|
915
|
-
---
|
|
569
|
+
For detailed information on each module, refer to the [SDK Documentation](https://docs.bentonow.com/subscribers).
|
|
916
570
|
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
This is an enum with the following values:
|
|
920
|
-
|
|
921
|
-
| Name | Value |
|
|
922
|
-
| --------------- | ------------------- |
|
|
923
|
-
| EVENTS | `'events'` |
|
|
924
|
-
| TAGS | `'tags'` |
|
|
925
|
-
| VISITORS | `'visitors'` |
|
|
926
|
-
| VISITORS_FIELDS | `'visitors-fields'` |
|
|
927
|
-
|
|
928
|
-
---
|
|
929
|
-
|
|
930
|
-
### `Field`
|
|
931
|
-
|
|
932
|
-
| Property | Type | Default | Required |
|
|
933
|
-
| ---------- | ------------------------------------------- | ------- | -------- |
|
|
934
|
-
| attributes | [`FieldAttributes`](#FieldAttributes) | _none_ | ✔️ |
|
|
935
|
-
| id | `string` | _none_ | ✔️ |
|
|
936
|
-
| type | [`EntityType.VISITORS_FIELDS`](#EntityType) | _none_ | ✔️ |
|
|
937
|
-
|
|
938
|
-
---
|
|
939
|
-
|
|
940
|
-
### `FieldAttributes`
|
|
941
|
-
|
|
942
|
-
| Property | Type | Default | Required |
|
|
943
|
-
| ----------- | ------------------- | ------- | -------- |
|
|
944
|
-
| created_at | `string` | _none_ | ✔️ |
|
|
945
|
-
| key | `string` | _none_ | ✔️ |
|
|
946
|
-
| name | `string` | _none_ | ✔️ |
|
|
947
|
-
| whitelisted | `boolean` \| `null` | _none_ | ✔️ |
|
|
948
|
-
|
|
949
|
-
---
|
|
950
|
-
|
|
951
|
-
### `FormResponse`
|
|
952
|
-
|
|
953
|
-
| Property | Type | Default | Required |
|
|
954
|
-
| ---------- | --------------------------------------------------- | ------- | -------- |
|
|
955
|
-
| attributes | [`FormResponseAttributes`](#FormResponseAttributes) | _none_ | ✔️ |
|
|
956
|
-
| id | `string` | _none_ | ✔️ |
|
|
957
|
-
| type | [`EntityType.EVENTS`](#EntityType) | _none_ | ✔️ |
|
|
958
|
-
|
|
959
|
-
---
|
|
960
|
-
|
|
961
|
-
### `FormResponseAttributes`
|
|
962
|
-
|
|
963
|
-
| Property | Type | Default | Required |
|
|
964
|
-
| -------- | --------------------------------------- | ------- | -------- |
|
|
965
|
-
| data | [`FormResponseData`](#FormResponseData) | _none_ | ✔️ |
|
|
966
|
-
| uuid | `string` | _none_ | ✔️ |
|
|
967
|
-
|
|
968
|
-
---
|
|
969
|
-
|
|
970
|
-
### `FormResponseData`
|
|
971
|
-
|
|
972
|
-
| Property | Type | Default | Required |
|
|
973
|
-
| -------- | ------------------------------- | ------- | -------- |
|
|
974
|
-
| browser | [`BrowserData`](#BrowserData) | _none_ | ✔️ |
|
|
975
|
-
| date | `string` | _none_ | ✔️ |
|
|
976
|
-
| details | `{ [key: string]: any }` | _none_ | ✔️ |
|
|
977
|
-
| fields | `{ [key: string]: any }` | _none_ | ✔️ |
|
|
978
|
-
| id | `string` | _none_ | ✔️ |
|
|
979
|
-
| identity | [`IdentityData`](#IdentityData) | _none_ | ✔️ |
|
|
980
|
-
| ip | `string` | _none_ | ✔️ |
|
|
981
|
-
| location | [`LocationData`](#LocationData) | _none_ | ✔️ |
|
|
982
|
-
| page | [`PageData`](#PageData) | _none_ | ✔️ |
|
|
983
|
-
| site | `string` | _none_ | ✔️ |
|
|
984
|
-
| type | `string` | _none_ | ✔️ |
|
|
985
|
-
| visit | `string` | _none_ | ✔️ |
|
|
986
|
-
| visitor | `string` | _none_ | ✔️ |
|
|
987
|
-
|
|
988
|
-
---
|
|
989
|
-
|
|
990
|
-
### `GetSubscribersParameters`
|
|
991
|
-
|
|
992
|
-
Note that this takes either `email` _or_ `uuid`, but never both.
|
|
993
|
-
|
|
994
|
-
| Property | Type | Default | Required |
|
|
995
|
-
| -------- | -------- | ------- | -------- |
|
|
996
|
-
| email | `string` | _none_ | ✔️ |
|
|
997
|
-
|
|
998
|
-
| Property | Type | Default | Required |
|
|
999
|
-
| -------- | -------- | ------- | -------- |
|
|
1000
|
-
| uuid | `string` | _none_ | ✔️ |
|
|
1001
|
-
|
|
1002
|
-
---
|
|
1003
|
-
|
|
1004
|
-
### `GeolocateParameters`
|
|
1005
|
-
|
|
1006
|
-
| Property | Type | Default | Required |
|
|
1007
|
-
| -------- | -------- | ------- | -------- |
|
|
1008
|
-
| ip | `string` | _none_ | ✔️ |
|
|
1009
|
-
|
|
1010
|
-
---
|
|
1011
|
-
|
|
1012
|
-
### `GuessGenderParameters`
|
|
1013
|
-
|
|
1014
|
-
| Property | Type | Default | Required |
|
|
1015
|
-
| -------- | -------- | ------- | -------- |
|
|
1016
|
-
| name | `string` | _none_ | ✔️ |
|
|
1017
|
-
|
|
1018
|
-
---
|
|
1019
|
-
|
|
1020
|
-
### `GuessGenderResponse`
|
|
1021
|
-
|
|
1022
|
-
| Property | Type | Default | Required |
|
|
1023
|
-
| ---------- | ------------------ | ------- | -------- |
|
|
1024
|
-
| confidence | `number` \| `null` | _none_ | ✔️ |
|
|
1025
|
-
| gender | `string` \| `null` | _none_ | ✔️ |
|
|
1026
|
-
|
|
1027
|
-
---
|
|
1028
|
-
|
|
1029
|
-
### `IdentityData`
|
|
1030
|
-
|
|
1031
|
-
| Property | Type | Default | Required |
|
|
1032
|
-
| -------- | -------- | ------- | -------- |
|
|
1033
|
-
| email | `string` | _none_ | ✔️ |
|
|
1034
|
-
|
|
1035
|
-
---
|
|
1036
|
-
|
|
1037
|
-
### `LocationData`
|
|
1038
|
-
|
|
1039
|
-
| Property | Type | Default | Required |
|
|
1040
|
-
| ---------------- | -------- | ------- | -------- |
|
|
1041
|
-
| city_name | `string` | _none_ | ❌ |
|
|
1042
|
-
| continent_code | `string` | _none_ | ❌ |
|
|
1043
|
-
| country_code2 | `string` | _none_ | ❌ |
|
|
1044
|
-
| country_code3 | `string` | _none_ | ❌ |
|
|
1045
|
-
| country_name | `string` | _none_ | ❌ |
|
|
1046
|
-
| ip | `string` | _none_ | ❌ |
|
|
1047
|
-
| latitude | `number` | _none_ | ❌ |
|
|
1048
|
-
| longitude | `number` | _none_ | ❌ |
|
|
1049
|
-
| postal_code | `string` | _none_ | ❌ |
|
|
1050
|
-
| real_region_name | `string` | _none_ | ❌ |
|
|
1051
|
-
| region_name | `string` | _none_ | ❌ |
|
|
1052
|
-
| request | `string` | _none_ | ❌ |
|
|
1053
|
-
|
|
1054
|
-
---
|
|
1055
|
-
|
|
1056
|
-
### `PageData`
|
|
1057
|
-
|
|
1058
|
-
| Property | Type | Default | Required |
|
|
1059
|
-
| -------- | -------- | ------- | -------- |
|
|
1060
|
-
| host | `string` | _none_ | ✔️ |
|
|
1061
|
-
| path | `string` | _none_ | ✔️ |
|
|
1062
|
-
| protocol | `string` | _none_ | ✔️ |
|
|
1063
|
-
| referrer | `string` | _none_ | ✔️ |
|
|
1064
|
-
| url | `string` | _none_ | ✔️ |
|
|
1065
|
-
|
|
1066
|
-
---
|
|
1067
|
-
|
|
1068
|
-
### `PurchaseCart`
|
|
1069
|
-
|
|
1070
|
-
| Property | Type | Default | Required |
|
|
1071
|
-
| ---------------------- | --------------------------------- | ------- | -------- |
|
|
1072
|
-
| abandoned_checkout_url | `string` | _none_ | ❌ |
|
|
1073
|
-
| items | [`PurchaseItem[]`](#PurchaseItem) | _none_ | ❌ |
|
|
1074
|
-
|
|
1075
|
-
---
|
|
1076
|
-
|
|
1077
|
-
### `PurchaseDetails`
|
|
1078
|
-
|
|
1079
|
-
| Property | Type | Default | Required |
|
|
1080
|
-
| -------- | --------------------------------------- | ------- | -------- |
|
|
1081
|
-
| unique | `{ key: string \| number; }` | _none_ | ✔️ |
|
|
1082
|
-
| value | `{ currency: string; amount: number; }` | _none_ | ✔️ |
|
|
1083
|
-
| cart | [`PurchaseCart`](#PurchaseCart) | _none_ | ❌ |
|
|
1084
|
-
|
|
1085
|
-
---
|
|
1086
|
-
|
|
1087
|
-
### `PurchaseItem`
|
|
1088
|
-
|
|
1089
|
-
In addition to the properties below, you can pass any other properties that you want as part of the `PurchaseItem`.
|
|
1090
|
-
|
|
1091
|
-
| Property | Type | Default | Required |
|
|
1092
|
-
| ------------- | -------- | ------- | -------- |
|
|
1093
|
-
| product_sku | `string` | _none_ | ❌ |
|
|
1094
|
-
| product_name | `string` | _none_ | ❌ |
|
|
1095
|
-
| quantity | `number` | _none_ | ❌ |
|
|
1096
|
-
| product_price | `number` | _none_ | ❌ |
|
|
1097
|
-
| product_id | `string` | _none_ | ❌ |
|
|
1098
|
-
|
|
1099
|
-
---
|
|
1100
|
-
|
|
1101
|
-
### `RemoveFieldParameters<S>`
|
|
1102
|
-
|
|
1103
|
-
The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
1104
|
-
|
|
1105
|
-
| Property | Type | Default | Required |
|
|
1106
|
-
| --------- | --------- | ------- | -------- |
|
|
1107
|
-
| email | `string` | _none_ | ✔️ |
|
|
1108
|
-
| fieldName | `keyof S` | _none_ | ✔️ |
|
|
1109
|
-
|
|
1110
|
-
---
|
|
1111
|
-
|
|
1112
|
-
### `RemoveSubscriberParameters`
|
|
1113
|
-
|
|
1114
|
-
| Property | Type | Default | Required |
|
|
1115
|
-
| -------- | -------- | ------- | -------- |
|
|
1116
|
-
| date | `Date` | _none_ | ❌ |
|
|
1117
|
-
| email | `string` | _none_ | ✔️ |
|
|
1118
|
-
|
|
1119
|
-
---
|
|
1120
|
-
|
|
1121
|
-
### `RemoveTagParameters`
|
|
1122
|
-
|
|
1123
|
-
| Property | Type | Default | Required |
|
|
1124
|
-
| -------- | -------- | ------- | -------- |
|
|
1125
|
-
| email | `string` | _none_ | ✔️ |
|
|
1126
|
-
| tagName | `string` | _none_ | ✔️ |
|
|
1127
|
-
|
|
1128
|
-
---
|
|
1129
|
-
|
|
1130
|
-
### `SubscribeParameters`
|
|
1131
|
-
|
|
1132
|
-
| Property | Type | Default | Required |
|
|
1133
|
-
| -------- | -------- | ------- | -------- |
|
|
1134
|
-
| email | `string` | _none_ | ✔️ |
|
|
1135
|
-
|
|
1136
|
-
---
|
|
1137
|
-
|
|
1138
|
-
### `Subscriber<S>`
|
|
1139
|
-
|
|
1140
|
-
The `S` from above represents the type of your subscriber's custom fields in Bento. This only applies in `TypeScript`. Please read the [TypeScript](#TypeScript) section for more details.
|
|
571
|
+
## Types Reference
|
|
1141
572
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
| attributes | [`SubscriberAttributes<S>`](#subscriberattributess) | _none_ | ✔️ |
|
|
1145
|
-
| id | `string` | _none_ | ✔️ |
|
|
1146
|
-
| type | [`EntityType.VISITOR`](#EntityType) | _none_ | ✔️ |
|
|
573
|
+
This section provides a detailed reference for the types used in the Bento Node.js SDK.
|
|
574
|
+
AddFieldParameters `<S>`
|
|
1147
575
|
|
|
1148
|
-
|
|
576
|
+
Parameters for adding a field to a subscriber.
|
|
1149
577
|
|
|
1150
|
-
|
|
578
|
+
| Property | Type | Required | Description |
|
|
579
|
+
|----------|------------------------------|----------|----------------------------|
|
|
580
|
+
| email | string | ✔️ | Subscriber's email address |
|
|
581
|
+
| field | { key: keyof S; value: any } | ✔️ | Field to add |
|
|
1151
582
|
|
|
1152
|
-
|
|
1153
|
-
| --------------- | ------------- | ------- | -------- |
|
|
1154
|
-
| cached_tag_ids | `string[]` | _none_ | ✔️ |
|
|
1155
|
-
| email | `string` | _none_ | ✔️ |
|
|
1156
|
-
| fields | `S` \| `null` | _none_ | ✔️ |
|
|
1157
|
-
| unsubscribed_at | `string` | _none_ | ✔️ |
|
|
1158
|
-
| uuid | `string` | _none_ | ✔️ |
|
|
583
|
+
### AddSubscriberParameters `<S>`
|
|
1159
584
|
|
|
1160
|
-
|
|
585
|
+
Parameters for adding a new subscriber.
|
|
1161
586
|
|
|
1162
|
-
| Property
|
|
1163
|
-
|
|
1164
|
-
|
|
|
1165
|
-
|
|
|
1166
|
-
|
|
|
1167
|
-
| site_id | `string` | _none_ | ✔️ |
|
|
587
|
+
| Property | Type | Required | Description |
|
|
588
|
+
|----------|---------------|----------|--------------------------------------|
|
|
589
|
+
| date | Date | ❌ | Date of subscription |
|
|
590
|
+
| email | string | ✔️ | Subscriber's email address |
|
|
591
|
+
| fields | Partial `<S>` | ❌ | Additional fields for the subscriber |
|
|
1168
592
|
|
|
1169
|
-
|
|
593
|
+
### AddTagParameters
|
|
1170
594
|
|
|
1171
|
-
|
|
595
|
+
Parameters for adding a tag to a subscriber.
|
|
1172
596
|
|
|
1173
|
-
| Property
|
|
1174
|
-
|
|
1175
|
-
|
|
|
1176
|
-
|
|
|
1177
|
-
| type | [`EntityType.TAG`](#EntityType) | _none_ | ✔️ |
|
|
597
|
+
| Property | Type | Required | Description |
|
|
598
|
+
|----------|--------|----------|----------------------------|
|
|
599
|
+
| email | string | ✔️ | Subscriber's email address |
|
|
600
|
+
| tagName | string | ✔️ | Name of the tag to add |
|
|
1178
601
|
|
|
1179
|
-
|
|
602
|
+
### BatchImportEventsParameter `<S>`, `<E>`
|
|
1180
603
|
|
|
1181
|
-
|
|
604
|
+
Parameters for batch importing events.
|
|
1182
605
|
|
|
1183
|
-
| Property | Type
|
|
1184
|
-
|
|
1185
|
-
|
|
|
1186
|
-
| email | `string` | _none_ | ✔️ |
|
|
1187
|
-
| tagName | `string` | _none_ | ✔️ |
|
|
606
|
+
| Property | Type | Required | Description |
|
|
607
|
+
|----------|-------------------------|----------|---------------------------|
|
|
608
|
+
| events | BentoEvent `<S>`, `<E>` | ✔️ | Array of events to import |
|
|
1188
609
|
|
|
1189
|
-
|
|
610
|
+
### BatchImportSubscribersParameter `<S>`
|
|
1190
611
|
|
|
1191
|
-
|
|
612
|
+
Parameters for batch importing subscribers.
|
|
1192
613
|
|
|
1193
|
-
|
|
614
|
+
| Property | Type | Required | Description |
|
|
615
|
+
|-------------|---------------------------------------|----------|--------------------------------|
|
|
616
|
+
| subscribers | ({ email: string } & Partial `<S>`)[] | ✔️ | Array of subscribers to import |
|
|
1194
617
|
|
|
1195
|
-
|
|
618
|
+
### BentoEvent `<S>`, `<E>`
|
|
619
|
+
Represents different types of events in Bento. It's a union of the following event types:
|
|
1196
620
|
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
621
|
+
- BaseEvent `<E>`
|
|
622
|
+
- PurchaseEvent
|
|
623
|
+
- SubscribeEvent `<S>`
|
|
624
|
+
- TagEvent
|
|
625
|
+
- UnsubscribeEvent
|
|
626
|
+
- UpdateFieldsEvent `<S>`
|
|
1203
627
|
|
|
1204
|
-
|
|
628
|
+
### PurchaseDetails
|
|
1205
629
|
|
|
1206
|
-
|
|
630
|
+
Details of a purchase event.
|
|
1207
631
|
|
|
1208
|
-
| Property
|
|
1209
|
-
|
|
1210
|
-
|
|
|
1211
|
-
|
|
|
1212
|
-
|
|
|
632
|
+
| Property | Type | Required | Description |
|
|
633
|
+
|----------|--------------------------------------|----------|------------------------------------|
|
|
634
|
+
| unique | { key: string \| number } | ✔️ | Unique identifier for the purchase |
|
|
635
|
+
| value | { currency: string; amount: number } | ✔️ | Value of the purchase |
|
|
636
|
+
| cart | PurchaseCart | ❌ | Additional cart details |
|
|
1213
637
|
|
|
1214
|
-
|
|
638
|
+
### ChangeEmailParameters
|
|
1215
639
|
|
|
1216
|
-
|
|
640
|
+
Parameters for changing a subscriber's email.
|
|
1217
641
|
|
|
1218
|
-
| Property | Type
|
|
1219
|
-
|
|
1220
|
-
|
|
|
642
|
+
| Property | Type | Required | Description |
|
|
643
|
+
|----------|--------|----------|-----------------------|
|
|
644
|
+
| oldEmail | string | ✔️ | Current email address |
|
|
645
|
+
| newEmail | string | ✔️ | New email address |
|
|
1221
646
|
|
|
1222
|
-
|
|
647
|
+
### CreateFieldParameters
|
|
1223
648
|
|
|
1224
|
-
|
|
649
|
+
Parameters for creating a new field.
|
|
1225
650
|
|
|
1226
|
-
|
|
651
|
+
| Property | Type | Required | Description |
|
|
652
|
+
|----------|--------|----------|----------------------|
|
|
653
|
+
| key | string | ✔️ | Key of the new field |
|
|
1227
654
|
|
|
1228
|
-
|
|
1229
|
-
| -------- | ------------ | ------- | -------- |
|
|
1230
|
-
| date | `Date` | _none_ | ❌ |
|
|
1231
|
-
| email | `string` | _none_ | ✔️ |
|
|
1232
|
-
| fields | `Partial<S>` | _none_ | ✔️ |
|
|
655
|
+
### CreateTagParameters
|
|
1233
656
|
|
|
1234
|
-
|
|
657
|
+
Parameters for creating a new tag.
|
|
1235
658
|
|
|
1236
|
-
|
|
659
|
+
| Property | Type | Required | Description |
|
|
660
|
+
|----------|--------|----------|---------------------|
|
|
661
|
+
| name | string | ✔️ | Name of the new tag |
|
|
1237
662
|
|
|
1238
|
-
|
|
1239
|
-
| --------- | -------- | ------- | -------- |
|
|
1240
|
-
| email | `string` | _none_ | ✔️ |
|
|
1241
|
-
| ip | `string` | _none_ | ❌ |
|
|
1242
|
-
| name | `string` | _none_ | ❌ |
|
|
1243
|
-
| userAgent | `string` | _none_ | ❌ |
|
|
663
|
+
### Subscriber `<S>`
|
|
1244
664
|
|
|
1245
|
-
|
|
665
|
+
Represents a subscriber in Bento.
|
|
1246
666
|
|
|
1247
|
-
|
|
667
|
+
| Property | Type | Required | Description |
|
|
668
|
+
|------------|----------------------------|----------|------------------------------|
|
|
669
|
+
| attributes | SubscriberAttributes `<S>` | ✔️ | Attributes of the subscriber |
|
|
670
|
+
| id | string | ✔️ | Unique identifier |
|
|
671
|
+
| type | EntityType.VISITOR | ✔️ | Type of the entity |
|
|
1248
672
|
|
|
1249
|
-
###
|
|
673
|
+
### TrackParameters `<S>`, `<E>`
|
|
1250
674
|
|
|
1251
|
-
|
|
675
|
+
Parameters for tracking an event.
|
|
1252
676
|
|
|
1253
|
-
|
|
677
|
+
| Property | Type | Required | Description |
|
|
678
|
+
|----------|------------------------|----------|-------------------------------------|
|
|
679
|
+
| email | string | ✔️ | Subscriber's email address |
|
|
680
|
+
| type | string | ✔️ | Type of the event |
|
|
681
|
+
| details | { [key: string]: any } | ❌ | Additional details of the event |
|
|
682
|
+
| fields | Partial `<S>` | ❌ | Fields to update for the subscriber |
|
|
1254
683
|
|
|
1255
|
-
|
|
684
|
+
### ValidateEmailParameters
|
|
1256
685
|
|
|
1257
|
-
|
|
1258
|
-
type MySubscriberFields = {
|
|
1259
|
-
firstName: string;
|
|
1260
|
-
lastName: string;
|
|
1261
|
-
age: number;
|
|
1262
|
-
};
|
|
686
|
+
Parameters for validating an email address.
|
|
1263
687
|
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
688
|
+
| Property | Type | Required | Description |
|
|
689
|
+
|-----------|--------|----------|--------------------------------|
|
|
690
|
+
| email | string | ✔️ | Email address to validate |
|
|
691
|
+
| ip | string | ❌ | IP address of the user |
|
|
692
|
+
| name | string | ❌ | Name associated with the email |
|
|
693
|
+
| userAgent | string | ❌ | User agent string |
|
|
1268
694
|
|
|
1269
|
-
|
|
695
|
+
Note: The `S` and `E` generic types are used for TypeScript support. `S` represents the type of your subscriber's custom fields, and `E` represents the prefix used for custom events. For more details, refer to the TypeScript section of the documentation.
|
|
1270
696
|
|
|
1271
|
-
The `E` generic is a string that represents the custom prefix used for your custom commands. This is used to ensure that you are not accidentally changing things on your subscribers that you do not intend to change. It also prevents clashes with using internal Bento events.
|
|
1272
|
-
|
|
1273
|
-
To set this type, pass it as the second generic parameter when initializing your `Analytics` object.
|
|
1274
|
-
|
|
1275
|
-
```ts
|
|
1276
|
-
const bento = new Analytics<any, '$myPrefix.'>({
|
|
1277
|
-
// ... initialization options from above.
|
|
1278
|
-
});
|
|
1279
|
-
```
|
|
1280
697
|
|
|
1281
698
|
## Things to know
|
|
1282
699
|
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
700
|
+
- All events must be identified with an email address.
|
|
701
|
+
- Most events are indexed within seconds in your Bento account.
|
|
702
|
+
- The SDK supports TypeScript with generics for custom fields and events.
|
|
703
|
+
- Batch operations are available for importing subscribers and events efficiently.
|
|
704
|
+
- The SDK doesn't currently support anonymous events (coming soon).
|
|
1286
705
|
|
|
1287
706
|
## Contributing
|
|
1288
707
|
|
|
1289
|
-
|
|
708
|
+
We welcome contributions! Please see our [contributing guidelines](CODE_OF_CONDUCT.md) for details on how to submit pull requests, report issues, and suggest improvements.
|
|
1290
709
|
|
|
1291
710
|
## License
|
|
1292
711
|
|
|
1293
|
-
The
|
|
712
|
+
The Bento SDK for Node.js is available as open source under the terms of the [MIT License](LICENSE.md).
|