@amplitude/analytics-node 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +152 -0
- package/lib/cjs/config.d.ts +7 -0
- package/lib/cjs/config.d.ts.map +1 -0
- package/lib/cjs/config.js +23 -0
- package/lib/cjs/config.js.map +1 -0
- package/lib/cjs/index.d.ts +4 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +19 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/node-client.d.ts +138 -0
- package/lib/cjs/node-client.d.ts.map +1 -0
- package/lib/cjs/node-client.js +175 -0
- package/lib/cjs/node-client.js.map +1 -0
- package/lib/cjs/plugins/context.d.ts +11 -0
- package/lib/cjs/plugins/context.d.ts.map +1 -0
- package/lib/cjs/plugins/context.js +29 -0
- package/lib/cjs/plugins/context.js.map +1 -0
- package/lib/cjs/transports/http.d.ts +6 -0
- package/lib/cjs/transports/http.d.ts.map +1 -0
- package/lib/cjs/transports/http.js +66 -0
- package/lib/cjs/transports/http.js.map +1 -0
- package/lib/cjs/version.d.ts +2 -0
- package/lib/cjs/version.d.ts.map +1 -0
- package/lib/cjs/version.js +4 -0
- package/lib/cjs/version.js.map +1 -0
- package/lib/esm/config.d.ts +7 -0
- package/lib/esm/config.d.ts.map +1 -0
- package/lib/esm/config.js +20 -0
- package/lib/esm/config.js.map +1 -0
- package/lib/esm/index.d.ts +4 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/node-client.d.ts +138 -0
- package/lib/esm/node-client.d.ts.map +1 -0
- package/lib/esm/node-client.js +173 -0
- package/lib/esm/node-client.js.map +1 -0
- package/lib/esm/plugins/context.d.ts +11 -0
- package/lib/esm/plugins/context.d.ts.map +1 -0
- package/lib/esm/plugins/context.js +27 -0
- package/lib/esm/plugins/context.js.map +1 -0
- package/lib/esm/transports/http.d.ts +6 -0
- package/lib/esm/transports/http.d.ts.map +1 -0
- package/lib/esm/transports/http.js +64 -0
- package/lib/esm/transports/http.js.map +1 -0
- package/lib/esm/version.d.ts +2 -0
- package/lib/esm/version.d.ts.map +1 -0
- package/lib/esm/version.js +2 -0
- package/lib/esm/version.js.map +1 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Amplitude Analytics
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://amplitude.com" target="_blank" align="center">
|
|
3
|
+
<img src="https://static.amplitude.com/lightning/46c85bfd91905de8047f1ee65c7c93d6fa9ee6ea/static/media/amplitude-logo-with-text.4fb9e463.svg" width="280">
|
|
4
|
+
</a>
|
|
5
|
+
<br />
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
# @amplitude/analytics-node
|
|
9
|
+
|
|
10
|
+
Official Amplitude SDK for Node.js (Beta)
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
To get started with using Amplitude Node.js SDK, install the package to your project via NPM.
|
|
15
|
+
|
|
16
|
+
### Using Node package
|
|
17
|
+
|
|
18
|
+
This package is published on NPM registry and is available to be installed using npm and yarn.
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
# npm
|
|
22
|
+
npm install @amplitude/analytics-node
|
|
23
|
+
|
|
24
|
+
# yarn
|
|
25
|
+
yarn add @amplitude/analytics-node
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Initializing SDK
|
|
31
|
+
|
|
32
|
+
Initialization is necessary before any instrumentation is done. The API key for your Amplitude project is required.
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
amplitude.init(API_KEY);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Tracking an Event
|
|
39
|
+
|
|
40
|
+
Events represent how users interact with your application. For example, "Button Clicked" may be an action you want to note.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { track } from '@amplitude/analytics-node';
|
|
44
|
+
|
|
45
|
+
// Track a basic event
|
|
46
|
+
track('Button Clicked');
|
|
47
|
+
|
|
48
|
+
// Track events with additional properties
|
|
49
|
+
const eventProperties = {
|
|
50
|
+
selectedColors: ['red', 'blue'],
|
|
51
|
+
};
|
|
52
|
+
track('Button Clicked', eventProperties);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### User Properties
|
|
56
|
+
|
|
57
|
+
User properties help you understand your users at the time they performed some action within your app such as their device details, their preferences, or language.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { Identify, identify } from '@amplitude/analytics-node';
|
|
61
|
+
|
|
62
|
+
const event = new Identify();
|
|
63
|
+
|
|
64
|
+
// sets the value of a user property
|
|
65
|
+
event.set('key1', 'value1');
|
|
66
|
+
|
|
67
|
+
// sets the value of a user property only once
|
|
68
|
+
event.setOnce('key1', 'value1');
|
|
69
|
+
|
|
70
|
+
// increments a user property by some numerical value.
|
|
71
|
+
event.add('value1', 10);
|
|
72
|
+
|
|
73
|
+
// pre inserts a value or values to a user property
|
|
74
|
+
event.preInsert('ab-tests', 'new-user-test');
|
|
75
|
+
|
|
76
|
+
// post inserts a value or values to a user property
|
|
77
|
+
event.postInsert('ab-tests', 'new-user-test');
|
|
78
|
+
|
|
79
|
+
// removes a value or values to a user property
|
|
80
|
+
event.remove('ab-tests', 'new-user-test')
|
|
81
|
+
|
|
82
|
+
// sends identify event
|
|
83
|
+
identify(event);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### prepend/append
|
|
87
|
+
|
|
88
|
+
* append will append a value or values to a user property array.
|
|
89
|
+
* prepend will prepend a value or values to a user property.
|
|
90
|
+
|
|
91
|
+
### User Groups
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { setGroup } from '@amplitude/analytics-node';
|
|
95
|
+
|
|
96
|
+
// set group with single group name
|
|
97
|
+
setGroup('orgId', '15');
|
|
98
|
+
|
|
99
|
+
// set group with multiple group names
|
|
100
|
+
setGroup('sport', ['soccer', 'tennis']);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Group Identify
|
|
104
|
+
|
|
105
|
+
This feature is only available to Growth and Enterprise customers who have purchased the [Accounts add-on](https://amplitude.zendesk.com/hc/en-us/articles/115001765532).
|
|
106
|
+
|
|
107
|
+
Use the Group Identify API to set or update properties of particular groups. However, these updates will only affect events going forward.
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { Identify, groupIdentify } from '@amplitude/analytics-node';
|
|
111
|
+
|
|
112
|
+
const groupType = 'plan';
|
|
113
|
+
const groupName = 'enterprise';
|
|
114
|
+
const event = new Identify()
|
|
115
|
+
event.set('key1', 'value1');
|
|
116
|
+
|
|
117
|
+
groupIdentify(groupType, groupName, identify);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Track Revenue
|
|
121
|
+
|
|
122
|
+
Revenue instances will store each revenue transaction and allow you to define several special revenue properties (such as 'revenueType', 'productIdentifier', etc.) that are used in Amplitude's Event Segmentation and Revenue LTV charts. These Revenue instance objects are then passed into `revenue` to send as revenue events to Amplitude. This allows us to automatically display data relevant to revenue in the platform. You can use this to track both in-app and non-in-app purchases.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { Revenue, revenue } from '@amplitude/analytics-node';
|
|
126
|
+
|
|
127
|
+
const event = new Revenue()
|
|
128
|
+
.setProductId('com.company.productId')
|
|
129
|
+
.setPrice(3.99)
|
|
130
|
+
.setQuantity(3);
|
|
131
|
+
|
|
132
|
+
revenue(event);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Callback
|
|
136
|
+
|
|
137
|
+
All asynchronous API are optionally awaitable through a specific Promise interface. This also serves as callback interface.
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// Using async/await
|
|
141
|
+
const results = await track('Button Clicked').promise;
|
|
142
|
+
result.event; // {...} (The final event object sent to Amplitude)
|
|
143
|
+
result.code; // 200 (The HTTP response status code of the request.
|
|
144
|
+
result.message; // "Event tracked successfully" (The response message)
|
|
145
|
+
|
|
146
|
+
// Using promises
|
|
147
|
+
track('Button Clicked').promise.then((result) => {
|
|
148
|
+
result.event; // {...} (The final event object sent to Amplitude)
|
|
149
|
+
result.code; // 200 (The HTTP response status code of the request.
|
|
150
|
+
result.message; // "Event tracked successfully" (The response message)
|
|
151
|
+
});
|
|
152
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NodeOptions, NodeConfig as INodeConfig } from '@amplitude/analytics-types';
|
|
2
|
+
import { Config } from '@amplitude/analytics-core';
|
|
3
|
+
export declare class NodeConfig extends Config implements INodeConfig {
|
|
4
|
+
constructor(apiKey: string, options?: NodeOptions);
|
|
5
|
+
}
|
|
6
|
+
export declare const useNodeConfig: (apiKey: string, overrides?: NodeOptions | undefined) => INodeConfig;
|
|
7
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAGnD,qBAAa,UAAW,SAAQ,MAAO,YAAW,WAAW;gBAC/C,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;CAWlD;AAED,eAAO,MAAM,aAAa,WAAY,MAAM,0CAA4B,WAEvE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.useNodeConfig = exports.NodeConfig = void 0;
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
5
|
+
var http_1 = require("./transports/http");
|
|
6
|
+
var NodeConfig = /** @class */ (function (_super) {
|
|
7
|
+
(0, tslib_1.__extends)(NodeConfig, _super);
|
|
8
|
+
function NodeConfig(apiKey, options) {
|
|
9
|
+
var _a;
|
|
10
|
+
var _this = this;
|
|
11
|
+
var storageProvider = options === null || options === void 0 ? void 0 : options.storageProvider;
|
|
12
|
+
var transportProvider = (_a = options === null || options === void 0 ? void 0 : options.transportProvider) !== null && _a !== void 0 ? _a : new http_1.Http();
|
|
13
|
+
_this = _super.call(this, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, options), { apiKey: apiKey, storageProvider: storageProvider, transportProvider: transportProvider })) || this;
|
|
14
|
+
return _this;
|
|
15
|
+
}
|
|
16
|
+
return NodeConfig;
|
|
17
|
+
}(analytics_core_1.Config));
|
|
18
|
+
exports.NodeConfig = NodeConfig;
|
|
19
|
+
var useNodeConfig = function (apiKey, overrides) {
|
|
20
|
+
return new NodeConfig(apiKey, overrides);
|
|
21
|
+
};
|
|
22
|
+
exports.useNodeConfig = useNodeConfig;
|
|
23
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";;;AACA,4DAAmD;AACnD,0CAAyC;AAEzC;IAAgC,2CAAM;IACpC,oBAAY,MAAc,EAAE,OAAqB;;QAAjD,iBAUC;QATC,IAAM,eAAe,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,CAAC;QACjD,IAAM,iBAAiB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,iBAAiB,mCAAI,IAAI,WAAI,EAAE,CAAC;QAEnE,QAAA,kEACK,OAAO,KACV,MAAM,QAAA,EACN,eAAe,iBAAA,EACf,iBAAiB,mBAAA,IACjB,SAAC;;IACL,CAAC;IACH,iBAAC;AAAD,CAAC,AAZD,CAAgC,uBAAM,GAYrC;AAZY,gCAAU;AAchB,IAAM,aAAa,GAAG,UAAC,MAAc,EAAE,SAAuB;IACnE,OAAO,IAAI,UAAU,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC3C,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB","sourcesContent":["import { NodeOptions, NodeConfig as INodeConfig } from '@amplitude/analytics-types';\nimport { Config } from '@amplitude/analytics-core';\nimport { Http } from './transports/http';\n\nexport class NodeConfig extends Config implements INodeConfig {\n constructor(apiKey: string, options?: NodeOptions) {\n const storageProvider = options?.storageProvider;\n const transportProvider = options?.transportProvider ?? new Http();\n\n super({\n ...options,\n apiKey,\n storageProvider,\n transportProvider,\n });\n }\n}\n\nexport const useNodeConfig = (apiKey: string, overrides?: NodeOptions): INodeConfig => {\n return new NodeConfig(apiKey, overrides);\n};\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { add, groupIdentify, identify, init, logEvent, remove, revenue, setGroup, setOptOut, track, flush, } from './node-client';
|
|
2
|
+
export { Revenue, Identify } from '@amplitude/analytics-core';
|
|
3
|
+
export * as Types from '@amplitude/analytics-types';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,QAAQ,EACR,SAAS,EACT,KAAK,EACL,KAAK,GACN,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,KAAK,MAAM,4BAA4B,CAAC"}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.Types = exports.Identify = exports.Revenue = exports.flush = exports.track = exports.setOptOut = exports.setGroup = exports.revenue = exports.remove = exports.logEvent = exports.init = exports.identify = exports.groupIdentify = exports.add = void 0;
|
|
3
|
+
var node_client_1 = require("./node-client");
|
|
4
|
+
Object.defineProperty(exports, "add", { enumerable: true, get: function () { return node_client_1.add; } });
|
|
5
|
+
Object.defineProperty(exports, "groupIdentify", { enumerable: true, get: function () { return node_client_1.groupIdentify; } });
|
|
6
|
+
Object.defineProperty(exports, "identify", { enumerable: true, get: function () { return node_client_1.identify; } });
|
|
7
|
+
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return node_client_1.init; } });
|
|
8
|
+
Object.defineProperty(exports, "logEvent", { enumerable: true, get: function () { return node_client_1.logEvent; } });
|
|
9
|
+
Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return node_client_1.remove; } });
|
|
10
|
+
Object.defineProperty(exports, "revenue", { enumerable: true, get: function () { return node_client_1.revenue; } });
|
|
11
|
+
Object.defineProperty(exports, "setGroup", { enumerable: true, get: function () { return node_client_1.setGroup; } });
|
|
12
|
+
Object.defineProperty(exports, "setOptOut", { enumerable: true, get: function () { return node_client_1.setOptOut; } });
|
|
13
|
+
Object.defineProperty(exports, "track", { enumerable: true, get: function () { return node_client_1.track; } });
|
|
14
|
+
Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return node_client_1.flush; } });
|
|
15
|
+
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
16
|
+
Object.defineProperty(exports, "Revenue", { enumerable: true, get: function () { return analytics_core_1.Revenue; } });
|
|
17
|
+
Object.defineProperty(exports, "Identify", { enumerable: true, get: function () { return analytics_core_1.Identify; } });
|
|
18
|
+
exports.Types = require("@amplitude/analytics-types");
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAAA,6CAYuB;AAXrB,kGAAA,GAAG,OAAA;AACH,4GAAA,aAAa,OAAA;AACb,uGAAA,QAAQ,OAAA;AACR,mGAAA,IAAI,OAAA;AACJ,uGAAA,QAAQ,OAAA;AACR,qGAAA,MAAM,OAAA;AACN,sGAAA,OAAO,OAAA;AACP,uGAAA,QAAQ,OAAA;AACR,wGAAA,SAAS,OAAA;AACT,oGAAA,KAAK,OAAA;AACL,oGAAA,KAAK,OAAA;AAEP,4DAA8D;AAArD,yGAAA,OAAO,OAAA;AAAE,0GAAA,QAAQ,OAAA;AAC1B,sDAAoD","sourcesContent":["export {\n add,\n groupIdentify,\n identify,\n init,\n logEvent,\n remove,\n revenue,\n setGroup,\n setOptOut,\n track,\n flush,\n} from './node-client';\nexport { Revenue, Identify } from '@amplitude/analytics-core';\nexport * as Types from '@amplitude/analytics-types';\n"]}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { AmplitudeCore } from '@amplitude/analytics-core';
|
|
2
|
+
import { NodeConfig, NodeOptions } from '@amplitude/analytics-types';
|
|
3
|
+
export declare class AmplitudeNode extends AmplitudeCore<NodeConfig> {
|
|
4
|
+
init(apiKey: string, options?: NodeOptions): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Initializes the Amplitude SDK with your apiKey and optional configurations.
|
|
8
|
+
* This method must be called before any other operations.
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* await init(API_KEY, USER_ID, options).promise;
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const init: (apiKey: string, options?: NodeOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
15
|
+
/**
|
|
16
|
+
* Adds a new plugin.
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const plugin = {...};
|
|
20
|
+
* add(plugin);
|
|
21
|
+
*
|
|
22
|
+
* // alternatively, this tracking method is awaitable
|
|
23
|
+
* await add(plugin).promise;
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const add: (plugin: import("@amplitude/analytics-types").Plugin) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
27
|
+
/**
|
|
28
|
+
* Removes a plugin.
|
|
29
|
+
*
|
|
30
|
+
* ```typescript
|
|
31
|
+
* remove('myPlugin');
|
|
32
|
+
*
|
|
33
|
+
* // alternatively, this tracking method is awaitable
|
|
34
|
+
* await remove('myPlugin').promise;
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const remove: (pluginName: string) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
38
|
+
/**
|
|
39
|
+
* Tracks user-defined event, with specified type, optional event properties and optional overwrites.
|
|
40
|
+
*
|
|
41
|
+
* ```typescript
|
|
42
|
+
* // event tracking with event type only
|
|
43
|
+
* track('Page Load');
|
|
44
|
+
*
|
|
45
|
+
* // event tracking with event type and additional event properties
|
|
46
|
+
* track('Page Load', { loadTime: 1000 });
|
|
47
|
+
*
|
|
48
|
+
* // event tracking with event type, additional event properties, and overwritten event options
|
|
49
|
+
* track('Page Load', { loadTime: 1000 }, { sessionId: -1 });
|
|
50
|
+
*
|
|
51
|
+
* // alternatively, this tracking method is awaitable
|
|
52
|
+
* const result = await track('Page Load').promise;
|
|
53
|
+
* console.log(result.event); // {...}
|
|
54
|
+
* console.log(result.code); // 200
|
|
55
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const track: (eventInput: string | import("@amplitude/analytics-types").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
59
|
+
/**
|
|
60
|
+
* Alias for track()
|
|
61
|
+
*/
|
|
62
|
+
export declare const logEvent: (eventInput: string | import("@amplitude/analytics-types").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
63
|
+
/**
|
|
64
|
+
* Sends an identify event containing user property operations
|
|
65
|
+
*
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const id = new Identify();
|
|
68
|
+
* id.set('colors', ['rose', 'gold']);
|
|
69
|
+
* identify(id);
|
|
70
|
+
*
|
|
71
|
+
* // alternatively, this tracking method is awaitable
|
|
72
|
+
* const result = await identify(id).promise;
|
|
73
|
+
* console.log(result.event); // {...}
|
|
74
|
+
* console.log(result.code); // 200
|
|
75
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare const identify: (identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
79
|
+
/**
|
|
80
|
+
* Sends a group identify event containing group property operations.
|
|
81
|
+
*
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const id = new Identify();
|
|
84
|
+
* id.set('skills', ['js', 'ts']);
|
|
85
|
+
* const groupType = 'org';
|
|
86
|
+
* const groupName = 'engineering';
|
|
87
|
+
* groupIdentify(groupType, groupName, id);
|
|
88
|
+
*
|
|
89
|
+
* // alternatively, this tracking method is awaitable
|
|
90
|
+
* const result = await groupIdentify(groupType, groupName, id).promise;
|
|
91
|
+
* console.log(result.event); // {...}
|
|
92
|
+
* console.log(result.code); // 200
|
|
93
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare const groupIdentify: (groupType: string, groupName: string | string[], identify: import("@amplitude/analytics-types").Identify, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
97
|
+
export declare const setGroup: (groupType: string, groupName: string | string[]) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
98
|
+
/**
|
|
99
|
+
* Sends a revenue event containing revenue property operations.
|
|
100
|
+
*
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const rev = new Revenue();
|
|
103
|
+
* rev.setRevenue(100);
|
|
104
|
+
* revenue(rev);
|
|
105
|
+
*
|
|
106
|
+
* // alternatively, this tracking method is awaitable
|
|
107
|
+
* const result = await revenue(rev).promise;
|
|
108
|
+
* console.log(result.event); // {...}
|
|
109
|
+
* console.log(result.code); // 200
|
|
110
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare const revenue: (revenue: import("@amplitude/analytics-types").Revenue, eventOptions?: import("@amplitude/analytics-types").EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<import("@amplitude/analytics-types").Result>>;
|
|
114
|
+
/**
|
|
115
|
+
* Sets a new optOut config value. This toggles event tracking on/off.
|
|
116
|
+
*
|
|
117
|
+
*```typescript
|
|
118
|
+
* // Stops tracking
|
|
119
|
+
* setOptOut(true);
|
|
120
|
+
*
|
|
121
|
+
* // Starts/resumes tracking
|
|
122
|
+
* setOptOut(false);
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare const setOptOut: (optOut: boolean) => void;
|
|
126
|
+
/**
|
|
127
|
+
* Flush and send all the events which haven't been sent.
|
|
128
|
+
*
|
|
129
|
+
*```typescript
|
|
130
|
+
* // Send all the unsent events
|
|
131
|
+
* flush();
|
|
132
|
+
*
|
|
133
|
+
* // alternatively, this tracking method is awaitable
|
|
134
|
+
* await flush().promise;
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare const flush: () => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
138
|
+
//# sourceMappingURL=node-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-client.d.ts","sourceRoot":"","sources":["../../src/node-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA8B,MAAM,2BAA2B,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAIrE,qBAAa,aAAc,SAAQ,aAAa,CAAC,UAAU,CAAC;IACpD,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;CAiBjD;AAID;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,4HAA0C,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,GAAG,8HAAyC,CAAC;AAE1D;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,6FAA4C,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,KAAK,sTAA2C,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,QAAQ,sTAA8C,CAAC;AAEpE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,uPAA8C,CAAC;AAEpE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,wSAAmD,CAAC;AAC9E,eAAO,MAAM,QAAQ,iKAA8C,CAAC;AAEpE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,OAAO,qPAA6C,CAAC;AAElE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,2BAAgC,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,2EAA2C,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.flush = exports.setOptOut = exports.revenue = exports.setGroup = exports.groupIdentify = exports.identify = exports.logEvent = exports.track = exports.remove = exports.add = exports.init = exports.AmplitudeNode = void 0;
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
5
|
+
var context_1 = require("./plugins/context");
|
|
6
|
+
var config_1 = require("./config");
|
|
7
|
+
var AmplitudeNode = /** @class */ (function (_super) {
|
|
8
|
+
(0, tslib_1.__extends)(AmplitudeNode, _super);
|
|
9
|
+
function AmplitudeNode() {
|
|
10
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
11
|
+
}
|
|
12
|
+
AmplitudeNode.prototype.init = function (apiKey, options) {
|
|
13
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
14
|
+
var nodeOptions;
|
|
15
|
+
return (0, tslib_1.__generator)(this, function (_a) {
|
|
16
|
+
switch (_a.label) {
|
|
17
|
+
case 0:
|
|
18
|
+
nodeOptions = (0, config_1.useNodeConfig)(apiKey, (0, tslib_1.__assign)({}, options));
|
|
19
|
+
return [4 /*yield*/, _super.prototype._init.call(this, nodeOptions)];
|
|
20
|
+
case 1:
|
|
21
|
+
_a.sent();
|
|
22
|
+
return [4 /*yield*/, this.add(new context_1.Context())];
|
|
23
|
+
case 2:
|
|
24
|
+
_a.sent();
|
|
25
|
+
return [4 /*yield*/, this.add(new analytics_core_1.Destination())];
|
|
26
|
+
case 3:
|
|
27
|
+
_a.sent();
|
|
28
|
+
// Set timeline ready for processing events
|
|
29
|
+
// Send existing events, which might be collected by track before init
|
|
30
|
+
this.timeline.isReady = true;
|
|
31
|
+
if (!this.config.optOut) {
|
|
32
|
+
this.timeline.scheduleApply(0);
|
|
33
|
+
}
|
|
34
|
+
return [2 /*return*/];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return AmplitudeNode;
|
|
40
|
+
}(analytics_core_1.AmplitudeCore));
|
|
41
|
+
exports.AmplitudeNode = AmplitudeNode;
|
|
42
|
+
var client = new AmplitudeNode();
|
|
43
|
+
/**
|
|
44
|
+
* Initializes the Amplitude SDK with your apiKey and optional configurations.
|
|
45
|
+
* This method must be called before any other operations.
|
|
46
|
+
*
|
|
47
|
+
* ```typescript
|
|
48
|
+
* await init(API_KEY, USER_ID, options).promise;
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
exports.init = (0, analytics_core_1.returnWrapper)(client.init.bind(client));
|
|
52
|
+
/**
|
|
53
|
+
* Adds a new plugin.
|
|
54
|
+
*
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const plugin = {...};
|
|
57
|
+
* add(plugin);
|
|
58
|
+
*
|
|
59
|
+
* // alternatively, this tracking method is awaitable
|
|
60
|
+
* await add(plugin).promise;
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
exports.add = (0, analytics_core_1.returnWrapper)(client.add.bind(client));
|
|
64
|
+
/**
|
|
65
|
+
* Removes a plugin.
|
|
66
|
+
*
|
|
67
|
+
* ```typescript
|
|
68
|
+
* remove('myPlugin');
|
|
69
|
+
*
|
|
70
|
+
* // alternatively, this tracking method is awaitable
|
|
71
|
+
* await remove('myPlugin').promise;
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
exports.remove = (0, analytics_core_1.returnWrapper)(client.remove.bind(client));
|
|
75
|
+
/**
|
|
76
|
+
* Tracks user-defined event, with specified type, optional event properties and optional overwrites.
|
|
77
|
+
*
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // event tracking with event type only
|
|
80
|
+
* track('Page Load');
|
|
81
|
+
*
|
|
82
|
+
* // event tracking with event type and additional event properties
|
|
83
|
+
* track('Page Load', { loadTime: 1000 });
|
|
84
|
+
*
|
|
85
|
+
* // event tracking with event type, additional event properties, and overwritten event options
|
|
86
|
+
* track('Page Load', { loadTime: 1000 }, { sessionId: -1 });
|
|
87
|
+
*
|
|
88
|
+
* // alternatively, this tracking method is awaitable
|
|
89
|
+
* const result = await track('Page Load').promise;
|
|
90
|
+
* console.log(result.event); // {...}
|
|
91
|
+
* console.log(result.code); // 200
|
|
92
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
exports.track = (0, analytics_core_1.returnWrapper)(client.track.bind(client));
|
|
96
|
+
/**
|
|
97
|
+
* Alias for track()
|
|
98
|
+
*/
|
|
99
|
+
exports.logEvent = (0, analytics_core_1.returnWrapper)(client.logEvent.bind(client));
|
|
100
|
+
/**
|
|
101
|
+
* Sends an identify event containing user property operations
|
|
102
|
+
*
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const id = new Identify();
|
|
105
|
+
* id.set('colors', ['rose', 'gold']);
|
|
106
|
+
* identify(id);
|
|
107
|
+
*
|
|
108
|
+
* // alternatively, this tracking method is awaitable
|
|
109
|
+
* const result = await identify(id).promise;
|
|
110
|
+
* console.log(result.event); // {...}
|
|
111
|
+
* console.log(result.code); // 200
|
|
112
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
exports.identify = (0, analytics_core_1.returnWrapper)(client.identify.bind(client));
|
|
116
|
+
/**
|
|
117
|
+
* Sends a group identify event containing group property operations.
|
|
118
|
+
*
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const id = new Identify();
|
|
121
|
+
* id.set('skills', ['js', 'ts']);
|
|
122
|
+
* const groupType = 'org';
|
|
123
|
+
* const groupName = 'engineering';
|
|
124
|
+
* groupIdentify(groupType, groupName, id);
|
|
125
|
+
*
|
|
126
|
+
* // alternatively, this tracking method is awaitable
|
|
127
|
+
* const result = await groupIdentify(groupType, groupName, id).promise;
|
|
128
|
+
* console.log(result.event); // {...}
|
|
129
|
+
* console.log(result.code); // 200
|
|
130
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
exports.groupIdentify = (0, analytics_core_1.returnWrapper)(client.groupIdentify.bind(client));
|
|
134
|
+
exports.setGroup = (0, analytics_core_1.returnWrapper)(client.setGroup.bind(client));
|
|
135
|
+
/**
|
|
136
|
+
* Sends a revenue event containing revenue property operations.
|
|
137
|
+
*
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const rev = new Revenue();
|
|
140
|
+
* rev.setRevenue(100);
|
|
141
|
+
* revenue(rev);
|
|
142
|
+
*
|
|
143
|
+
* // alternatively, this tracking method is awaitable
|
|
144
|
+
* const result = await revenue(rev).promise;
|
|
145
|
+
* console.log(result.event); // {...}
|
|
146
|
+
* console.log(result.code); // 200
|
|
147
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
exports.revenue = (0, analytics_core_1.returnWrapper)(client.revenue.bind(client));
|
|
151
|
+
/**
|
|
152
|
+
* Sets a new optOut config value. This toggles event tracking on/off.
|
|
153
|
+
*
|
|
154
|
+
*```typescript
|
|
155
|
+
* // Stops tracking
|
|
156
|
+
* setOptOut(true);
|
|
157
|
+
*
|
|
158
|
+
* // Starts/resumes tracking
|
|
159
|
+
* setOptOut(false);
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
exports.setOptOut = client.setOptOut.bind(client);
|
|
163
|
+
/**
|
|
164
|
+
* Flush and send all the events which haven't been sent.
|
|
165
|
+
*
|
|
166
|
+
*```typescript
|
|
167
|
+
* // Send all the unsent events
|
|
168
|
+
* flush();
|
|
169
|
+
*
|
|
170
|
+
* // alternatively, this tracking method is awaitable
|
|
171
|
+
* await flush().promise;
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
exports.flush = (0, analytics_core_1.returnWrapper)(client.flush.bind(client));
|
|
175
|
+
//# sourceMappingURL=node-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-client.js","sourceRoot":"","sources":["../../src/node-client.ts"],"names":[],"mappings":";;;AAAA,4DAAsF;AAEtF,6CAA4C;AAC5C,mCAAyC;AAEzC;IAAmC,8CAAyB;IAA5D;;IAkBA,CAAC;IAjBO,4BAAI,GAAV,UAAW,MAAc,EAAE,OAAqB;;;;;;wBACxC,WAAW,GAAG,IAAA,sBAAa,EAAC,MAAM,4BACnC,OAAO,EACV,CAAC;wBAEH,qBAAM,iBAAM,KAAK,YAAC,WAAW,CAAC,EAAA;;wBAA9B,SAA8B,CAAC;wBAE/B,qBAAM,IAAI,CAAC,GAAG,CAAC,IAAI,iBAAO,EAAE,CAAC,EAAA;;wBAA7B,SAA6B,CAAC;wBAC9B,qBAAM,IAAI,CAAC,GAAG,CAAC,IAAI,4BAAW,EAAE,CAAC,EAAA;;wBAAjC,SAAiC,CAAC;wBAElC,2CAA2C;wBAC3C,sEAAsE;wBACtE,IAAI,CAAC,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC;wBAC7B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;4BACvB,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;yBAChC;;;;;KACF;IACH,oBAAC;AAAD,CAAC,AAlBD,CAAmC,8BAAa,GAkB/C;AAlBY,sCAAa;AAoB1B,IAAM,MAAM,GAAG,IAAI,aAAa,EAAE,CAAC;AAEnC;;;;;;;GAOG;AACU,QAAA,IAAI,GAAG,IAAA,8BAAa,EAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAE5D;;;;;;;;;;GAUG;AACU,QAAA,GAAG,GAAG,IAAA,8BAAa,EAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAE1D;;;;;;;;;GASG;AACU,QAAA,MAAM,GAAG,IAAA,8BAAa,EAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;GAmBG;AACU,QAAA,KAAK,GAAG,IAAA,8BAAa,EAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAE9D;;GAEG;AACU,QAAA,QAAQ,GAAG,IAAA,8BAAa,EAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpE;;;;;;;;;;;;;;GAcG;AACU,QAAA,QAAQ,GAAG,IAAA,8BAAa,EAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpE;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,aAAa,GAAG,IAAA,8BAAa,EAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AACjE,QAAA,QAAQ,GAAG,IAAA,8BAAa,EAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpE;;;;;;;;;;;;;;GAcG;AACU,QAAA,OAAO,GAAG,IAAA,8BAAa,EAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AAElE;;;;;;;;;;GAUG;AACU,QAAA,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEvD;;;;;;;;;;GAUG;AACU,QAAA,KAAK,GAAG,IAAA,8BAAa,EAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import { AmplitudeCore, Destination, returnWrapper } from '@amplitude/analytics-core';\nimport { NodeConfig, NodeOptions } from '@amplitude/analytics-types';\nimport { Context } from './plugins/context';\nimport { useNodeConfig } from './config';\n\nexport class AmplitudeNode extends AmplitudeCore<NodeConfig> {\n async init(apiKey: string, options?: NodeOptions) {\n const nodeOptions = useNodeConfig(apiKey, {\n ...options,\n });\n\n await super._init(nodeOptions);\n\n await this.add(new Context());\n await this.add(new Destination());\n\n // Set timeline ready for processing events\n // Send existing events, which might be collected by track before init\n this.timeline.isReady = true;\n if (!this.config.optOut) {\n this.timeline.scheduleApply(0);\n }\n }\n}\n\nconst client = new AmplitudeNode();\n\n/**\n * Initializes the Amplitude SDK with your apiKey and optional configurations.\n * This method must be called before any other operations.\n *\n * ```typescript\n * await init(API_KEY, USER_ID, options).promise;\n * ```\n */\nexport const init = returnWrapper(client.init.bind(client));\n\n/**\n * Adds a new plugin.\n *\n * ```typescript\n * const plugin = {...};\n * add(plugin);\n *\n * // alternatively, this tracking method is awaitable\n * await add(plugin).promise;\n * ```\n */\nexport const add = returnWrapper(client.add.bind(client));\n\n/**\n * Removes a plugin.\n *\n * ```typescript\n * remove('myPlugin');\n *\n * // alternatively, this tracking method is awaitable\n * await remove('myPlugin').promise;\n * ```\n */\nexport const remove = returnWrapper(client.remove.bind(client));\n\n/**\n * Tracks user-defined event, with specified type, optional event properties and optional overwrites.\n *\n * ```typescript\n * // event tracking with event type only\n * track('Page Load');\n *\n * // event tracking with event type and additional event properties\n * track('Page Load', { loadTime: 1000 });\n *\n * // event tracking with event type, additional event properties, and overwritten event options\n * track('Page Load', { loadTime: 1000 }, { sessionId: -1 });\n *\n * // alternatively, this tracking method is awaitable\n * const result = await track('Page Load').promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const track = returnWrapper(client.track.bind(client));\n\n/**\n * Alias for track()\n */\nexport const logEvent = returnWrapper(client.logEvent.bind(client));\n\n/**\n * Sends an identify event containing user property operations\n *\n * ```typescript\n * const id = new Identify();\n * id.set('colors', ['rose', 'gold']);\n * identify(id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await identify(id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const identify = returnWrapper(client.identify.bind(client));\n\n/**\n * Sends a group identify event containing group property operations.\n *\n * ```typescript\n * const id = new Identify();\n * id.set('skills', ['js', 'ts']);\n * const groupType = 'org';\n * const groupName = 'engineering';\n * groupIdentify(groupType, groupName, id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await groupIdentify(groupType, groupName, id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const groupIdentify = returnWrapper(client.groupIdentify.bind(client));\nexport const setGroup = returnWrapper(client.setGroup.bind(client));\n\n/**\n * Sends a revenue event containing revenue property operations.\n *\n * ```typescript\n * const rev = new Revenue();\n * rev.setRevenue(100);\n * revenue(rev);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await revenue(rev).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const revenue = returnWrapper(client.revenue.bind(client));\n\n/**\n * Sets a new optOut config value. This toggles event tracking on/off.\n *\n *```typescript\n * // Stops tracking\n * setOptOut(true);\n *\n * // Starts/resumes tracking\n * setOptOut(false);\n * ```\n */\nexport const setOptOut = client.setOptOut.bind(client);\n\n/**\n * Flush and send all the events which haven't been sent.\n *\n *```typescript\n * // Send all the unsent events\n * flush();\n *\n * // alternatively, this tracking method is awaitable\n * await flush().promise;\n * ```\n */\nexport const flush = returnWrapper(client.flush.bind(client));\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BeforePlugin, NodeConfig, Event, PluginType } from '@amplitude/analytics-types';
|
|
2
|
+
export declare class Context implements BeforePlugin {
|
|
3
|
+
name: string;
|
|
4
|
+
type: PluginType.BEFORE;
|
|
5
|
+
config: NodeConfig;
|
|
6
|
+
eventId: number;
|
|
7
|
+
library: string;
|
|
8
|
+
setup(config: NodeConfig): Promise<undefined>;
|
|
9
|
+
execute(context: Event): Promise<Event>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/plugins/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAIzF,qBAAa,OAAQ,YAAW,YAAY;IAC1C,IAAI,SAAa;IACjB,IAAI,oBAA8B;IAKlC,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,SAAK;IACZ,OAAO,SAAkC;IAEzC,KAAK,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IAK7C,OAAO,CAAC,OAAO,EAAE,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;CAexC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.Context = void 0;
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var analytics_types_1 = require("@amplitude/analytics-types");
|
|
5
|
+
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
6
|
+
var version_1 = require("../version");
|
|
7
|
+
var Context = /** @class */ (function () {
|
|
8
|
+
function Context() {
|
|
9
|
+
this.name = 'context';
|
|
10
|
+
this.type = analytics_types_1.PluginType.BEFORE;
|
|
11
|
+
this.eventId = 0;
|
|
12
|
+
this.library = "amplitude-node-ts/".concat(version_1.VERSION);
|
|
13
|
+
}
|
|
14
|
+
Context.prototype.setup = function (config) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
return Promise.resolve(undefined);
|
|
17
|
+
};
|
|
18
|
+
Context.prototype.execute = function (context) {
|
|
19
|
+
var _this = this;
|
|
20
|
+
return new Promise(function (resolve) {
|
|
21
|
+
var time = new Date().getTime();
|
|
22
|
+
var contextEvent = (0, tslib_1.__assign)((0, tslib_1.__assign)({ time: time, insert_id: (0, analytics_core_1.UUID)(), plan: _this.config.plan }, context), { event_id: _this.eventId++, library: _this.library });
|
|
23
|
+
return resolve(contextEvent);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return Context;
|
|
27
|
+
}());
|
|
28
|
+
exports.Context = Context;
|
|
29
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/plugins/context.ts"],"names":[],"mappings":";;;AAAA,8DAAyF;AACzF,4DAAiD;AACjD,sCAAqC;AAErC;IAAA;QACE,SAAI,GAAG,SAAS,CAAC;QACjB,SAAI,GAAG,4BAAU,CAAC,MAAe,CAAC;QAMlC,YAAO,GAAG,CAAC,CAAC;QACZ,YAAO,GAAG,4BAAqB,iBAAO,CAAE,CAAC;IAsB3C,CAAC;IApBC,uBAAK,GAAL,UAAM,MAAkB;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,yBAAO,GAAP,UAAQ,OAAc;QAAtB,iBAcC;QAbC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO;YACzB,IAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;YAElC,IAAM,YAAY,iDAChB,IAAI,MAAA,EACJ,SAAS,EAAE,IAAA,qBAAI,GAAE,EACjB,IAAI,EAAE,KAAI,CAAC,MAAM,CAAC,IAAI,IACnB,OAAO,KACV,QAAQ,EAAE,KAAI,CAAC,OAAO,EAAE,EACxB,OAAO,EAAE,KAAI,CAAC,OAAO,GACtB,CAAC;YACF,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IACH,cAAC;AAAD,CAAC,AA/BD,IA+BC;AA/BY,0BAAO","sourcesContent":["import { BeforePlugin, NodeConfig, Event, PluginType } from '@amplitude/analytics-types';\nimport { UUID } from '@amplitude/analytics-core';\nimport { VERSION } from '../version';\n\nexport class Context implements BeforePlugin {\n name = 'context';\n type = PluginType.BEFORE as const;\n\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: NodeConfig;\n eventId = 0;\n library = `amplitude-node-ts/${VERSION}`;\n\n setup(config: NodeConfig): Promise<undefined> {\n this.config = config;\n return Promise.resolve(undefined);\n }\n\n execute(context: Event): Promise<Event> {\n return new Promise((resolve) => {\n const time = new Date().getTime();\n\n const contextEvent: Event = {\n time,\n insert_id: UUID(),\n plan: this.config.plan,\n ...context,\n event_id: this.eventId++,\n library: this.library,\n };\n return resolve(contextEvent);\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Payload, Response, Transport } from '@amplitude/analytics-types';
|
|
2
|
+
import { BaseTransport } from '@amplitude/analytics-core';
|
|
3
|
+
export declare class Http extends BaseTransport implements Transport {
|
|
4
|
+
send(serverUrl: string, payload: Payload): Promise<Response | null>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/transports/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAI1D,qBAAa,IAAK,SAAQ,aAAc,YAAW,SAAS;IAC1D,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAiDpE"}
|