-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalytics_resthook_function.js
68 lines (64 loc) · 1.59 KB
/
analytics_resthook_function.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Please do not delete [used for Intellisense]
* @param {ServerRequest} request The incoming webhook request
* @param {Object.<string, any>} settings Custom settings
* @return void
*/
async function onRequest(request, settings) {
let eventBody = request.json();
let userId = '';
let sessionId = '';
if (!!eventBody.properties.user_id) {
userId = eventBody.properties.user_id.toString();
sessionId = eventBody.properties.session_id;
} else {
sessionId = eventBody.properties.session_id;
}
switch (eventBody.name) {
case 'content_view':
eventFriendlyName = 'Content View';
break;
case 'profile_view':
eventFriendlyName = 'Profile View';
break;
case 'channel_view':
eventFriendlyName = 'Channel View';
break;
case 'room_view':
eventFriendlyName = 'Room View';
break;
case 'follow':
eventFriendlyName = 'Follow';
break;
case 'sign_in':
eventFriendlyName = 'Sign In';
break;
case 'course_landed':
eventFriendlyName = 'Course Landed';
break;
case 'course_content:viewed':
eventFriendlyName = 'Course Content View';
break;
case 'course_content:access_denied':
eventFriendlyName = 'Course Content Access Denied';
break;
case 'ip_authentication:new_session':
eventFriendlyName = 'Sign In - IP Authentication';
break;
default:
eventFriendlyName = eventBody.name;
}
Segment.identify({
userId: userId,
anonymousId: sessionId,
traits: {
name: eventBody.properties.user
}
});
Segment.track({
event: eventFriendlyName,
userId: userId,
anonymousId: sessionId,
properties: { ...eventBody.properties }
});
}