@hellotext/hellotext 2.2.0 → 2.3.0
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 +1 -44
- package/dist/hellotext.js +1 -1
- package/index.d.ts +28 -0
- package/lib/api/identifications.cjs +42 -0
- package/lib/api/identifications.js +45 -0
- package/lib/api/index.cjs +6 -0
- package/lib/api/index.js +6 -0
- package/lib/hellotext.cjs +38 -14
- package/lib/hellotext.js +44 -15
- package/lib/models/cookies.cjs +23 -1
- package/lib/models/cookies.js +23 -1
- package/lib/models/index.cjs +7 -0
- package/lib/models/index.js +1 -0
- package/lib/models/page.cjs +79 -1
- package/lib/models/page.js +80 -1
- package/lib/models/user.cjs +53 -0
- package/lib/models/user.js +47 -0
- package/package.json +1 -1
- package/src/api/identifications.js +25 -0
- package/src/api/index.js +5 -0
- package/src/hellotext.js +37 -5
- package/src/models/cookies.js +23 -1
- package/src/models/index.js +1 -0
- package/src/models/page.js +83 -1
- package/src/models/user.js +35 -0
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@ Failing to initialize the class before calling any other method will throw a `No
|
|
|
51
51
|
|
|
52
52
|
Learn how to leverage the library to track events and collect forms.
|
|
53
53
|
|
|
54
|
+
- [Understanding Sessions](/docs/sessions.md)
|
|
54
55
|
- [Tracking Events](/docs/tracking.md)
|
|
55
56
|
- [Forms](/docs/forms.md)
|
|
56
57
|
- [Webchat](/docs/webchat.md)
|
|
@@ -105,50 +106,6 @@ Hellotext.removeEventListener(eventName, callback)
|
|
|
105
106
|
- `form:completed` This event is fired when a form has been completed. A form is completed when the user fills all required inputs and verifies their OTP(One-Time Password). The callback will receive the form object that was completed, alongside the data the user filled in the form.
|
|
106
107
|
- View Webchat events [here](/docs/webchat.md#events)
|
|
107
108
|
|
|
108
|
-
## Understanding Sessions
|
|
109
|
-
|
|
110
|
-
The library looks for a session identifier present on the `hello_session` query parameter. If the session is not present as a cookie neither it will create a new random session identifier, you can disable this default behaviour via the configuration, see [Configuration Options](#configuration-options) for more information.
|
|
111
|
-
The session is automatically sent to Hellotext any time the `Hellotext.track` method is called.
|
|
112
|
-
|
|
113
|
-
Short links redirections attaches a session identifier to the destination url as `hello_session` query parameter. This will identify all the events back to the customer who opened the link.
|
|
114
|
-
|
|
115
|
-
### Get session
|
|
116
|
-
|
|
117
|
-
It is possible to obtain the current session by simply calling `Hellotext.session`. When the session is present in the cookies,
|
|
118
|
-
the value stored in the cookies is returned. Otherwise, a new session is generated via [crypto.randomUUID()](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID).
|
|
119
|
-
The session is kept in the client and not sent to Hellotext's servers until an event is tracked.
|
|
120
|
-
|
|
121
|
-
An event is tracked in the following cases
|
|
122
|
-
|
|
123
|
-
- Explicitly calling `Hellotext.track` method.
|
|
124
|
-
- When a form is submitted and the form data is sent to Hellotext.
|
|
125
|
-
|
|
126
|
-
```javascript
|
|
127
|
-
Hellotext.session
|
|
128
|
-
// Returns da834c54-97fa-44ef-bafd-2bd4fec60636
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
If the session has not been set yet, the result returned will be `undefined`.
|
|
132
|
-
You can check whether the session has been set or not by calling `Hellotext.isInitialized`.
|
|
133
|
-
|
|
134
|
-
```javascript
|
|
135
|
-
if (Hellotext.isInitialized) {
|
|
136
|
-
console.log('session is present')
|
|
137
|
-
} else {
|
|
138
|
-
console.log('session has not been set')
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
Moreover, you can hook in and listen for the session being set, such that when it's set, you're notified about the change, like so
|
|
143
|
-
|
|
144
|
-
```javascript
|
|
145
|
-
Hellotext.on('session-set', session => {
|
|
146
|
-
console.log('session is: ', session)
|
|
147
|
-
})
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
You may want to store the session on your backend when customers are unidentified so you can later [attach it to a profile](https://www.hellotext.com/api#attach_session) when it becomes known.
|
|
151
|
-
|
|
152
109
|
### Configuration
|
|
153
110
|
|
|
154
111
|
When initializing the library, you may pass an optional configuration object as the second argument.
|