-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
64 lines (54 loc) · 1.46 KB
/
app.ts
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
/**
* Basic NodeJS App, No Frameworks
*
* For server and middleware usage see [server.ts](./server.ts)
*/
import dotenv from 'dotenv';
import { amplitude, analytics, experiment, UserLoggedIn, Logger, User } from './amplitude'
import { getProductConfigurationFromEnv } from "@amplitude/util";
// Read Configuration
dotenv.config()
const userId = process.env.AMP_USER_ID || 'alpha-user-id-node';
const deviceId = process.env.AMP_DEVICE_ID || 'alpha-device-id-node';
amplitude.typed.load({
environment: 'production',
logger: new Logger(),
// Try reading in ApiKeys from .env file
...getProductConfigurationFromEnv(),
})
/**
* 1. Track with `userId`
*/
analytics.userId(userId).track(new UserLoggedIn({
method: "email"
}));
/**
* 2. Track with `deviceId`
*/
analytics.deviceId(deviceId).typed.userSignedUp();
/**
* 3. Track with `userProperties`
*/
const user = new User(userId);
user.typed.setUserProperties({
referralSource: 'other'
})
analytics.user(user).typed.checkout();
/**
* 4. Keep user scoped clients for multiple actions for the same user
*/
// create individual product clients for user
const userAnalytics = analytics.user(user);
const userExperiment = experiment.user(user);
if (userExperiment.typed.codegenBooleanExperiment().on) {
userAnalytics.typed.userSignedUp({
referralSource: "other"
})
userAnalytics.track(new UserLoggedIn({
method: "email"
}))
} else {
userAnalytics.track({
event_type: 'My Untyped Event'
})
}