core-outline 1.1.10 → 1.1.11
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/package.json
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from
|
|
2
|
-
import { record } from
|
|
3
|
-
import { v4 } from
|
|
4
|
-
import socket from
|
|
1
|
+
import React, { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { record } from "rrweb";
|
|
3
|
+
import { v4 } from "uuid";
|
|
4
|
+
import socket from "./socket";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
EventType,
|
|
8
|
-
eventWithTime,
|
|
9
|
-
IncrementalSource,
|
|
10
|
-
MouseInteractions,
|
|
11
|
-
} from 'rrweb';
|
|
6
|
+
import { EventType, eventWithTime, IncrementalSource, MouseInteractions } from "rrweb";
|
|
12
7
|
|
|
13
8
|
const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
14
9
|
const [events, setEvents] = useState([]);
|
|
@@ -17,62 +12,60 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
17
12
|
const [currentPage, setCurrentPage] = useState(window.location.href);
|
|
18
13
|
const [location, setLocation] = useState({ latitude: null, longitude: null });
|
|
19
14
|
const [browser, setBrowser] = useState(getBrowserInfo());
|
|
20
|
-
const [appToken, setAppToken] = useState(
|
|
21
|
-
const [sessionId, setSessionId] = useState(
|
|
15
|
+
const [appToken, setAppToken] = useState("");
|
|
16
|
+
const [sessionId, setSessionId] = useState("");
|
|
22
17
|
|
|
23
18
|
async function authorizeApp(data_source_id, data_source_secret) {
|
|
24
19
|
const requestOptions = {
|
|
25
|
-
method:
|
|
20
|
+
method: "POST",
|
|
26
21
|
headers: {
|
|
27
|
-
|
|
22
|
+
"Content-Type": "application/json",
|
|
28
23
|
},
|
|
29
24
|
body: JSON.stringify({
|
|
30
25
|
data_source_id: data_source_id,
|
|
31
26
|
data_source_secret: data_source_secret,
|
|
32
27
|
}),
|
|
33
28
|
};
|
|
34
|
-
const response = fetch(
|
|
35
|
-
`http://localhost:4000/data-source/authorize`,
|
|
36
|
-
requestOptions
|
|
37
|
-
)
|
|
29
|
+
const response = fetch(`http://localhost:4000/data-source/authorize`, requestOptions)
|
|
38
30
|
.then((response) => response.json())
|
|
39
31
|
.then((data) => {
|
|
40
32
|
setAppToken(data.app_token);
|
|
41
33
|
return data;
|
|
42
34
|
})
|
|
43
35
|
.catch((error) => {
|
|
44
|
-
console.error(
|
|
36
|
+
console.error("Error:", error);
|
|
45
37
|
return error;
|
|
46
38
|
});
|
|
47
39
|
return response;
|
|
48
40
|
}
|
|
49
41
|
useEffect(async () => {
|
|
50
42
|
await authorizeApp(data_source_id, data_source_secret);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
localStorage.setItem(
|
|
54
|
-
|
|
43
|
+
let sessionId = v4();
|
|
44
|
+
setSessionId(sessionId);
|
|
45
|
+
localStorage.setItem("coreOutlineSessionId", sessionId);
|
|
46
|
+
localStorage.setItem("coreOutlineDataSourceIdId", data_source_id);
|
|
47
|
+
console.log("Session", sessionId);
|
|
55
48
|
socket.send({
|
|
56
|
-
topic:
|
|
49
|
+
topic: "session-data",
|
|
57
50
|
data_source_id: data_source_id,
|
|
58
|
-
session_id:
|
|
51
|
+
session_id: localStorage.getItem("coreOutlineSessionId"),
|
|
59
52
|
start_date: new Date().toLocaleString(),
|
|
60
53
|
latitude: location.latitude,
|
|
61
54
|
longitude: location.longitude,
|
|
62
55
|
browser: browser,
|
|
63
|
-
event_id:
|
|
56
|
+
event_id: "SESSION_START",
|
|
64
57
|
});
|
|
65
58
|
|
|
66
59
|
return () => {
|
|
67
60
|
socket.send({
|
|
68
|
-
topic:
|
|
61
|
+
topic: "session-data",
|
|
69
62
|
data_source_id: data_source_id,
|
|
70
|
-
session_id:
|
|
63
|
+
session_id: localStorage.getItem("coreOutlineSessionId"),
|
|
71
64
|
start_date: new Date().toLocaleString(),
|
|
72
65
|
latitude: location.latitude,
|
|
73
66
|
longitude: location.longitude,
|
|
74
67
|
browser: browser,
|
|
75
|
-
event_id:
|
|
68
|
+
event_id: "SESSION_END",
|
|
76
69
|
});
|
|
77
70
|
};
|
|
78
71
|
}, []);
|
|
@@ -103,20 +96,20 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
103
96
|
const handleNavigation = () => {
|
|
104
97
|
setCurrentPage(window.location.href);
|
|
105
98
|
socket.send({
|
|
106
|
-
topic:
|
|
99
|
+
topic: "session-data",
|
|
107
100
|
data_source_id: data_source_id,
|
|
108
|
-
session_id:
|
|
101
|
+
session_id: localStorage.getItem("coreOutlineSessionId"),
|
|
109
102
|
start_date: new Date().toLocaleString(),
|
|
110
103
|
latitude: location.latitude,
|
|
111
104
|
longitude: location.longitude,
|
|
112
105
|
browser: browser,
|
|
113
106
|
page_name: window.location.href,
|
|
114
|
-
event_id:
|
|
107
|
+
event_id: "PAGE_NAVIGATION",
|
|
115
108
|
});
|
|
116
109
|
saveEvents(events);
|
|
117
110
|
};
|
|
118
111
|
|
|
119
|
-
window.addEventListener(
|
|
112
|
+
window.addEventListener("popstate", handleNavigation);
|
|
120
113
|
const originalPushState = window.history.pushState;
|
|
121
114
|
window.history.pushState = function (...args) {
|
|
122
115
|
originalPushState.apply(this, args);
|
|
@@ -124,13 +117,13 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
124
117
|
};
|
|
125
118
|
|
|
126
119
|
return () => {
|
|
127
|
-
window.removeEventListener(
|
|
120
|
+
window.removeEventListener("popstate", handleNavigation);
|
|
128
121
|
window.history.pushState = originalPushState;
|
|
129
122
|
};
|
|
130
123
|
}, [currentPage]);
|
|
131
124
|
|
|
132
125
|
useEffect(() => {
|
|
133
|
-
console.log(
|
|
126
|
+
console.log("Location", location);
|
|
134
127
|
getLocation();
|
|
135
128
|
}, []);
|
|
136
129
|
|
|
@@ -163,7 +156,7 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
163
156
|
if (!recorderActive.current) {
|
|
164
157
|
stopFn = record({
|
|
165
158
|
emit(event) {
|
|
166
|
-
console.log(
|
|
159
|
+
console.log("Event:", event);
|
|
167
160
|
if (event.type == 3 && event.data.type == 2) {
|
|
168
161
|
return;
|
|
169
162
|
}
|
|
@@ -177,7 +170,7 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
177
170
|
return;
|
|
178
171
|
}
|
|
179
172
|
if (event.type == 3 && event.data.type == 3) {
|
|
180
|
-
console.log(
|
|
173
|
+
console.log("Contextmenu Event:", event);
|
|
181
174
|
}
|
|
182
175
|
setEvents((prevEvents) => [...prevEvents, event]);
|
|
183
176
|
},
|
|
@@ -200,7 +193,7 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
200
193
|
|
|
201
194
|
useEffect(() => {
|
|
202
195
|
const handleClick = (event) => {
|
|
203
|
-
console.log(
|
|
196
|
+
console.log("Inner text:", event.target.innerText);
|
|
204
197
|
const clickEvent = {
|
|
205
198
|
type: EventType.IncrementalSnapshot,
|
|
206
199
|
data: {
|
|
@@ -212,33 +205,15 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
212
205
|
},
|
|
213
206
|
timestamp: Date.now(),
|
|
214
207
|
};
|
|
215
|
-
const clickedElement = document.elementFromPoint(
|
|
216
|
-
clickEvent.data.x,
|
|
217
|
-
clickEvent.data.y
|
|
218
|
-
);
|
|
208
|
+
const clickedElement = document.elementFromPoint(clickEvent.data.x, clickEvent.data.y);
|
|
219
209
|
|
|
220
210
|
if (clickedElement) {
|
|
221
211
|
clickEvent.data.metadata = {
|
|
222
|
-
label:
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
clickedElement.getAttribute('value') ||
|
|
228
|
-
clickedElement.innerText ||
|
|
229
|
-
null,
|
|
230
|
-
id:
|
|
231
|
-
clickedElement.getAttribute('id') ||
|
|
232
|
-
clickedElement.innerText ||
|
|
233
|
-
null,
|
|
234
|
-
name:
|
|
235
|
-
clickedElement.getAttribute('name') ||
|
|
236
|
-
clickedElement.innerText ||
|
|
237
|
-
null,
|
|
238
|
-
class:
|
|
239
|
-
clickedElement.getAttribute('class') ||
|
|
240
|
-
clickedElement.innerText ||
|
|
241
|
-
null,
|
|
212
|
+
label: clickedElement.getAttribute("data-label") || clickedElement.innerText || null,
|
|
213
|
+
value: clickedElement.getAttribute("value") || clickedElement.innerText || null,
|
|
214
|
+
id: clickedElement.getAttribute("id") || clickedElement.innerText || null,
|
|
215
|
+
name: clickedElement.getAttribute("name") || clickedElement.innerText || null,
|
|
216
|
+
class: clickedElement.getAttribute("class") || clickedElement.innerText || null,
|
|
242
217
|
tag: clickedElement.tagName,
|
|
243
218
|
html: String(clickedElement.getHTML()),
|
|
244
219
|
innerText: event.target.innerText,
|
|
@@ -247,56 +222,50 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
247
222
|
setEvents((prevEvents) => [...prevEvents, clickEvent]);
|
|
248
223
|
|
|
249
224
|
socket.send({
|
|
250
|
-
topic:
|
|
225
|
+
topic: "session-data",
|
|
251
226
|
data_source_id: data_source_id,
|
|
252
|
-
session_id:
|
|
227
|
+
session_id: localStorage.getItem("coreOutlineSessionId"),
|
|
253
228
|
start_date: new Date().toLocaleString(),
|
|
254
229
|
latitude: location.latitude,
|
|
255
230
|
longitude: location.longitude,
|
|
256
231
|
browser: browser,
|
|
257
|
-
event_id:
|
|
232
|
+
event_id: "ITEM_CLICKED",
|
|
258
233
|
// item_clicked: event.target,
|
|
259
234
|
});
|
|
260
235
|
};
|
|
261
236
|
|
|
262
|
-
document.addEventListener(
|
|
237
|
+
document.addEventListener("click", handleClick);
|
|
263
238
|
|
|
264
239
|
return () => {
|
|
265
|
-
document.removeEventListener(
|
|
240
|
+
document.removeEventListener("click", handleClick);
|
|
266
241
|
};
|
|
267
242
|
}, []);
|
|
268
243
|
|
|
269
244
|
function saveEvents(events) {
|
|
270
|
-
const requestOptions = {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
};
|
|
277
|
-
fetch(
|
|
278
|
-
|
|
279
|
-
)
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return fetch(uploadURL, requestOptions);
|
|
284
|
-
});
|
|
245
|
+
// const requestOptions = {
|
|
246
|
+
// method: "PUT",
|
|
247
|
+
// headers: {
|
|
248
|
+
// "Content-Type": "application/json",
|
|
249
|
+
// },
|
|
250
|
+
// body: JSON.stringify(events),
|
|
251
|
+
// };
|
|
252
|
+
// fetch(`http://localhost:5000/generate-s3-url/${data_source_id}/${sessionId}`)
|
|
253
|
+
// .then((response) => response.json())
|
|
254
|
+
// .then((data) => {
|
|
255
|
+
// const uploadURL = data.signed_url;
|
|
256
|
+
// return fetch(uploadURL, requestOptions);
|
|
257
|
+
// });
|
|
285
258
|
}
|
|
286
259
|
|
|
287
|
-
function saveEventsLocally(type =
|
|
288
|
-
let blob =
|
|
289
|
-
if (type ===
|
|
290
|
-
blob = new Blob([JSON.stringify(events, null, 2)], {
|
|
291
|
-
|
|
292
|
-
});
|
|
293
|
-
} else if (type === 'raw') {
|
|
294
|
-
blob = new Blob([JSON.stringify(replayEvents, null, 2)], {
|
|
295
|
-
type: 'application/json',
|
|
296
|
-
});
|
|
260
|
+
function saveEventsLocally(type = "formatted" || "raw") {
|
|
261
|
+
let blob = "";
|
|
262
|
+
if (type === "formatted") {
|
|
263
|
+
blob = new Blob([JSON.stringify(events, null, 2)], { type: "application/json" });
|
|
264
|
+
} else if (type === "raw") {
|
|
265
|
+
blob = new Blob([JSON.stringify(replayEvents, null, 2)], { type: "application/json" });
|
|
297
266
|
}
|
|
298
267
|
const url = URL.createObjectURL(blob);
|
|
299
|
-
const a = document.createElement(
|
|
268
|
+
const a = document.createElement("a");
|
|
300
269
|
a.href = url;
|
|
301
270
|
a.download = `${type}_events.json`;
|
|
302
271
|
a.click();
|
|
@@ -305,24 +274,18 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
305
274
|
|
|
306
275
|
function getBrowserInfo() {
|
|
307
276
|
const userAgent = navigator.userAgent;
|
|
308
|
-
let browserName =
|
|
277
|
+
let browserName = "Unknown";
|
|
309
278
|
|
|
310
|
-
if (userAgent.indexOf(
|
|
311
|
-
browserName =
|
|
312
|
-
} else if (
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
browserName = 'Safari';
|
|
321
|
-
} else if (
|
|
322
|
-
userAgent.indexOf('MSIE') > -1 ||
|
|
323
|
-
userAgent.indexOf('Trident/') > -1
|
|
324
|
-
) {
|
|
325
|
-
browserName = 'Internet Explorer';
|
|
279
|
+
if (userAgent.indexOf("Firefox") > -1) {
|
|
280
|
+
browserName = "Firefox";
|
|
281
|
+
} else if (userAgent.indexOf("Opera") > -1 || userAgent.indexOf("OPR") > -1) {
|
|
282
|
+
browserName = "Opera";
|
|
283
|
+
} else if (userAgent.indexOf("Chrome") > -1) {
|
|
284
|
+
browserName = "Chrome";
|
|
285
|
+
} else if (userAgent.indexOf("Safari") > -1) {
|
|
286
|
+
browserName = "Safari";
|
|
287
|
+
} else if (userAgent.indexOf("MSIE") > -1 || userAgent.indexOf("Trident/") > -1) {
|
|
288
|
+
browserName = "Internet Explorer";
|
|
326
289
|
}
|
|
327
290
|
|
|
328
291
|
return browserName;
|
|
@@ -338,51 +301,59 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
338
301
|
});
|
|
339
302
|
},
|
|
340
303
|
(error) => {
|
|
341
|
-
console.error(
|
|
304
|
+
console.error("Error getting location:", error);
|
|
342
305
|
}
|
|
343
306
|
);
|
|
344
307
|
} else {
|
|
345
|
-
console.error(
|
|
308
|
+
console.error("Geolocation is not supported by this browser.");
|
|
346
309
|
}
|
|
347
310
|
}
|
|
348
311
|
|
|
349
312
|
return (
|
|
350
313
|
<div>
|
|
314
|
+
<button
|
|
315
|
+
onClick={() => {
|
|
316
|
+
saveEventsLocally("formatted");
|
|
317
|
+
saveEventsLocally("raw");
|
|
318
|
+
}}
|
|
319
|
+
>
|
|
320
|
+
Save Events Locally
|
|
321
|
+
</button>
|
|
351
322
|
{children}
|
|
352
323
|
</div>
|
|
353
324
|
);
|
|
354
325
|
};
|
|
355
326
|
|
|
356
327
|
export const flag_item_clicked = (item_id) => {
|
|
357
|
-
const sessionId = localStorage.getItem(
|
|
358
|
-
const dataSourceId = localStorage.getItem(
|
|
359
|
-
console.log(
|
|
360
|
-
console.log(
|
|
328
|
+
const sessionId = localStorage.getItem("coreOutlineSessionId");
|
|
329
|
+
const dataSourceId = localStorage.getItem("coreOutlineDataSourceIdId");
|
|
330
|
+
console.log("Session", sessionId);
|
|
331
|
+
console.log("Data Source", dataSourceId);
|
|
361
332
|
socket.send({
|
|
362
|
-
topic:
|
|
333
|
+
topic: "session-data",
|
|
363
334
|
data_source_id: dataSourceId,
|
|
364
|
-
session_id:
|
|
335
|
+
session_id: localStorage.getItem("coreOutlineSessionId"),
|
|
365
336
|
start_date: new Date().toLocaleString(),
|
|
366
|
-
event_id:
|
|
337
|
+
event_id: "PRODUCT_CLICKED",
|
|
367
338
|
item_clicked: item_id,
|
|
368
339
|
});
|
|
369
|
-
return { status:
|
|
340
|
+
return { status: "success", message: "Item click flagged successfully." };
|
|
370
341
|
};
|
|
371
342
|
|
|
372
343
|
export const flag_item_purchased = (item_id) => {
|
|
373
|
-
const sessionId = localStorage.getItem(
|
|
374
|
-
const dataSourceId = localStorage.getItem(
|
|
375
|
-
console.log(
|
|
376
|
-
console.log(
|
|
344
|
+
const sessionId = localStorage.getItem("coreOutlineSessionId");
|
|
345
|
+
const dataSourceId = localStorage.getItem("coreOutlineDataSourceIdId");
|
|
346
|
+
console.log("Session", sessionId);
|
|
347
|
+
console.log("Data Source", dataSourceId);
|
|
377
348
|
socket.send({
|
|
378
|
-
topic:
|
|
349
|
+
topic: "session-data",
|
|
379
350
|
data_source_id: dataSourceId,
|
|
380
|
-
session_id:
|
|
351
|
+
session_id: localStorage.getItem("coreOutlineSessionId"),
|
|
381
352
|
start_date: new Date().toLocaleString(),
|
|
382
|
-
event_id:
|
|
353
|
+
event_id: "PRODUCT_PURCHASED",
|
|
383
354
|
item_clicked: item_id,
|
|
384
355
|
});
|
|
385
|
-
return { status:
|
|
356
|
+
return { status: "success", message: "Item purchase flagged successfully." };
|
|
386
357
|
};
|
|
387
358
|
|
|
388
359
|
export default CoreOutline;
|