@bentonow/bento-node-sdk 0.1.14 → 0.2.1

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/README.md CHANGED
@@ -11,6 +11,7 @@ Track events, update data, record LTV and more in Node.JS. Data is stored in you
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
+ ❤️ Thank you @jonsherrard from [Devular](https://www.devular.com/) for your contribution.
14
15
 
15
16
  - [Installation](#Installation)
16
17
  - [Get Started](#Get-Started)
@@ -20,10 +21,12 @@ Track events, update data, record LTV and more in Node.JS. Data is stored in you
20
21
  - [addSubscriber(parameters: AddSubscriberParameters): Promise\<boolean\>](#addsubscriberparameters-addsubscriberparameters-promiseboolean)
21
22
  - [removeSubscriber(parameters: RemoveSubscriberParameters): Promise\<boolean\>](#removesubscriberparameters-removesubscriberparameters-promiseboolean)
22
23
  - [updateFields(parameters: UpdateFieldsParameters\<S\>): Promise\<boolean\>](#updatefieldsparameters-updatefieldsparameterss-promiseboolean)
24
+ - [track(parameters: TrackParameters<S, E>): Promise<boolean>](#trackparameters-trackparameterss-e-promiseboolean)
23
25
  - [trackPurchase(parameters: TrackPurchaseParameters): Promise\<boolean\>](#trackpurchaseparameters-trackpurchaseparameters-promiseboolean)
24
26
  - [Batch](#Batch)
25
27
  - [.importSubscribers(parameters: BatchImportSubscribersParameter\<S\>): Promise\<number\>](#batchimportsubscribersparameters-batchimportsubscribersparameters-promisenumber)
26
28
  - [.importEvents(parameters: BatchImportEventsParameter\<S, E\>): Promise\<number\>](#batchimporteventsparameters-batchimporteventsparameters-e-promisenumber)
29
+ - [.sendTransactionalEmails(parameters: BatchsendTransactionalEmailsParameter<S, E>): Promise<number>](#batchsendtransactionalemailsparameters-batchsendtransactionalemailsparameters-e-promisenumber)
27
30
  - [Commands](#Commands)
28
31
  - [.addTag(parameters: AddTagParameters): Promise\<Subscriber\<S\> | null\>](#commandsaddtagparameters-addtagparameters-promisesubscribers--null)
29
32
  - [.removeTag(parameters: RemoveTagParameters): Promise\<Subscriber\<S\> | null\>](#commandsremovetagparameters-removetagparameters-promisesubscribers--null)
@@ -64,9 +67,11 @@ Run the following command in your project folder.
64
67
  npm install @bentonow/bento-node-sdk --save
65
68
  ```
66
69
 
67
- ## Get Started
70
+ ## Getting Started
68
71
 
69
- To get started with tracking things in Bento, simply initialize the client and run wild!
72
+ To get started with tracking your users in Bento, simply initialize the client and go wild.
73
+
74
+ The below example showcases using `track` and `trackPurchase` which are the two recommended functions you should lean on as they can trigger automations. If you need to upload a lot of data but do not wish to trigger automations, like when you sign up, then use [importSubscribers](#batchimportsubscribersparameters-batchimportsubscribersparameters-promisenumber) instead.
70
75
 
71
76
  ```ts
72
77
  import { Analytics } from '@bentonow/bento-node-sdk';
@@ -74,38 +79,35 @@ import { Analytics } from '@bentonow/bento-node-sdk';
74
79
  const bento = new Analytics({
75
80
  authentication: {
76
81
  publishableKey: 'publishableKey',
77
- secretKey: 'secretKey',
82
+ secretKey: 'secretKey',
78
83
  },
79
84
  logErrors: false, // Set to true to see the HTTP errors logged
80
85
  siteUuid: 'siteUuid',
81
86
  });
82
87
 
83
- bento.V1.addSubscriber({
84
- email: 'test@bentonow.com',
85
- })
86
- .then(result => console.log(result))
87
- .catch(error => console.error(error));
88
-
89
- bento.V1.updateFields({
88
+ bento.V1.track({
90
89
  email: 'test@bentonow.com',
90
+ type: '$formSubmitted',
91
91
  fields: {
92
- firstName: 'Test',
93
- lastName: 'User',
92
+ first_name: 'Test',
93
+ last_name: 'Test',
94
94
  },
95
- })
96
- .then(result => console.log(result))
97
- .catch(error => console.error(error));
95
+ details: {
96
+ fromCustomEvent: true,
97
+ },
98
+ }).then(result => console.log(result)).catch(error => console.error(error));
98
99
 
99
100
  bento.V1.trackPurchase({
100
101
  email: 'test@bentonow.com',
101
102
  purchaseDetails: {
102
- unique: { key: 1234 },
103
+ unique: { key: 1234 }, // this key stops duplicate order values being tracked
103
104
  value: { amount: 100, currency: 'USD' },
104
105
  },
105
106
  cart: {
106
- abandoned_checkout_url: '',
107
+ abandoned_checkout_url: 'https://example.com',
107
108
  },
108
109
  });
110
+
109
111
  ```
110
112
 
111
113
  Read on to see what all you can do with the SDK.
@@ -271,8 +273,8 @@ bento.V1.track({
271
273
  email: 'test@bentonow.com',
272
274
  type: '$custom.event',
273
275
  fields: {
274
- firstName: 'Custom Name',
275
- lastName: 'Custom Name',
276
+ firstName: 'Custom Name',
277
+ lastName: 'Custom Name',
276
278
  },
277
279
  details: {
278
280
  fromCustomEvent: true,
@@ -286,7 +288,7 @@ bento.V1.track({
286
288
 
287
289
  ### `Batch.importSubscribers(parameters: BatchImportSubscribersParameter<S>): Promise<number>`
288
290
 
289
- **This does not trigger automations!** - If you wish to trigger automations, please batch import events with the type set to `BentoEvents.SUBSCRIBE`, or `$subscribe`. Note that the batch event import cannot attach custom fields and will ignore everything except the email.
291
+ **This does not trigger automations!** - If you wish to trigger automations, please batch import events.
290
292
 
291
293
  Creates a batch job to import subscribers into the system. You can pass in between 1 and 1,000 subscribers to import. Each subscriber must have an email, and may optionally have any additional fields. The additional fields are added as custom fields on the subscriber.
292
294
 
@@ -305,6 +307,8 @@ bento.V1.Batch.importSubscribers({
305
307
  },
306
308
  {
307
309
  email: 'test2@bentonow.com',
310
+ some_custom_variable: 'tester-123',
311
+ primary_user: true,
308
312
  },
309
313
  {
310
314
  email: 'test3@bentonow.com',
@@ -320,7 +324,7 @@ bento.V1.Batch.importSubscribers({
320
324
 
321
325
  ### `Batch.importEvents(parameters: BatchImportEventsParameter<S, E>): Promise<number>`
322
326
 
323
- Creates a batch job to import events into the system. You can pass in between 1 and 1,000 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,
327
+ 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,
324
328
 
325
329
  Returns the number of events that were imported.
326
330
 
@@ -364,6 +368,37 @@ bento.V1.Batch.importEvents({
364
368
  .catch(error => console.error(error));
365
369
  ```
366
370
 
371
+ ---
372
+
373
+ ### `Batch.sendTransactionalEmails(parameters: BatchsendTransactionalEmailsParameter<S, E>): Promise<number>`
374
+
375
+ Creates a batch job to send transactional emails from Bento's infrastructure. You can pass in between 1 and 100 emails to send. Each email must have a `to` address, a `from` address, a `subject`, an `html_body` and `transactional: true`.
376
+
377
+ In addition you can add a `personalizations` object to provide liquid tags that will be injected into the email.
378
+
379
+ Requests are instant and queued into a priority queue. Most requests will be processed within 30 seconds. We currently limit this endpoint to 60 emails per minute.
380
+
381
+ Returns the number of emails that were imported.
382
+
383
+ ```ts
384
+ bento.V1.Batch.sendTransactionalEmails({
385
+ emails: [
386
+ {
387
+ to: 'test@bentonow.com', // required — if no user with this email exists in your account they will be created.
388
+ from: 'jesse@bentonow.com', // required — must be an email author in your account.
389
+ subject: 'Reset Password', // required
390
+ html_body: '<p>Here is a link to reset your password ... {{ link }}</p>', // required - can also use text_body if you want to use our plain text theme.
391
+ transactional: true, // IMPORTANT — this bypasses the subscription status of a user. Abuse will lead to account shutdown.
392
+ personalizations: {
393
+ link: 'https://example.com/test',
394
+ }, // optional — provide your own Liquid tags to be injected into the email.
395
+ },
396
+ ],
397
+ })
398
+ .then(result => console.log(result))
399
+ .catch(error => console.error(error));
400
+ ```
401
+
367
402
  ## Commands
368
403
 
369
404
  ### `Commands.addTag(parameters: AddTagParameters): Promise<Subscriber<S> | null>`