@hellotext/hellotext 2.1.4 → 2.1.6
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 -0
- package/dist/hellotext.js +1 -1
- package/lib/controllers/webchat_controller.cjs +14 -10
- package/lib/controllers/webchat_controller.js +14 -10
- package/lib/core/event.cjs +1 -1
- package/lib/core/event.js +1 -1
- package/lib/hellotext.cjs +3 -1
- package/lib/hellotext.js +4 -4
- package/lib/models/cookies.cjs +6 -1
- package/lib/models/cookies.js +6 -1
- package/lib/models/index.cjs +14 -0
- package/lib/models/index.js +2 -0
- package/lib/models/page.cjs +86 -0
- package/lib/models/page.js +81 -0
- package/lib/models/utm.cjs +41 -0
- package/lib/models/utm.js +38 -0
- package/package.json +1 -1
- package/src/controllers/webchat_controller.js +14 -10
- package/src/core/event.js +1 -0
- package/src/hellotext.js +5 -2
- package/src/models/cookies.js +9 -3
- package/src/models/index.js +2 -0
- package/src/models/page.js +65 -0
- package/src/models/utm.js +33 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { UTM } from './utm'
|
|
2
|
+
|
|
3
|
+
class Page {
|
|
4
|
+
constructor(url = null) {
|
|
5
|
+
this.utm = new UTM()
|
|
6
|
+
this._url = url
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get the current page URL
|
|
11
|
+
* @returns {string} The page URL
|
|
12
|
+
*/
|
|
13
|
+
get url() {
|
|
14
|
+
return this._url || window.location.href
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the current page title
|
|
19
|
+
* @returns {string} The page title
|
|
20
|
+
*/
|
|
21
|
+
get title() {
|
|
22
|
+
return document.title
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get the current page path
|
|
27
|
+
* @returns {string} The page path
|
|
28
|
+
*/
|
|
29
|
+
get path() {
|
|
30
|
+
if (this._url) {
|
|
31
|
+
try {
|
|
32
|
+
return new URL(this._url).pathname
|
|
33
|
+
} catch (e) {
|
|
34
|
+
return '/'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return window.location.pathname
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get current UTM parameters
|
|
43
|
+
* @returns {Object} The UTM parameters
|
|
44
|
+
*/
|
|
45
|
+
get utmParams() {
|
|
46
|
+
return this.utm.current
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get page data for tracking
|
|
51
|
+
* @returns {Object} Object containing page object and utm_params
|
|
52
|
+
*/
|
|
53
|
+
get trackingData() {
|
|
54
|
+
return {
|
|
55
|
+
page: {
|
|
56
|
+
url: this.url,
|
|
57
|
+
title: this.title,
|
|
58
|
+
path: this.path,
|
|
59
|
+
},
|
|
60
|
+
utm_params: this.utmParams,
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { Page }
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Cookies } from './cookies'
|
|
2
|
+
|
|
3
|
+
class UTM {
|
|
4
|
+
constructor() {
|
|
5
|
+
const urlSearchParams = new URLSearchParams(window.location.search)
|
|
6
|
+
|
|
7
|
+
const utmsFromUrl = {
|
|
8
|
+
source: urlSearchParams.get('utm_source'),
|
|
9
|
+
medium: urlSearchParams.get('utm_medium'),
|
|
10
|
+
campaign: urlSearchParams.get('utm_campaign'),
|
|
11
|
+
term: urlSearchParams.get('utm_term'),
|
|
12
|
+
content: urlSearchParams.get('utm_content'),
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (utmsFromUrl.source && utmsFromUrl.medium) {
|
|
16
|
+
const cleanUtms = Object.fromEntries(
|
|
17
|
+
Object.entries(utmsFromUrl).filter(([_, value]) => value),
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
Cookies.set('hello_utm', JSON.stringify(cleanUtms))
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get current() {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(Cookies.get('hello_utm')) || {}
|
|
27
|
+
} catch (e) {
|
|
28
|
+
return {}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { UTM }
|