Uh oh!
There was an error while loading. Please reload this page.
forked from segmentio/analytics-node
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
Latest commit
executable file
·123 lines (110 loc) · 2.84 KB
/
Copy pathcli.js
File metadata and controls
executable file
·123 lines (110 loc) · 2.84 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env node
'use strict'
constprogram=require('commander')
constAnalytics=require('.')
constpkg=require('./package')
consttoObject=str=>JSON.parse(str)
program
.version(pkg.version)
.option('-w, --writeKey <key>','the Filum write key to use')
.option('-h, --host <host>','the Filum API hostname to use')
.option('-t, --type <type>','the Filum message type')
.option('-u, --userId <id>','the user id to send the event as')
.option('-a, --anonymousId <id>','the anonymous user id to send the event as')
.option('-c, --context <context>','additional context for the event (JSON-encoded)',toObject)
.option('-i, --integrations <integrations>','additional integrations for the event (JSON-encoded)',toObject)
.option('-e, --event <event>','the event name to send with the event')
.option('-p, --properties <properties>','the event properties to send (JSON-encoded)',toObject)
.option('-n, --name <name>','name of the screen or page to send with the message')
.option('-t, --traits <traits>','the identify/group traits to send (JSON-encoded)',toObject)
.option('-g, --groupId <groupId>','the group id')
.option('-pid, --previousId <previousId>','the previous id')
.parse(process.argv)
if(program.args.length!==0){
program.help()
}
constwriteKey=program.writeKey
consthost=program.host
consttype=program.type
constuserId=program.userId
constanonymousId=program.anonymousId
constcontext=program.context
constintegrations=program.integrations
constevent=program.event
constproperties=program.properties
constname=program.name
consttraits=program.traits
constgroupId=program.groupId
constpreviousId=program.previousId
construn=(method,args)=>{
constanalytics=newAnalytics(writeKey,{ host,flushAt: 1})
analytics[method](args,err=>{
if(err){
console.error(err.stack)
process.exit(1)
}
})
}
switch(type){
case'track':
run('track',{
event,
properties,
userId,
anonymousId,
context,
integrations
})
break
case'page':
run('page',{
name,
properties,
userId,
anonymousId,
context,
integrations
})
break
case'screen':
run('screen',{
name,
properties,
userId,
anonymousId,
context,
integrations
})
break
case'identify':
run('identify',{
traits,
userId,
anonymousId,
context,
integrations
})
break
case'group':
run('group',{
groupId,
traits,
userId,
anonymousId,
context,
integrations
})
break
case'alias':
run('alias',{
previousId,
userId,
anonymousId,
context,
integrations
})
break
default:
console.error('invalid type:',type)
process.exit(1)
}