-
Notifications
You must be signed in to change notification settings - Fork 11
/
init-ampli.ts
70 lines (59 loc) · 1.67 KB
/
init-ampli.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
65
66
67
68
69
70
import { ampli, DefaultOptions } from "./ampli";
import loggingMiddleware from "./middleware/loggingMiddleware";
import { init as initNodeClient } from '@amplitude/node';
import { LogLevel } from '@amplitude/types';
const AMPLITUDE_API_KEY = process.env.NEXT_PUBLIC_AMPLITUDE_API_KEY;
/**
* Start by calling ampli.load()
*
* 'ampli' is the default instance of Ampli()
*/
/**
* When you pull your tracking plan you can use the defaults and call load() without arguments
*
* This requires connecting your account via `ampli pull`
* which will set you API key in the generated Ampli SDK
*/
// ampli.load();
/**
* OR Specify an environment
*/
// ampli.load({ environment: 'development' })
/**
* OR Use an existing Amplitude instance
* requires "import { init as initNodeClient } from '@amplitude/node';"
*/
// const instance = initNodeClient(AMPLITUDE_API_KEY!, { ...DefaultOptions, logLevel: LogLevel.Verbose });
// ampli.load({ client: { instance } });
/**
* OR Specify AmplitudeClient 'config'
*/
ampli.load({
client: {
apiKey: AMPLITUDE_API_KEY,
}
})
/**
* For testing you can disable ampli
*/
// ampli.load({
// disabled: process.env.IS_TESTING ? true : false,
// });
/**
* Make as many Ampli instances as you want
*/
// const ampli2 = new Ampli();
// ampli2.load({ client: { apiKey: 'api-key-2' } });
/**
* Middleware can be used for many things including
* logging, filtering, event modification and more.
*/
/**
* Logging
*/
ampli.client.addEventMiddleware(loggingMiddleware);
/**
* Middleware can also modify the event stream
* Adding stop middleware will prevent events from going to Amplitude
*/
// ampli.client.addEventMiddleware(stopMiddleware);