@hellotext/hellotext 1.8.1 → 1.8.3

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
@@ -85,11 +85,18 @@ Short links redirections attaches a session identifier to the destination url as
85
85
 
86
86
  ### Get session
87
87
 
88
- It is possible to obtain the current session by simply calling `Hellotext.session`.
88
+ It is possible to obtain the current session by simply calling `Hellotext.session`. When the session is present in the cookies,
89
+ 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).
90
+ The session is kept in the client and not sent to Hellotext's servers until an event is tracked.
91
+
92
+ An event is tracked in the following cases
93
+
94
+ - Explicitly calling `Hellotext.track` method.
95
+ - When a form is submitted and the form data is sent to Hellotext.
89
96
 
90
97
  ```javascript
91
- await Hellotext.session
92
- // Returns bBJn9vR15yPaYkWmR2QK0jopMeNxrA6l
98
+ Hellotext.session
99
+ // Returns da834c54-97fa-44ef-bafd-2bd4fec60636
93
100
  ```
94
101
 
95
102
  If the session has not been set yet, the result returned will be `undefined`.
@@ -20,10 +20,6 @@ afterEach(() => {
20
20
  });
21
21
 
22
22
  describe("when trying to call methods before initializing the class", () => {
23
- it("raises an error when Hellotext.session is called", () => {
24
- expect(() => Hellotext.session).toThrowError()
25
- });
26
-
27
23
  it("raises an error when Hellotext.track is called", () => {
28
24
  expect(Hellotext.track("page.viewed")).rejects.toThrowError()
29
25
  });
@@ -196,12 +192,6 @@ describe("when hello_preview query parameter is present", () => {
196
192
  Hellotext.initialize(123)
197
193
  })
198
194
 
199
- describe(".initialize", () => {
200
- it("does not attempt to set the session", () => {
201
- expect(getCookieValue("hello_session")).toEqual(undefined)
202
- });
203
- })
204
-
205
195
  describe(".track", () => {
206
196
  it("returns a success response without interacting with the API", async () => {
207
197
  const response = await Hellotext.track("page.viewed")
@@ -209,10 +199,3 @@ describe("when hello_preview query parameter is present", () => {
209
199
  });
210
200
  })
211
201
  })
212
-
213
- describe('setSession', () => {
214
- it('sets the session', () => {
215
- Hellotext.setSession("12345")
216
- expect(Hellotext.session).toEqual("12345")
217
- })
218
- })
@@ -76,7 +76,7 @@ describe('markAsCompleted', () => {
76
76
  const emit = jest.spyOn(Hellotext.eventEmitter, 'dispatch')
77
77
 
78
78
  form.markAsCompleted()
79
- expect(emit).toHaveBeenCalledWith('form:completed', { id: 1 })
79
+ expect(emit).toHaveBeenCalled()
80
80
  })
81
81
  })
82
82