@hellotext/hellotext 1.0.4 → 1.0.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/README.md +2 -2
- package/lib/hellotext.js +32 -29
- package/package.json +1 -5
package/README.md
CHANGED
|
@@ -125,9 +125,9 @@ Hellotext.track("product.purchased", {
|
|
|
125
125
|
|
|
126
126
|
## Understanding Sessions
|
|
127
127
|
|
|
128
|
-
The library looks for a session identifier present on the `
|
|
128
|
+
The library looks for a session identifier present on the `hellotext_session` parameter. If the session is not present as a cookie neither it will create a new random session identifier. The session is automatically sent to Hellotext any time the `Hellotext.track` method is called.
|
|
129
129
|
|
|
130
|
-
Short links redirections attaches a session identifier to the destination url as `
|
|
130
|
+
Short links redirections attaches a session identifier to the destination url as `hellotext_session` parameter. This will identify all the events back to the customer who opened the link.
|
|
131
131
|
|
|
132
132
|
### Get session
|
|
133
133
|
|
package/lib/hellotext.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
|
|
3
1
|
const apiUrl = 'https://api.hellotext.com/v1/'
|
|
4
2
|
|
|
5
3
|
class Hellotext {
|
|
@@ -17,8 +15,8 @@ class Hellotext {
|
|
|
17
15
|
this.setSessionCookie(session)
|
|
18
16
|
} else {
|
|
19
17
|
this.mintAnonymousSession().then(response => {
|
|
20
|
-
this._session = response.
|
|
21
|
-
this.setSessionCookie(response.
|
|
18
|
+
this._session = response.id
|
|
19
|
+
this.setSessionCookie(response.id)
|
|
22
20
|
})
|
|
23
21
|
}
|
|
24
22
|
}
|
|
@@ -30,48 +28,53 @@ class Hellotext {
|
|
|
30
28
|
* @param { String } url optional url, the url is automatically inferred when the action is tracked
|
|
31
29
|
* @returns {Promise}
|
|
32
30
|
*/
|
|
33
|
-
static track(action, params, url = null) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
static async track(action, params, url = null) {
|
|
32
|
+
const response = await fetch(apiUrl + "track/events", {
|
|
33
|
+
headers: this.headers,
|
|
34
|
+
method: "post",
|
|
35
|
+
body: JSON.stringify({
|
|
37
36
|
session: this.session,
|
|
38
37
|
url: url || window.location.href,
|
|
39
38
|
action,
|
|
40
39
|
...params,
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
)
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
return response.json()
|
|
48
44
|
}
|
|
49
45
|
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @returns {Promise<any>|String}
|
|
49
|
+
*/
|
|
50
50
|
static get session() {
|
|
51
51
|
if (this._session) return this._session
|
|
52
52
|
|
|
53
53
|
return this.mintAnonymousSession().then(response => {
|
|
54
|
-
this._session = response.
|
|
55
|
-
return response.
|
|
56
|
-
})
|
|
54
|
+
this._session = response.id
|
|
55
|
+
return response.id
|
|
56
|
+
}).then(() => this._session)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// private
|
|
60
60
|
|
|
61
|
-
static mintAnonymousSession() {
|
|
61
|
+
static async mintAnonymousSession() {
|
|
62
62
|
const trackingUrl = apiUrl + 'track/sessions'
|
|
63
63
|
|
|
64
|
-
this.mintingPromise =
|
|
65
|
-
|
|
66
|
-
{},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
},
|
|
72
|
-
)
|
|
64
|
+
this.mintingPromise = await fetch(trackingUrl, {
|
|
65
|
+
method: "post",
|
|
66
|
+
headers: { Authorization: `Bearer ${this.business_id}` },
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
return this.mintingPromise.json()
|
|
70
|
+
}
|
|
73
71
|
|
|
74
|
-
|
|
72
|
+
static get headers() {
|
|
73
|
+
return {
|
|
74
|
+
Authorization: `Bearer ${this.business_id}`,
|
|
75
|
+
Accept: 'application.json',
|
|
76
|
+
'Content-Type': 'application/json'
|
|
77
|
+
}
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
static setSessionCookie(session) {
|
package/package.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hellotext/hellotext",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Hellotext javascript client",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Hellotext",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://github.com/hellotext/hellotext.js",
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"@rails/actioncable": "^7.0.4",
|
|
11
|
-
"axios": "^0.21.1"
|
|
12
|
-
},
|
|
13
9
|
"devDependencies": {
|
|
14
10
|
"prettier": "2.8.2"
|
|
15
11
|
},
|