core-outline 0.0.8 → 0.1.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/README.md +7 -7
- package/dist/index.es.js +98 -51
- package/dist/index.js +98 -51
- package/package.json +1 -1
- package/src/index.js +18 -7
- package/src/lib/request/app.js +3 -3
- package/src/lib/streams/producer.js +1 -1
- package/src/services/page/update-page.js +7 -5
- package/src/services/session/end-session.js +15 -16
- package/src/services/session/start-session.js +48 -11
- package/src/services/target/update-target.js +3 -3
package/README.md
CHANGED
|
@@ -19,24 +19,24 @@ var session_details = core.sessionDetails()
|
|
|
19
19
|
"session_id":"<session_id>",
|
|
20
20
|
}
|
|
21
21
|
"""
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
# Tracking user actions
|
|
23
|
+
### Update current page
|
|
24
24
|
|
|
25
25
|
Use this function when a user enters a page:
|
|
26
26
|
|
|
27
|
-
core.
|
|
27
|
+
core.setCurrentPage(<current_page_name>, <is_terminal>)
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
### Register a made purchase
|
|
30
30
|
|
|
31
31
|
Add this function to an onclick listener for when a user completes a transaction
|
|
32
32
|
|
|
33
|
-
core.
|
|
33
|
+
core.recordPurchase()
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
### Register an action item click
|
|
36
36
|
|
|
37
37
|
This function is to be used when a user clicks on one of the recommended actions items
|
|
38
38
|
|
|
39
|
-
core.
|
|
39
|
+
core.recordItemClick(<recommended_action_item_name>)
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
|
package/dist/index.es.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const uuid = require('uuid');
|
|
2
2
|
const {
|
|
3
|
-
io: io$
|
|
3
|
+
io: io$3
|
|
4
4
|
} = require('socket.io-client');
|
|
5
|
-
const socket$
|
|
6
|
-
function streamData$
|
|
7
|
-
socket$
|
|
5
|
+
const socket$3 = io$3('http://52.35.48.129:4000');
|
|
6
|
+
function streamData$3(data) {
|
|
7
|
+
socket$3.emit('dataEvent', data);
|
|
8
8
|
}
|
|
9
9
|
const makeRequest = async ({
|
|
10
10
|
url,
|
|
@@ -13,12 +13,26 @@ const makeRequest = async ({
|
|
|
13
13
|
params,
|
|
14
14
|
method
|
|
15
15
|
}) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
let res;
|
|
17
|
+
console.log(url);
|
|
18
|
+
console.log(params);
|
|
19
|
+
if (params) {
|
|
20
|
+
res = await fetch(`${url}${params}`).then(function (response) {
|
|
21
|
+
console.log(response);
|
|
22
|
+
return response.json();
|
|
23
|
+
}).then(function (json) {
|
|
24
|
+
console.log(json);
|
|
25
|
+
return json;
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
res = await fetch(`${url}`).then(function (response) {
|
|
29
|
+
console.log(response);
|
|
30
|
+
return response.json();
|
|
31
|
+
}).then(function (json) {
|
|
32
|
+
console.log(json);
|
|
33
|
+
return json;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
22
36
|
return res;
|
|
23
37
|
};
|
|
24
38
|
async function getSessionLocation() {
|
|
@@ -28,82 +42,115 @@ async function getSessionLocation() {
|
|
|
28
42
|
});
|
|
29
43
|
return res;
|
|
30
44
|
}
|
|
31
|
-
|
|
45
|
+
async function getAppDetails(app_id) {
|
|
46
|
+
const res = await makeRequest({
|
|
47
|
+
url: "http://52.35.48.129:5000/data-source/get-data-source",
|
|
48
|
+
method: 'get',
|
|
49
|
+
params: `?type=saas&app_id=${app_id}`
|
|
50
|
+
});
|
|
51
|
+
return res;
|
|
52
|
+
}
|
|
53
|
+
const startSession = async app_id => {
|
|
32
54
|
let loc = await getSessionLocation();
|
|
55
|
+
console.log(loc);
|
|
56
|
+
data_source = await getAppDetails(app_id);
|
|
57
|
+
console.log(data_source);
|
|
33
58
|
let session = {
|
|
59
|
+
"topic": "session-data",
|
|
60
|
+
"data_source_id": data_source?.data_source_id,
|
|
34
61
|
"session_id": uuid.v4(),
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
62
|
+
"start_date": new Date(Date.now()).toDateString(),
|
|
63
|
+
"latitude": loc?.lat,
|
|
64
|
+
"longitude": loc?.lon,
|
|
65
|
+
"country": loc?.country,
|
|
66
|
+
"region": loc?.regionName,
|
|
67
|
+
"city": loc?.city,
|
|
68
|
+
"device": "getDeviceInfo"
|
|
42
69
|
};
|
|
43
70
|
console.log(session);
|
|
44
|
-
streamData$
|
|
45
|
-
"topic": "session-data",
|
|
46
|
-
"data": session
|
|
47
|
-
});
|
|
71
|
+
streamData$3(session);
|
|
48
72
|
return session;
|
|
49
73
|
};
|
|
50
74
|
|
|
51
75
|
const {
|
|
52
|
-
io: io$
|
|
76
|
+
io: io$2
|
|
53
77
|
} = require('socket.io-client');
|
|
54
|
-
const socket$
|
|
55
|
-
function streamData$
|
|
56
|
-
socket$
|
|
78
|
+
const socket$2 = io$2('http://52.35.48.129:4000');
|
|
79
|
+
function streamData$2(data) {
|
|
80
|
+
socket$2.emit('dataEvent', data);
|
|
57
81
|
}
|
|
58
|
-
const updatePage = async (session_id, location) => {
|
|
82
|
+
const updatePage = async (session_id, location, is_terminal = false) => {
|
|
59
83
|
let page = {};
|
|
60
84
|
page = {
|
|
85
|
+
"topic": "page-data",
|
|
61
86
|
"session_id": session_id,
|
|
62
|
-
"start_date": Date.now(),
|
|
63
|
-
"
|
|
64
|
-
"
|
|
87
|
+
"start_date": new Date(Date.now()).toDateString(),
|
|
88
|
+
"page_name": location,
|
|
89
|
+
"is_terminal": is_terminal
|
|
65
90
|
};
|
|
66
|
-
streamData$
|
|
67
|
-
"topic": "page-data",
|
|
68
|
-
"data": page
|
|
69
|
-
});
|
|
91
|
+
streamData$2(page);
|
|
70
92
|
return page;
|
|
71
93
|
};
|
|
72
94
|
|
|
73
95
|
const {
|
|
74
|
-
io
|
|
96
|
+
io: io$1
|
|
75
97
|
} = require('socket.io-client');
|
|
76
|
-
const socket = io('http://
|
|
77
|
-
function streamData(data) {
|
|
78
|
-
socket.emit('dataEvent', data);
|
|
98
|
+
const socket$1 = io$1('http://52.35.48.129:4000');
|
|
99
|
+
function streamData$1(data) {
|
|
100
|
+
socket$1.emit('dataEvent', data);
|
|
79
101
|
}
|
|
80
102
|
const targetReached = async session_id => {
|
|
81
|
-
streamData({
|
|
82
|
-
"topic": "
|
|
83
|
-
"session_id": session_id
|
|
103
|
+
streamData$1({
|
|
104
|
+
"topic": "update-session-data",
|
|
105
|
+
"session_id": session_id,
|
|
106
|
+
"click_through": true
|
|
84
107
|
});
|
|
85
108
|
};
|
|
86
109
|
const registerClick = async (session_id, item_id) => {
|
|
87
|
-
streamData({
|
|
88
|
-
"topic": "
|
|
110
|
+
streamData$1({
|
|
111
|
+
"topic": "update-session-data",
|
|
89
112
|
"session_id": session_id,
|
|
90
|
-
"
|
|
113
|
+
"item_clicked": item_id
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const {
|
|
118
|
+
io
|
|
119
|
+
} = require('socket.io-client');
|
|
120
|
+
const socket = io('http://52.35.48.129:4000');
|
|
121
|
+
function streamData(data) {
|
|
122
|
+
socket.emit('dataEvent', data);
|
|
123
|
+
}
|
|
124
|
+
const endSession = async (session_id, end_date) => {
|
|
125
|
+
streamData({
|
|
126
|
+
topic: "update-session-data",
|
|
127
|
+
session_id,
|
|
128
|
+
end_date
|
|
91
129
|
});
|
|
92
130
|
};
|
|
93
131
|
|
|
94
132
|
class CoreOutline {
|
|
95
|
-
constructor(
|
|
96
|
-
this.
|
|
97
|
-
this.secret_id = secret_id;
|
|
98
|
-
this.sessionDetails = startSession();
|
|
133
|
+
constructor(app_id) {
|
|
134
|
+
this.sessionDetails = startSession(app_id);
|
|
99
135
|
this.startSession = startSession;
|
|
100
|
-
this.
|
|
136
|
+
this.endSession = endSession;
|
|
137
|
+
this.pageDetails = updatePage(this.sessionDetails?.session_id, "");
|
|
101
138
|
this.updatePage = updatePage;
|
|
102
139
|
this.targetReached = targetReached;
|
|
103
140
|
this.registerClick = registerClick;
|
|
104
141
|
}
|
|
105
|
-
|
|
106
|
-
this.sessionDetails.end_time = Date.now();
|
|
142
|
+
endCurrentSession() {
|
|
143
|
+
this.sessionDetails.end_time = new Date(Date.now()).toDateString();
|
|
144
|
+
this.endSession(this.sessionDetails?.session_id, this.sessionDetails.end_time);
|
|
145
|
+
}
|
|
146
|
+
setCurrentPage(page_name, is_terminal = false) {
|
|
147
|
+
this.updatePage(this.sessionDetails?.session_id, page_name, is_terminal);
|
|
148
|
+
}
|
|
149
|
+
recordPurchase() {
|
|
150
|
+
this.targetReached(this.sessionDetails?.session_id);
|
|
151
|
+
}
|
|
152
|
+
recordItemClick(item_id) {
|
|
153
|
+
this.registerClick(this.sessionDetails?.session_id, item_id);
|
|
107
154
|
}
|
|
108
155
|
}
|
|
109
156
|
|
package/dist/index.js
CHANGED
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const uuid = require('uuid');
|
|
6
6
|
const {
|
|
7
|
-
io: io$
|
|
7
|
+
io: io$3
|
|
8
8
|
} = require('socket.io-client');
|
|
9
|
-
const socket$
|
|
10
|
-
function streamData$
|
|
11
|
-
socket$
|
|
9
|
+
const socket$3 = io$3('http://52.35.48.129:4000');
|
|
10
|
+
function streamData$3(data) {
|
|
11
|
+
socket$3.emit('dataEvent', data);
|
|
12
12
|
}
|
|
13
13
|
const makeRequest = async ({
|
|
14
14
|
url,
|
|
@@ -17,12 +17,26 @@ const makeRequest = async ({
|
|
|
17
17
|
params,
|
|
18
18
|
method
|
|
19
19
|
}) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
let res;
|
|
21
|
+
console.log(url);
|
|
22
|
+
console.log(params);
|
|
23
|
+
if (params) {
|
|
24
|
+
res = await fetch(`${url}${params}`).then(function (response) {
|
|
25
|
+
console.log(response);
|
|
26
|
+
return response.json();
|
|
27
|
+
}).then(function (json) {
|
|
28
|
+
console.log(json);
|
|
29
|
+
return json;
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
res = await fetch(`${url}`).then(function (response) {
|
|
33
|
+
console.log(response);
|
|
34
|
+
return response.json();
|
|
35
|
+
}).then(function (json) {
|
|
36
|
+
console.log(json);
|
|
37
|
+
return json;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
26
40
|
return res;
|
|
27
41
|
};
|
|
28
42
|
async function getSessionLocation() {
|
|
@@ -32,82 +46,115 @@ async function getSessionLocation() {
|
|
|
32
46
|
});
|
|
33
47
|
return res;
|
|
34
48
|
}
|
|
35
|
-
|
|
49
|
+
async function getAppDetails(app_id) {
|
|
50
|
+
const res = await makeRequest({
|
|
51
|
+
url: "http://52.35.48.129:5000/data-source/get-data-source",
|
|
52
|
+
method: 'get',
|
|
53
|
+
params: `?type=saas&app_id=${app_id}`
|
|
54
|
+
});
|
|
55
|
+
return res;
|
|
56
|
+
}
|
|
57
|
+
const startSession = async app_id => {
|
|
36
58
|
let loc = await getSessionLocation();
|
|
59
|
+
console.log(loc);
|
|
60
|
+
data_source = await getAppDetails(app_id);
|
|
61
|
+
console.log(data_source);
|
|
37
62
|
let session = {
|
|
63
|
+
"topic": "session-data",
|
|
64
|
+
"data_source_id": data_source?.data_source_id,
|
|
38
65
|
"session_id": uuid.v4(),
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
66
|
+
"start_date": new Date(Date.now()).toDateString(),
|
|
67
|
+
"latitude": loc?.lat,
|
|
68
|
+
"longitude": loc?.lon,
|
|
69
|
+
"country": loc?.country,
|
|
70
|
+
"region": loc?.regionName,
|
|
71
|
+
"city": loc?.city,
|
|
72
|
+
"device": "getDeviceInfo"
|
|
46
73
|
};
|
|
47
74
|
console.log(session);
|
|
48
|
-
streamData$
|
|
49
|
-
"topic": "session-data",
|
|
50
|
-
"data": session
|
|
51
|
-
});
|
|
75
|
+
streamData$3(session);
|
|
52
76
|
return session;
|
|
53
77
|
};
|
|
54
78
|
|
|
55
79
|
const {
|
|
56
|
-
io: io$
|
|
80
|
+
io: io$2
|
|
57
81
|
} = require('socket.io-client');
|
|
58
|
-
const socket$
|
|
59
|
-
function streamData$
|
|
60
|
-
socket$
|
|
82
|
+
const socket$2 = io$2('http://52.35.48.129:4000');
|
|
83
|
+
function streamData$2(data) {
|
|
84
|
+
socket$2.emit('dataEvent', data);
|
|
61
85
|
}
|
|
62
|
-
const updatePage = async (session_id, location) => {
|
|
86
|
+
const updatePage = async (session_id, location, is_terminal = false) => {
|
|
63
87
|
let page = {};
|
|
64
88
|
page = {
|
|
89
|
+
"topic": "page-data",
|
|
65
90
|
"session_id": session_id,
|
|
66
|
-
"start_date": Date.now(),
|
|
67
|
-
"
|
|
68
|
-
"
|
|
91
|
+
"start_date": new Date(Date.now()).toDateString(),
|
|
92
|
+
"page_name": location,
|
|
93
|
+
"is_terminal": is_terminal
|
|
69
94
|
};
|
|
70
|
-
streamData$
|
|
71
|
-
"topic": "page-data",
|
|
72
|
-
"data": page
|
|
73
|
-
});
|
|
95
|
+
streamData$2(page);
|
|
74
96
|
return page;
|
|
75
97
|
};
|
|
76
98
|
|
|
77
99
|
const {
|
|
78
|
-
io
|
|
100
|
+
io: io$1
|
|
79
101
|
} = require('socket.io-client');
|
|
80
|
-
const socket = io('http://
|
|
81
|
-
function streamData(data) {
|
|
82
|
-
socket.emit('dataEvent', data);
|
|
102
|
+
const socket$1 = io$1('http://52.35.48.129:4000');
|
|
103
|
+
function streamData$1(data) {
|
|
104
|
+
socket$1.emit('dataEvent', data);
|
|
83
105
|
}
|
|
84
106
|
const targetReached = async session_id => {
|
|
85
|
-
streamData({
|
|
86
|
-
"topic": "
|
|
87
|
-
"session_id": session_id
|
|
107
|
+
streamData$1({
|
|
108
|
+
"topic": "update-session-data",
|
|
109
|
+
"session_id": session_id,
|
|
110
|
+
"click_through": true
|
|
88
111
|
});
|
|
89
112
|
};
|
|
90
113
|
const registerClick = async (session_id, item_id) => {
|
|
91
|
-
streamData({
|
|
92
|
-
"topic": "
|
|
114
|
+
streamData$1({
|
|
115
|
+
"topic": "update-session-data",
|
|
93
116
|
"session_id": session_id,
|
|
94
|
-
"
|
|
117
|
+
"item_clicked": item_id
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const {
|
|
122
|
+
io
|
|
123
|
+
} = require('socket.io-client');
|
|
124
|
+
const socket = io('http://52.35.48.129:4000');
|
|
125
|
+
function streamData(data) {
|
|
126
|
+
socket.emit('dataEvent', data);
|
|
127
|
+
}
|
|
128
|
+
const endSession = async (session_id, end_date) => {
|
|
129
|
+
streamData({
|
|
130
|
+
topic: "update-session-data",
|
|
131
|
+
session_id,
|
|
132
|
+
end_date
|
|
95
133
|
});
|
|
96
134
|
};
|
|
97
135
|
|
|
98
136
|
class CoreOutline {
|
|
99
|
-
constructor(
|
|
100
|
-
this.
|
|
101
|
-
this.secret_id = secret_id;
|
|
102
|
-
this.sessionDetails = startSession();
|
|
137
|
+
constructor(app_id) {
|
|
138
|
+
this.sessionDetails = startSession(app_id);
|
|
103
139
|
this.startSession = startSession;
|
|
104
|
-
this.
|
|
140
|
+
this.endSession = endSession;
|
|
141
|
+
this.pageDetails = updatePage(this.sessionDetails?.session_id, "");
|
|
105
142
|
this.updatePage = updatePage;
|
|
106
143
|
this.targetReached = targetReached;
|
|
107
144
|
this.registerClick = registerClick;
|
|
108
145
|
}
|
|
109
|
-
|
|
110
|
-
this.sessionDetails.end_time = Date.now();
|
|
146
|
+
endCurrentSession() {
|
|
147
|
+
this.sessionDetails.end_time = new Date(Date.now()).toDateString();
|
|
148
|
+
this.endSession(this.sessionDetails?.session_id, this.sessionDetails.end_time);
|
|
149
|
+
}
|
|
150
|
+
setCurrentPage(page_name, is_terminal = false) {
|
|
151
|
+
this.updatePage(this.sessionDetails?.session_id, page_name, is_terminal);
|
|
152
|
+
}
|
|
153
|
+
recordPurchase() {
|
|
154
|
+
this.targetReached(this.sessionDetails?.session_id);
|
|
155
|
+
}
|
|
156
|
+
recordItemClick(item_id) {
|
|
157
|
+
this.registerClick(this.sessionDetails?.session_id, item_id);
|
|
111
158
|
}
|
|
112
159
|
}
|
|
113
160
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
import startSession from "./services/session/start-session";
|
|
2
2
|
import updatePage from "./services/page/update-page";
|
|
3
3
|
import { targetReached, registerClick } from "./services/target/update-target"
|
|
4
|
+
import endSession from "./services/session/end-session";
|
|
5
|
+
|
|
4
6
|
|
|
5
7
|
export class CoreOutline {
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
8
|
-
this.secret_id = secret_id;
|
|
9
|
-
this.sessionDetails = startSession();
|
|
8
|
+
constructor(app_id) {
|
|
9
|
+
this.sessionDetails = startSession(app_id);
|
|
10
10
|
this.startSession = startSession;
|
|
11
|
-
this.
|
|
11
|
+
this.endSession = endSession;
|
|
12
|
+
this.pageDetails = updatePage(this.sessionDetails?.session_id, "");
|
|
12
13
|
this.updatePage = updatePage;
|
|
13
14
|
this.targetReached = targetReached;
|
|
14
15
|
this.registerClick = registerClick;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
this.sessionDetails.end_time = Date.now()
|
|
17
|
+
endCurrentSession(){
|
|
18
|
+
this.sessionDetails.end_time =new Date(Date.now()).toDateString()
|
|
19
|
+
this.endSession(this.sessionDetails?.session_id, this.sessionDetails.end_time)
|
|
20
|
+
}
|
|
21
|
+
setCurrentPage(page_name, is_terminal=false){
|
|
22
|
+
this.updatePage(this.sessionDetails?.session_id, page_name, is_terminal)
|
|
23
|
+
}
|
|
24
|
+
recordPurchase(){
|
|
25
|
+
this.targetReached(this.sessionDetails?.session_id)
|
|
26
|
+
}
|
|
27
|
+
recordItemClick(item_id){
|
|
28
|
+
this.registerClick(this.sessionDetails?.session_id, item_id)
|
|
18
29
|
}
|
|
19
30
|
}
|
|
20
31
|
|
package/src/lib/request/app.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
const { io} = require('socket.io-client');
|
|
2
|
-
const socket = io('http://
|
|
2
|
+
const socket = io('http://52.35.48.129:4000');
|
|
3
3
|
|
|
4
4
|
function streamData(data){
|
|
5
5
|
socket.emit('dataEvent', data);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
const updatePage = async(session_id, location) =>{
|
|
8
|
+
const updatePage = async(session_id, location, is_terminal=false) =>{
|
|
9
9
|
let page = {}
|
|
10
10
|
|
|
11
11
|
page = {
|
|
12
|
+
"topic":"page-data",
|
|
12
13
|
"session_id": session_id,
|
|
13
|
-
"start_date": Date.now(),
|
|
14
|
-
"end_date": null,
|
|
14
|
+
"start_date": new Date(Date.now()).toDateString(),
|
|
15
15
|
"page_name": location,
|
|
16
|
+
"is_terminal": is_terminal
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
streamData(
|
|
19
|
+
streamData(page)
|
|
19
20
|
return page
|
|
20
21
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
|
|
25
|
+
|
|
24
26
|
export default updatePage
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
const request = require('../../lib/index.js')
|
|
2
|
-
const { trackingConfigs, appConfigs } = require('../../config/index.js')
|
|
3
1
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)
|
|
2
|
+
const { io} = require('socket.io-client');
|
|
3
|
+
const socket = io('http://52.35.48.129:4000');
|
|
4
|
+
|
|
5
|
+
function streamData(data){
|
|
6
|
+
socket.emit('dataEvent', data);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const endSession = async(session_id, end_date) =>{
|
|
10
|
+
streamData({
|
|
11
|
+
topic:"update-session-data",
|
|
12
|
+
session_id,
|
|
13
|
+
end_date
|
|
14
|
+
})
|
|
18
15
|
}
|
|
19
16
|
|
|
17
|
+
|
|
18
|
+
// endSession('41d600e4-6c17-4626-bff4-8c173f904104', new Date(Date.now()).toLocaleString())
|
|
20
19
|
export default endSession
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const uuid = require('uuid')
|
|
2
2
|
const { io} = require('socket.io-client');
|
|
3
|
-
const socket = io('http://
|
|
3
|
+
const socket = io('http://52.35.48.129:4000');
|
|
4
4
|
|
|
5
5
|
function streamData(data){
|
|
6
6
|
socket.emit('dataEvent', data);
|
|
@@ -9,14 +9,32 @@ function streamData(data){
|
|
|
9
9
|
const makeRequest = async ({
|
|
10
10
|
url, service, body, params, method,
|
|
11
11
|
}) => {
|
|
12
|
-
|
|
12
|
+
let res
|
|
13
|
+
console.log(url)
|
|
14
|
+
console.log(params)
|
|
15
|
+
if(params){
|
|
16
|
+
res = await fetch(`${url}${params}`)
|
|
13
17
|
.then(function(response) {
|
|
14
|
-
|
|
18
|
+
console.log(response)
|
|
19
|
+
return response.json();
|
|
15
20
|
})
|
|
16
21
|
.then(function(json) {
|
|
17
22
|
console.log(json)
|
|
18
23
|
return json
|
|
19
|
-
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else{
|
|
27
|
+
res = await fetch(`${url}`)
|
|
28
|
+
.then(function(response) {
|
|
29
|
+
console.log(response)
|
|
30
|
+
return response.json();
|
|
31
|
+
})
|
|
32
|
+
.then(function(json) {
|
|
33
|
+
console.log(json)
|
|
34
|
+
return json
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
20
38
|
return res
|
|
21
39
|
}
|
|
22
40
|
|
|
@@ -29,21 +47,40 @@ async function getSessionLocation()
|
|
|
29
47
|
return res
|
|
30
48
|
}
|
|
31
49
|
|
|
50
|
+
async function getAppDetails(app_id)
|
|
51
|
+
{
|
|
52
|
+
const res = await makeRequest({
|
|
53
|
+
url: "http://52.35.48.129:5000/data-source/get-data-source",
|
|
54
|
+
method: 'get',
|
|
55
|
+
params: `?type=saas&app_id=${app_id}`
|
|
56
|
+
})
|
|
57
|
+
return res
|
|
58
|
+
}
|
|
59
|
+
|
|
32
60
|
|
|
33
|
-
|
|
61
|
+
|
|
62
|
+
const startSession = async(app_id) =>{
|
|
34
63
|
let loc = await getSessionLocation()
|
|
64
|
+
console.log(loc)
|
|
65
|
+
data_source = await getAppDetails(app_id)
|
|
66
|
+
console.log(data_source)
|
|
67
|
+
|
|
35
68
|
let session = {
|
|
69
|
+
"topic":"session-data",
|
|
70
|
+
"data_source_id": data_source?.data_source_id,
|
|
36
71
|
"session_id": uuid.v4(),
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
72
|
+
"start_date": new Date(Date.now()).toDateString(),
|
|
73
|
+
"latitude": loc?.lat,
|
|
74
|
+
"longitude": loc?.lon,
|
|
75
|
+
"country": loc?.country,
|
|
76
|
+
"region": loc?.regionName,
|
|
77
|
+
"city": loc?.city,
|
|
78
|
+
"device": "getDeviceInfo",
|
|
40
79
|
}
|
|
41
|
-
session = { ...session, ...loc}
|
|
42
80
|
console.log(session)
|
|
43
81
|
|
|
44
|
-
streamData(
|
|
82
|
+
streamData(session)
|
|
45
83
|
|
|
46
84
|
return session
|
|
47
85
|
}
|
|
48
|
-
|
|
49
86
|
export default startSession
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
const { io} = require('socket.io-client');
|
|
2
|
-
const socket = io('http://
|
|
2
|
+
const socket = io('http://52.35.48.129:4000');
|
|
3
3
|
|
|
4
4
|
function streamData(data){
|
|
5
5
|
socket.emit('dataEvent', data);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export const targetReached = async(session_id) =>{
|
|
9
|
-
streamData({"topic":"
|
|
9
|
+
streamData({"topic":"update-session-data", "session_id" : session_id, "click_through": true })
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const registerClick = async(session_id, item_id) =>{
|
|
13
|
-
streamData({"topic":"
|
|
13
|
+
streamData({"topic":"update-session-data", "session_id" : session_id, "item_clicked": item_id })
|
|
14
14
|
}
|
|
15
15
|
|