coveo.analytics 2.32.0 → 2.33.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/dist/browser.mjs +1 -1
- package/dist/coveoua.browser.js +1 -1
- package/dist/coveoua.browser.js.map +1 -1
- package/dist/coveoua.debug.js +1 -1
- package/dist/coveoua.debug.js.map +1 -1
- package/dist/coveoua.js +1 -1
- package/dist/coveoua.js.map +1 -1
- package/dist/definitions/version.d.ts +1 -1
- package/dist/esm/cookieutils.d.mts +1 -0
- package/dist/esm/cookieutils.mjs +43 -0
- package/dist/esm/detector.d.mts +1 -0
- package/dist/esm/detector.mjs +39 -0
- package/dist/esm/history.d.mts +2 -0
- package/dist/esm/history.mjs +134 -0
- package/dist/esm/storage.d.mts +1 -0
- package/dist/esm/storage.mjs +55 -0
- package/dist/library.cjs +1 -1
- package/dist/library.es.js +1 -1
- package/dist/library.js +1 -1
- package/dist/library.mjs +1 -1
- package/dist/react-native.es.js +1 -1
- package/package.json +7 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const libVersion = "2.
|
|
1
|
+
export declare const libVersion = "2.33.0";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../definitions/cookieutils.js';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
class Cookie {
|
|
2
|
+
static set(name, value, expire) {
|
|
3
|
+
var domain, expirationDate, domainParts, host;
|
|
4
|
+
if (expire) {
|
|
5
|
+
expirationDate = new Date();
|
|
6
|
+
expirationDate.setTime(expirationDate.getTime() + expire);
|
|
7
|
+
}
|
|
8
|
+
host = window.location.hostname;
|
|
9
|
+
if (host.indexOf('.') === -1) {
|
|
10
|
+
writeCookie(name, value, expirationDate);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
domainParts = host.split('.');
|
|
14
|
+
domain = domainParts[domainParts.length - 2] + '.' + domainParts[domainParts.length - 1];
|
|
15
|
+
writeCookie(name, value, expirationDate, domain);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
static get(name) {
|
|
19
|
+
var cookiePrefix = name + '=';
|
|
20
|
+
var cookieArray = document.cookie.split(';');
|
|
21
|
+
for (var i = 0; i < cookieArray.length; i++) {
|
|
22
|
+
var cookie = cookieArray[i];
|
|
23
|
+
cookie = cookie.replace(/^\s+/, '');
|
|
24
|
+
if (cookie.lastIndexOf(cookiePrefix, 0) === 0) {
|
|
25
|
+
return cookie.substring(cookiePrefix.length, cookie.length);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
static erase(name) {
|
|
31
|
+
Cookie.set(name, '', -1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function writeCookie(name, value, expirationDate, domain) {
|
|
35
|
+
document.cookie =
|
|
36
|
+
`${name}=${value}` +
|
|
37
|
+
(expirationDate ? `;expires=${expirationDate.toUTCString()}` : '') +
|
|
38
|
+
(domain ? `;domain=${domain}` : '') +
|
|
39
|
+
';path=/;SameSite=Lax' +
|
|
40
|
+
(window.location.protocol === 'https:' ? ';Secure' : '');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { Cookie };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../definitions/detector.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function hasWindow() {
|
|
2
|
+
return typeof window !== 'undefined';
|
|
3
|
+
}
|
|
4
|
+
function hasNavigator() {
|
|
5
|
+
return typeof navigator !== 'undefined';
|
|
6
|
+
}
|
|
7
|
+
function hasDocument() {
|
|
8
|
+
return typeof document !== 'undefined';
|
|
9
|
+
}
|
|
10
|
+
function hasLocalStorage() {
|
|
11
|
+
try {
|
|
12
|
+
return typeof localStorage !== 'undefined';
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function hasSessionStorage() {
|
|
19
|
+
try {
|
|
20
|
+
return typeof sessionStorage !== 'undefined';
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function hasCookieStorage() {
|
|
27
|
+
return hasNavigator() && navigator.cookieEnabled;
|
|
28
|
+
}
|
|
29
|
+
function hasCrypto() {
|
|
30
|
+
return typeof crypto !== 'undefined';
|
|
31
|
+
}
|
|
32
|
+
function hasCryptoRandomValues() {
|
|
33
|
+
return hasCrypto() && typeof crypto.getRandomValues !== 'undefined';
|
|
34
|
+
}
|
|
35
|
+
function hasLocation() {
|
|
36
|
+
return typeof location !== 'undefined';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { hasCookieStorage, hasCrypto, hasCryptoRandomValues, hasDocument, hasLocalStorage, hasLocation, hasNavigator, hasSessionStorage, hasWindow };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { getAvailableStorage } from './storage.mjs';
|
|
2
|
+
|
|
3
|
+
const STORE_KEY = '__coveo.analytics.history';
|
|
4
|
+
const MAX_NUMBER_OF_HISTORY_ELEMENTS = 20;
|
|
5
|
+
const MIN_THRESHOLD_FOR_DUPLICATE_VALUE = 1000 * 60;
|
|
6
|
+
const MAX_VALUE_SIZE = 75;
|
|
7
|
+
class HistoryStore {
|
|
8
|
+
constructor(store) {
|
|
9
|
+
this.store = store || getAvailableStorage();
|
|
10
|
+
}
|
|
11
|
+
addElement(elem) {
|
|
12
|
+
elem.internalTime = new Date().getTime();
|
|
13
|
+
elem = this.cropQueryElement(this.stripEmptyQuery(elem));
|
|
14
|
+
let currentHistory = this.getHistoryWithInternalTime();
|
|
15
|
+
if (currentHistory != null) {
|
|
16
|
+
if (this.isValidEntry(elem)) {
|
|
17
|
+
this.setHistory([elem].concat(currentHistory));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
this.setHistory([elem]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async addElementAsync(elem) {
|
|
25
|
+
elem.internalTime = new Date().getTime();
|
|
26
|
+
elem = this.cropQueryElement(this.stripEmptyQuery(elem));
|
|
27
|
+
let currentHistory = await this.getHistoryWithInternalTimeAsync();
|
|
28
|
+
if (currentHistory != null) {
|
|
29
|
+
if (this.isValidEntry(elem)) {
|
|
30
|
+
this.setHistory([elem].concat(currentHistory));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.setHistory([elem]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
getHistory() {
|
|
38
|
+
const history = this.getHistoryWithInternalTime();
|
|
39
|
+
return this.stripEmptyQueries(this.stripInternalTime(history));
|
|
40
|
+
}
|
|
41
|
+
async getHistoryAsync() {
|
|
42
|
+
const history = await this.getHistoryWithInternalTimeAsync();
|
|
43
|
+
return this.stripEmptyQueries(this.stripInternalTime(history));
|
|
44
|
+
}
|
|
45
|
+
getHistoryWithInternalTime() {
|
|
46
|
+
try {
|
|
47
|
+
const elements = this.store.getItem(STORE_KEY);
|
|
48
|
+
if (elements && typeof elements === 'string') {
|
|
49
|
+
return JSON.parse(elements);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async getHistoryWithInternalTimeAsync() {
|
|
60
|
+
try {
|
|
61
|
+
const elements = await this.store.getItem(STORE_KEY);
|
|
62
|
+
if (elements) {
|
|
63
|
+
return JSON.parse(elements);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
setHistory(history) {
|
|
74
|
+
try {
|
|
75
|
+
this.store.setItem(STORE_KEY, JSON.stringify(history.slice(0, MAX_NUMBER_OF_HISTORY_ELEMENTS)));
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
clear() {
|
|
81
|
+
try {
|
|
82
|
+
this.store.removeItem(STORE_KEY);
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
getMostRecentElement() {
|
|
88
|
+
let currentHistory = this.getHistoryWithInternalTime();
|
|
89
|
+
if (Array.isArray(currentHistory)) {
|
|
90
|
+
const sorted = currentHistory.sort((first, second) => {
|
|
91
|
+
return (second.internalTime || 0) - (first.internalTime || 0);
|
|
92
|
+
});
|
|
93
|
+
return sorted[0];
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
cropQueryElement(part) {
|
|
98
|
+
if (part.name && part.value && part.name.toLowerCase() === 'query') {
|
|
99
|
+
part.value = part.value.slice(0, MAX_VALUE_SIZE);
|
|
100
|
+
}
|
|
101
|
+
return part;
|
|
102
|
+
}
|
|
103
|
+
isValidEntry(elem) {
|
|
104
|
+
let lastEntry = this.getMostRecentElement();
|
|
105
|
+
if (lastEntry && lastEntry.value == elem.value) {
|
|
106
|
+
return ((elem.internalTime || 0) - (lastEntry.internalTime || 0) > MIN_THRESHOLD_FOR_DUPLICATE_VALUE);
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
stripInternalTime(history) {
|
|
111
|
+
if (Array.isArray(history)) {
|
|
112
|
+
return history.map((part) => {
|
|
113
|
+
const { name, time, value } = part;
|
|
114
|
+
return { name, time, value };
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
stripEmptyQuery(part) {
|
|
120
|
+
const { name, time, value } = part;
|
|
121
|
+
if (name &&
|
|
122
|
+
typeof value === 'string' &&
|
|
123
|
+
name.toLowerCase() === 'query' &&
|
|
124
|
+
value.trim() === '') {
|
|
125
|
+
return { name, time };
|
|
126
|
+
}
|
|
127
|
+
return part;
|
|
128
|
+
}
|
|
129
|
+
stripEmptyQueries(history) {
|
|
130
|
+
return history.map((part) => this.stripEmptyQuery(part));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { HistoryStore, MAX_NUMBER_OF_HISTORY_ELEMENTS, MAX_VALUE_SIZE, MIN_THRESHOLD_FOR_DUPLICATE_VALUE, STORE_KEY, HistoryStore as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../definitions/storage.js';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { hasLocalStorage, hasCookieStorage, hasSessionStorage } from './detector.mjs';
|
|
2
|
+
import { Cookie } from './cookieutils.mjs';
|
|
3
|
+
|
|
4
|
+
let preferredStorage = null;
|
|
5
|
+
function getAvailableStorage() {
|
|
6
|
+
if (hasLocalStorage()) {
|
|
7
|
+
return localStorage;
|
|
8
|
+
}
|
|
9
|
+
if (hasCookieStorage()) {
|
|
10
|
+
return new CookieStorage();
|
|
11
|
+
}
|
|
12
|
+
if (hasSessionStorage()) {
|
|
13
|
+
return sessionStorage;
|
|
14
|
+
}
|
|
15
|
+
return new NullStorage();
|
|
16
|
+
}
|
|
17
|
+
class CookieStorage {
|
|
18
|
+
getItem(key) {
|
|
19
|
+
return Cookie.get(`${CookieStorage.prefix}${key}`);
|
|
20
|
+
}
|
|
21
|
+
removeItem(key) {
|
|
22
|
+
Cookie.erase(`${CookieStorage.prefix}${key}`);
|
|
23
|
+
}
|
|
24
|
+
setItem(key, data, expire) {
|
|
25
|
+
Cookie.set(`${CookieStorage.prefix}${key}`, data, expire);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
CookieStorage.prefix = 'coveo_';
|
|
29
|
+
class CookieAndLocalStorage {
|
|
30
|
+
constructor() {
|
|
31
|
+
this.cookieStorage = new CookieStorage();
|
|
32
|
+
}
|
|
33
|
+
getItem(key) {
|
|
34
|
+
return localStorage.getItem(key) || this.cookieStorage.getItem(key);
|
|
35
|
+
}
|
|
36
|
+
removeItem(key) {
|
|
37
|
+
this.cookieStorage.removeItem(key);
|
|
38
|
+
localStorage.removeItem(key);
|
|
39
|
+
}
|
|
40
|
+
setItem(key, data) {
|
|
41
|
+
localStorage.setItem(key, data);
|
|
42
|
+
this.cookieStorage.setItem(key, data, 31556926000);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class NullStorage {
|
|
46
|
+
getItem(key) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
removeItem(key) {
|
|
50
|
+
}
|
|
51
|
+
setItem(key, data) {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { CookieAndLocalStorage, CookieStorage, NullStorage, getAvailableStorage, preferredStorage };
|
package/dist/library.cjs
CHANGED
|
@@ -669,7 +669,7 @@ function v5(value, namespace, buf, offset) {
|
|
|
669
669
|
v5.DNS = DNS;
|
|
670
670
|
v5.URL = URL$2;
|
|
671
671
|
|
|
672
|
-
var libVersion = "2.
|
|
672
|
+
var libVersion = "2.33.0";
|
|
673
673
|
|
|
674
674
|
var getFormattedLocation = function (location) {
|
|
675
675
|
return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
|
package/dist/library.es.js
CHANGED
|
@@ -524,7 +524,7 @@ function v5(value, namespace, buf, offset) {
|
|
|
524
524
|
v5.DNS = DNS;
|
|
525
525
|
v5.URL = URL$1;
|
|
526
526
|
|
|
527
|
-
const libVersion = "2.
|
|
527
|
+
const libVersion = "2.33.0";
|
|
528
528
|
|
|
529
529
|
const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
|
|
530
530
|
|
package/dist/library.js
CHANGED
|
@@ -669,7 +669,7 @@ function v5(value, namespace, buf, offset) {
|
|
|
669
669
|
v5.DNS = DNS;
|
|
670
670
|
v5.URL = URL$2;
|
|
671
671
|
|
|
672
|
-
var libVersion = "2.
|
|
672
|
+
var libVersion = "2.33.0";
|
|
673
673
|
|
|
674
674
|
var getFormattedLocation = function (location) {
|
|
675
675
|
return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
|
package/dist/library.mjs
CHANGED
|
@@ -667,7 +667,7 @@ function v5(value, namespace, buf, offset) {
|
|
|
667
667
|
v5.DNS = DNS;
|
|
668
668
|
v5.URL = URL$2;
|
|
669
669
|
|
|
670
|
-
var libVersion = "2.
|
|
670
|
+
var libVersion = "2.33.0";
|
|
671
671
|
|
|
672
672
|
var getFormattedLocation = function (location) {
|
|
673
673
|
return "".concat(location.protocol, "//").concat(location.hostname).concat(location.pathname.indexOf('/') === 0 ? location.pathname : "/".concat(location.pathname)).concat(location.search);
|
package/dist/react-native.es.js
CHANGED
|
@@ -596,7 +596,7 @@ const addPageViewToHistory = (pageViewValue) => __awaiter(void 0, void 0, void 0
|
|
|
596
596
|
yield store.addElementAsync(historyElement);
|
|
597
597
|
});
|
|
598
598
|
|
|
599
|
-
const libVersion = "2.
|
|
599
|
+
const libVersion = "2.33.0";
|
|
600
600
|
|
|
601
601
|
const getFormattedLocation = (location) => `${location.protocol}//${location.hostname}${location.pathname.indexOf('/') === 0 ? location.pathname : `/${location.pathname}`}${location.search}`;
|
|
602
602
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coveo.analytics",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.33.0",
|
|
4
4
|
"description": "📈 Coveo analytics client (node and browser compatible) ",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Coveo",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"files": [
|
|
13
13
|
"modules/",
|
|
14
14
|
"dist/**/*.d.ts",
|
|
15
|
+
"dist/**/*.d.mts",
|
|
15
16
|
"dist/**/*.js",
|
|
16
17
|
"dist/**/*.mjs",
|
|
17
18
|
"dist/**/*.cjs",
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
"fetch-mock": "9.11.0",
|
|
43
44
|
"jsdom": "28.1.0",
|
|
44
45
|
"node-fetch": "2.7.0",
|
|
46
|
+
"publint": "0.3.22",
|
|
45
47
|
"react-native-get-random-values": "1.11.0",
|
|
46
48
|
"rollup": "4.62.4",
|
|
47
49
|
"rollup-plugin-copy": "3.5.0",
|
|
@@ -50,7 +52,11 @@
|
|
|
50
52
|
"typescript": "6.0.3",
|
|
51
53
|
"vitest": "4.1.10"
|
|
52
54
|
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": "^22.11.0 || ^24.11.0"
|
|
57
|
+
},
|
|
53
58
|
"scripts": {
|
|
59
|
+
"publint": "publint",
|
|
54
60
|
"build": "rollup -c",
|
|
55
61
|
"start": "rollup -c -w --environment SERVE",
|
|
56
62
|
"test": "vitest run",
|