@hellotext/hellotext 1.3.4 → 1.4.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 +15 -1
- package/__tests__/hellotext_test.js +9 -0
- package/package.json +1 -1
- package/src/hellotext.js +11 -2
package/README.md
CHANGED
|
@@ -212,7 +212,7 @@ Hellotext.removeEventListener(eventName, callback)
|
|
|
212
212
|
|
|
213
213
|
## Understanding Sessions
|
|
214
214
|
|
|
215
|
-
The library looks for a session identifier present on the `hellotext_session` query parameter. If the session is not present as a cookie neither it will create a new random session identifier.
|
|
215
|
+
The library looks for a session identifier present on the `hellotext_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.
|
|
216
216
|
The session is automatically sent to Hellotext any time the `Hellotext.track` method is called.
|
|
217
217
|
|
|
218
218
|
Short links redirections attaches a session identifier to the destination url as `hellotext_session` query parameter. This will identify all the events back to the customer who opened the link.
|
|
@@ -246,3 +246,17 @@ Hellotext.on("session-set", (session) => {
|
|
|
246
246
|
```
|
|
247
247
|
|
|
248
248
|
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.
|
|
249
|
+
|
|
250
|
+
### Configuration
|
|
251
|
+
|
|
252
|
+
When initializing the library, you may pass an optional configuration object as the second argument.
|
|
253
|
+
|
|
254
|
+
```javascript
|
|
255
|
+
Hellotext.initialize("HELLOTEXT_BUSINESS_ID", configurationOptions);
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
#### Configuration Options
|
|
259
|
+
|
|
260
|
+
| Property | Description | Type | Default |
|
|
261
|
+
|---------------------|------------------------------------------------------------------------------------------------------------------|---------| --- |
|
|
262
|
+
| autogenerateSession | Whether the library should automatically generate a session when no session is found in the query or the cookies | Boolean | true
|
|
@@ -91,6 +91,15 @@ describe("when the class is initialized successfully", () => {
|
|
|
91
91
|
expect(Hellotext.session).toEqual("generated_token")
|
|
92
92
|
}, 1000)
|
|
93
93
|
});
|
|
94
|
+
|
|
95
|
+
it("does not mint a new session token when autogenerateSession is set to false", () => {
|
|
96
|
+
Hellotext.initialize(business_id, { autogenerateSession: false })
|
|
97
|
+
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
expect(getCookieValue("hello_session")).toEqual(undefined)
|
|
100
|
+
expect(Hellotext.session).toEqual(undefined)
|
|
101
|
+
}, 1000)
|
|
102
|
+
})
|
|
94
103
|
});
|
|
95
104
|
});
|
|
96
105
|
|
package/package.json
CHANGED
package/src/hellotext.js
CHANGED
|
@@ -6,20 +6,29 @@ import Query from "./query";
|
|
|
6
6
|
import { NotInitializedError } from './errors/notInitializedError'
|
|
7
7
|
import { InvalidEvent } from "./errors/invalidEvent"
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {Object} Config
|
|
11
|
+
* @property {Boolean} autogenerateSession
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
|
|
9
15
|
class Hellotext {
|
|
10
16
|
static __apiURL = 'https://api.hellotext.com/v1/'
|
|
11
17
|
|
|
12
18
|
static #session
|
|
13
19
|
static #business
|
|
20
|
+
static #config
|
|
14
21
|
static #eventEmitter = new EventEmitter()
|
|
15
22
|
static #query
|
|
16
23
|
|
|
17
24
|
/**
|
|
18
25
|
* initialize the module.
|
|
19
26
|
* @param business public business id
|
|
27
|
+
* @param { Config } config
|
|
20
28
|
*/
|
|
21
|
-
static initialize(business) {
|
|
29
|
+
static initialize(business, config = { autogenerateSession: true }) {
|
|
22
30
|
this.#business = business
|
|
31
|
+
this.#config = config
|
|
23
32
|
|
|
24
33
|
this.#query = new Query(window.location.search)
|
|
25
34
|
|
|
@@ -30,7 +39,7 @@ class Hellotext {
|
|
|
30
39
|
if (session && session !== "undefined" && session !== "null") {
|
|
31
40
|
this.#session = session
|
|
32
41
|
this.#setSessionCookie()
|
|
33
|
-
} else {
|
|
42
|
+
} else if(config.autogenerateSession) {
|
|
34
43
|
this.#mintAnonymousSession()
|
|
35
44
|
.then(response => {
|
|
36
45
|
this.#session = response.id
|