-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
109 lines (95 loc) · 2.85 KB
/
index.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const users = require("./includes/users");
const sessionizedEvents = require("./includes/sessionized_events");
const sessions = require("./includes/sessions");
const pageEvents = require("./includes/page_events");
const sessionizedPages = require("./includes/sessionized_pages");
const trackEvents = require("./includes/track_events");
const sessionizedTracks = require("./includes/sessionized_tracks");
const screenEvents = require("./includes/screen_events");
const sessionizedScreens = require("./includes/sessionized_screens");
const userMap = require("./includes/user_map");
module.exports = (params) => {
params = {
segmentSchema: "javascript", // schema that Segment writes tables into
sessionTimeoutMillis: 30 * 60 * 1000, // Session timeout in milliseconds
customPageFields: [], // list of custom fields to extract from the pages table
customUserFields: [], // list of custom fields to extract from the identifies table
customTrackFields: [], // list of custom fields to extract from the tracks table
customScreenFields: [], // list of custom fields to extract from the tracks table
declareSources: true,
includeTracks: true,
includePages: true,
includeScreens: false,
...params
};
const {
defaultConfig,
segmentSchema,
declareSources,
includeTracks,
includePages,
includeScreens
} = params;
let identifies, pages, tracks, screens;
if (declareSources) {
identifies = declare({
...defaultConfig,
schema: segmentSchema,
name: "identifies"
});
if (includePages) {
pages = declare({
...defaultConfig,
schema: segmentSchema,
name: "pages"
});
}
if (includeTracks) {
tracks = declare({
...defaultConfig,
schema: segmentSchema,
name: "tracks"
});
}
if (includeScreens) {
screens = declare({
...defaultConfig,
schema: segmentSchema,
name: "screens"
});
}
}
// Publish and return datasets.
let result = {
identifies,
users: users(params),
sessionizedEvents: sessionizedEvents(params),
sessions: sessions(params),
userMap: userMap(params),
};
if (includePages) {
result = {
...result,
pages,
pageEvents: pageEvents(params),
sessionizedPages: sessionizedPages(params)
};
}
if (includeTracks) {
result = {
...result,
tracks,
trackEvents: trackEvents(params),
sessionizedTracks: sessionizedTracks(params)
};
}
if (includeScreens) {
result = {
...result,
screens,
screenEvents: screenEvents(params),
sessionizedScreens: sessionizedScreens(params)
};
}
return result;
}