22
33// From here: https://segment.com/docs/connections/spec/page/
44let PAGE_FIELDS = {
5- url : "url" ,
6- referrer : "referrer" ,
7- title : "title" ,
8- name : "name" ,
9- search : "search" ,
10- path : "path" ,
11- context_campaign_content : "utm_content" ,
12- context_campaign_medium : "utm_medium" ,
13- context_campaign_source : "utm_source" ,
14- context_campaign_name : "utm_campaign" ,
15- context_campaign_term : "utm_term" } ;
5+ url : "url" ,
6+ referrer : "referrer" ,
7+ title : "title" ,
8+ name : "name" ,
9+ search : "search" ,
10+ path : "path" ,
11+ context_campaign_content : "utm_content" ,
12+ context_campaign_medium : "utm_medium" ,
13+ context_campaign_source : "utm_source" ,
14+ context_campaign_name : "utm_campaign" ,
15+ context_campaign_term : "utm_term"
16+ } ;
1617
1718// From here: https://segment.com/docs/connections/spec/track/
1819let TRACK_FIELDS = {
1920 event : "event"
2021} ;
2122
23+ // From here: https://segment.com/docs/connections/spec/screen/
24+ let SCREEN_FIELDS = {
25+ event : "name"
26+ } ;
27+
28+ function allPageFields ( params ) {
29+ const customPageFieldsObj = params . customPageFields . reduce ( ( acc , item ) => ( {
30+ ...acc ,
31+ [ item ] : item
32+ } ) , { } ) ;
33+ return {
34+ ...PAGE_FIELDS ,
35+ ...customPageFieldsObj
36+ } ;
37+ }
38+
39+ function allTrackFields ( params ) {
40+ const customTrackFieldsObj = params . customTrackFields . reduce ( ( acc , item ) => ( {
41+ ...acc ,
42+ [ item ] : item
43+ } ) , { } ) ;
44+ return {
45+ ...TRACK_FIELDS ,
46+ ...customTrackFieldsObj
47+ } ;
48+ }
49+
50+ function allScreenFields ( params ) {
51+ const customScreenFieldsObj = params . customScreenFields . reduce ( ( acc , item ) => ( {
52+ ...acc ,
53+ [ item ] : item
54+ } ) , { } ) ;
55+ return {
56+ ...SCREEN_FIELDS ,
57+ ...customScreenFieldsObj
58+ } ;
59+ }
60+
61+ function enabledEvents ( params ) {
62+ const events = [ ] ;
63+
64+ if ( params . includeTracks ) {
65+ events . push ( "track" ) ;
66+ }
67+ if ( params . includePages ) {
68+ events . push ( "page" ) ;
69+ }
70+ if ( params . includeScreens ) {
71+ events . push ( "screen" ) ;
72+ }
73+
74+ return events ;
75+ }
76+
2277module . exports = {
23- PAGE_FIELDS ,
24- TRACK_FIELDS
25- }
78+ allTrackFields,
79+ allPageFields,
80+ allScreenFields,
81+ enabledEvents
82+ }
0 commit comments