@hellotext/hellotext 1.8.6 → 1.8.7

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/docs/tracking.md CHANGED
@@ -65,7 +65,7 @@ Hellotext.track('page.viewed', {
65
65
  Failing to provide valid set of parameters will result in an error object being returned, describing the parameters that did not satisfy the rules.
66
66
 
67
67
  ```javascript
68
- const response = await Hellotext.track('app.installed', { app_parameters: { name: 'My App' } })
68
+ const response = await Hellotext.track('app.installed', { object_parameters: { name: null } })
69
69
 
70
70
  console.log(response.data)
71
71
  ```
@@ -76,10 +76,9 @@ yields
76
76
  {
77
77
  errors: [
78
78
  {
79
- type: 'parameter_not_unique',
79
+ type: 'parameter_invalid_empty',
80
80
  parameter: 'name',
81
- description:
82
- 'The value must be unique and it is already present in another object of the same type.',
81
+ description: 'This required parameter has an empty value. Provide a valid value for the parameter.',
83
82
  },
84
83
  ]
85
84
  }
@@ -87,10 +86,28 @@ yields
87
86
 
88
87
  For a complete list of errors types. See [Error Types](https://www.hellotext.com/api#errors)
89
88
 
90
- ### Associated objects
89
+ ### Event parameters
91
90
 
92
- Generally, most actions also require an associated object. These can be of type [`app`](https://www.hellotext.com/api#apps), [`coupon`](https://www.hellotext.com/api#coupons), [`form`](https://www.hellotext.com/api#forms), [`order`](https://www.hellotext.com/api#orders), [`product`](https://www.hellotext.com/api#products) and [`refund`](https://www.hellotext.com/api#refunds).
93
- Aside from [Custom Actions](https://www.hellotext.com/api#create_an_action), which don't require the trackable to be present.
91
+ Every tracked event has the following parameters which you can pass to the `track` method:
92
+
93
+
94
+ | Property | Description | Type | Default |
95
+ | -------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -------- | ------- |
96
+ | **amount** | Monetary amount that represents the revenue associated to this tracked event. | float | `0` |
97
+ | **currency** | Currency for the `amount` given in ISO 4217 format. If not specified, the currency default to the business' configured reporting currency. | currency | `USD` |
98
+ | **metadata** | Set of key-value pairs that you can attach to an event. This can be useful for storing additional information about the object in a structured format. | hash | `{}` |
99
+ | **tracked_at** | Original date when the event happened. This is useful if you want to record an event that happened in the past. If no value is provided its value will be the same from `created_at`. | epoch | `null` |
100
+
101
+ ### Associated object parameters
102
+
103
+ Generally, most actions also require an associated object. These can be of type [`app`](https://www.hellotext.com/api#apps), [`coupon`](https://www.hellotext.com/api#coupons), [`form`](https://www.hellotext.com/api#forms), [`order`](https://www.hellotext.com/api#orders), [`product`](https://www.hellotext.com/api#products) and [`refund`](https://www.hellotext.com/api#refunds), these events require an existing object to be present
104
+ in order to be tracked aside from [Custom Actions](https://www.hellotext.com/api#create_an_action), which don't require the trackable to be present.
105
+
106
+ Associated objects are represented by three possible parameters:
107
+
108
+ - `object`: An ID of an existing object of the same type. For example, when tracking app events, the `object` must be a previously created app object.
109
+ - `object_parameters`: A set of parameters for creating a new object of the same type. For example, when tracking app events, the `object_parameters` must be a set of parameters for creating a new app object.
110
+ - `object_type`: An ID or `name` of an existing custom object. Only required when tracking custom objects. Lets Hellotext know which type of object is being tracked. Learn more about [Objects](https://www.hellotext.com/api#objects).
94
111
 
95
112
  You can create the associated object directly by defining its parameters in a hash:
96
113
 
@@ -98,9 +115,15 @@ You can create the associated object directly by defining its parameters in a ha
98
115
  Hellotext.track('order.placed', {
99
116
  amount: 395.0,
100
117
  currency: 'USD',
101
- order_parameters: {
102
- amount: '395.00',
118
+ object_parameters: {
103
119
  reference: '654321',
120
+ source: 'myshop',
121
+ items: [
122
+ {
123
+ product: 'erA2RAXE',
124
+ quantity: 2,
125
+ }
126
+ ]
104
127
  },
105
128
  })
106
129
  ```
@@ -112,57 +135,69 @@ For more information about identifiers, view the [Tracking API](https://www.hell
112
135
  Hellotext.track('product.purchased', {
113
136
  amount: 395.0,
114
137
  currency: 'USD',
115
- product: 'erA2RAXE',
138
+ object: 'erA2RAXE',
116
139
  })
117
140
  ```
118
141
 
119
142
  ## List of actions
120
143
 
121
- The following is a complete list of built-in actions and their required associated objects.
144
+ The following is a complete list of built-in actions and their required associated objects. Each associated action accepts a possible set of two parameters
145
+
146
+
122
147
 
123
148
  | Action | Description | Required Parameter |
124
- | --------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------- |
125
- | **app.installed** | An app was installed. | `app` or [app_parameters](https://www.hellotext.com/api#app) |
126
- | **app.removed** | An app was removed. | `app` or [app_parameters](https://www.hellotext.com/api#app) |
127
- | **app.spent** | A customer spent on an app. | `app` or [app_parameters](https://www.hellotext.com/api#app) |
128
- | **cart.abandoned** | A cart was abandoned. | `product` or [product_parameters](https://www.hellotext.com/api#products) |
129
- | **cart.added** | Added an item to the cart. | `product` or [product_parameters](https://www.hellotext.com/api#products) |
130
- | **cart.removed** | Removed an item from the cart. | `product` or [product_parameters](https://www.hellotext.com/api#products) |
131
- | **coupon.redeemed** | A coupon was redeem by a customer. | `coupon` or [coupon_parameters](https://www.hellotext.com/api#coupons) |
132
- | **form.completed** | A form was completed by the customer. | `form` or [form_parameters](https://www.hellotext.com/api#forms) |
133
- | **order.placed** | Order has been placed. | `order` or [order_parameters](https://www.hellotext.com/api#orders) |
134
- | **order.confirmed** | Order has been confirmed by you. | `order` or [order_parameters](https://www.hellotext.com/api#orders) |
135
- | **order.cancelled** | Order has been cancelled either by you or your customer. | `order` or [order_parameters](https://www.hellotext.com/api#orders) |
136
- | **order.shipped** | Order has been shipped to your customer. | `order` or [order_parameters](https://www.hellotext.com/api#orders) |
137
- | **order.delivered** | Order has been delivered to your customer. | `order` or [order_parameters](https://www.hellotext.com/api#orders) |
149
+ | --------------------- | -------------------------------------------------------- |---------------------------------------------------------------------------|
150
+ | **app.installed** | An app was installed. | `object` or [object_parameters](https://www.hellotext.com/api#app) |
151
+ | **app.removed** | An app was removed. | `object` or [object_parameters](https://www.hellotext.com/api#app) |
152
+ | **app.spent** | A customer spent on an app. | `object` or [object_parameters](https://www.hellotext.com/api#app) |
153
+ | **cart.abandoned** | A cart was abandoned. | `object` or [object_parameters](https://www.hellotext.com/api#products) |
154
+ | **cart.added** | Added an item to the cart. | `object` or [object_parameters](https://www.hellotext.com/api#products) |
155
+ | **cart.removed** | Removed an item from the cart. | `object` or [object_parameters](https://www.hellotext.com/api#products) |
156
+ | **coupon.redeemed** | A coupon was redeem by a customer. | `object` or [object_parameters](https://www.hellotext.com/api#coupons) |
157
+ | **form.completed** | A form was completed by the customer. | `object` or [object_parameters](https://www.hellotext.com/api#forms) |
158
+ | **order.placed** | Order has been placed. | `object` or [object_parameters](https://www.hellotext.com/api#orders) |
159
+ | **order.confirmed** | Order has been confirmed by you. | `object` or [object_parameters](https://www.hellotext.com/api#orders) |
160
+ | **order.cancelled** | Order has been cancelled either by you or your customer. | `object` or [object_parameters](https://www.hellotext.com/api#orders) |
161
+ | **order.shipped** | Order has been shipped to your customer. | `object` or [object_parameters](https://www.hellotext.com/api#orders) |
162
+ | **order.delivered** | Order has been delivered to your customer. | `object` or [object_parameters](https://www.hellotext.com/api#orders) |
138
163
  | **page.viewed** | A page was viewed by a customer. | `url` |
139
- | **product.purchased** | A product has been purchased. | `product` or [product_parameters](https://www.hellotext.com/api#products) |
140
- | **product.viewed** | A product page has been viewed. | `product` or [product_parameters](https://www.hellotext.com/api#products) |
141
- | **refund.requested** | A customer requested a refund. | `refund` or [refund_parameters](https://www.hellotext.com/api#refunds) |
142
- | **refund.received** | A refund was issued by you to your customer. | `refund` or [refund_parameters](https://www.hellotext.com/api#refunds) |
164
+ | **product.purchased** | A product has been purchased. | `object` or [object_parameters](https://www.hellotext.com/api#products) |
165
+ | **product.viewed** | A product page has been viewed. | `object` or [object_parameters](https://www.hellotext.com/api#products) |
166
+ | **refund.requested** | A customer requested a refund. | `object` or [object_parameters](https://www.hellotext.com/api#refunds) |
167
+ | **refund.received** | A refund was issued by you to your customer. | `object` or [object_parameters](https://www.hellotext.com/api#refunds) |
143
168
 
144
169
  You can also create your **[own defined actions](https://www.hellotext.com/api#actions)**.
145
170
 
146
- ## Additional Properties
171
+ ### Tracking Custom Actions
147
172
 
148
- You can include additional attributes to the tracked event, additional properties must be included inside the `metadata` object:
173
+ Once you have created a custom action, you track it by specifying the action's name. Custom actions do not require an associated object to be present in order to be tracked.
174
+ However, it's possible to track custom actions alongside existing Objects, or new objects you introduce.
149
175
 
150
176
  ```javascript
151
- Hellotext.track('product.purchased', {
152
- amount: 0.2,
153
- currency: 'USD',
154
- metadata: {
155
- myProperty: 'custom',
156
- },
157
- tracked_at: 1665684173,
177
+ // Custom Action without an associated object
178
+
179
+ Hellotext.track('appointment.booked')
180
+
181
+ // Custom Action with an existing custom object instance.
182
+
183
+ Hellotext.track('appointment.booked', {
184
+ object_type: 'appointment',
185
+ object: 'erA2RAXE',
158
186
  })
159
- ```
160
187
 
161
- ### List of additional attributes
188
+ // Custom Action with a new custom object instance.
189
+ Hellotext.track('appointment.booked', {
190
+ object_type: 'appointment',
191
+ object_parameters: {
192
+ room: 'AA-101',
193
+ booked_at: 1632313200,
194
+ }
195
+ })
162
196
 
163
- | Property | Description | Type | Default |
164
- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------- |
165
- | **amount** | Monetary amount that represents the revenue associated to this tracked event. | float | `0` |
166
- | **currency** | Currency for the `amount` given in ISO 4217 format. | currency | `USD` |
167
- | **metadata** | Set of key-value pairs that you can attach to an event. This can be useful for storing additional information about the object in a structured format. | hash | `{}` |
168
- | **tracked_at** | Original date when the event happened. This is useful if you want to record an event that happened in the past. If no value is provided its value will be the same from `created_at`. | epoch | `null` |
197
+ // Custom Action with a builtin object instance.
198
+
199
+ Hellotext.track('appointment.booked', {
200
+ object_type: 'product',
201
+ object: 'erA2RAXE',
202
+ })
203
+ ```
package/lib/hellotext.js CHANGED
@@ -39,10 +39,10 @@ var Hellotext = /*#__PURE__*/function () {
39
39
  */
40
40
  function () {
41
41
  var _initialize = _asyncToGenerator(function* (business, config) {
42
+ this.business = new _models.Business(business);
42
43
  _core.Configuration.assign(config);
43
44
  _models.Session.initialize();
44
45
  _classPrivateFieldLooseBase(this, _query)[_query] = new _models.Query();
45
- this.business = new _models.Business(business);
46
46
  this.forms = new _models.FormCollection();
47
47
  if (_core.Configuration.webchat.id) {
48
48
  this.webchat = yield _models.Webchat.load(_core.Configuration.webchat.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellotext/hellotext",
3
- "version": "1.8.6",
3
+ "version": "1.8.7",
4
4
  "description": "Hellotext JavaScript Client",
5
5
  "source": "src/index.js",
6
6
  "main": "lib/index.js",
package/src/hellotext.js CHANGED
@@ -21,12 +21,12 @@ class Hellotext {
21
21
  * @param { Configuration } config
22
22
  */
23
23
  static async initialize(business, config) {
24
+ this.business = new Business(business)
25
+
24
26
  Configuration.assign(config)
25
27
  Session.initialize()
26
28
 
27
29
  this.#query = new Query()
28
-
29
- this.business = new Business(business)
30
30
  this.forms = new FormCollection()
31
31
 
32
32
  if (Configuration.webchat.id) {