forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics-node-tests.ts
More file actions
89 lines (80 loc) · 2.03 KB
/
Copy pathanalytics-node-tests.ts
File metadata and controls
89 lines (80 loc) · 2.03 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
import Analytics = require("analytics-node");
var analytics: Analytics;
function testConfig(): void {
analytics = new Analytics('YOUR_WRITE_KEY', {
flushAt: 20,
flushAfter: 10000
});
}
function testIdentify(): void {
analytics.identify({
userId: '019mr8mf4r',
traits: {
name: 'Michael Bolton',
email: 'mbolton@initech.com',
plan: 'Enterprise',
friends: 42
}
});
}
function testTrack(): void {
analytics.track({
userId: '019mr8mf4r',
event: 'Purchased an Item',
properties: {
revenue: 39.95,
shippingMethod: '2-day'
}
});
}
function testPage(): void {
analytics.page({
userId: '019mr8mf4r',
category: 'Docs',
name: 'Node.js Library',
properties: {
url: 'https://segment.com/docs/libraries/node',
path: '/docs/libraries/node/',
title: 'Node.js Library - Segment',
referrer: 'https://github.com/segmentio/analytics-node'
}
});
}
function testAlias(): void {
// the anonymous user does actions ...
analytics.track({ userId: 'anonymous_user', event: 'Anonymous Event' })
// the anonymous user signs up and is aliased
analytics.alias({ previousId: 'anonymous_user', userId: 'identified@gmail.com' })
// the identified user is identified
analytics.identify({ userId: 'identified@gmail.com', traits: { plan: 'Free' } })
// the identified user does actions ...
analytics.track({ userId: 'identified@gmail.com', event: 'Identified Action' })
}
function testGroup(): void {
analytics.group({
userId: '019mr8mf4r',
groupId: '56',
traits: {
name: 'Initech',
description: 'Accounting Software'
}
});
}
function testIntegrations(): void {
analytics.track({
event: 'Upgraded Membershipt',
userId: '97234974',
integrations: {
'All': false,
'Vero': true,
'Google Analytics': false
}
});
}
function testFlush(): void {
analytics.flush();
analytics.flush(function(err, batch) {
if (err) { alert("Oh nos!"); }
else { console.log(batch.batch[0].type); }
});
}