7
7
Log a single action to Moesif.
8
8
Actions represent events that occur within your application at a specific point in time. They can be tracked within your UI (such as "User Clicked Sign Up") or from your backend (such as "SMS Job Finished"). Each action consists of a required _ Action Name_ and optional _ Metadata_ .
9
9
10
- <aside class =" warning " >
11
- Actions can be tracked from your frontend app using moesif-browser-js or directly from your backend using this API.
12
- </aside >
13
-
14
- ** An example tracking actions using moesif-browser-js:**
10
+ <aside class =" notice " >
15
11
16
- <div class =" center-column " ></div >
17
- ``` javascript
18
- var moesif = require (' moesif-browser-js' );
19
-
20
- moesif .init ({
21
- applicationId: ' YOUR_COLLECTOR_APPLICATION_ID'
22
- });
12
+ Actions can be tracked from your frontend app using <code >moesif-browser-js</code > or directly from your backend using this API. You can also use
13
+ <a href =" https://github.com/Moesif/moesifapi-nodejs " >Moesif API library for Node.js</a > and
14
+ <a href =" https://github.com/Moesif/moesif-nodejs " >Moesif Node.js middleware</a >.
23
15
24
- // The first argument (required) contains the action name string.
25
- // The second argument (optional) contains event metadata.
26
- moesif .track (' Clicked Sign Up' , {
27
- button_label: ' Get Started' ,
28
- sign_up_method: ' Google SSO'
29
- });
30
- ```
31
- </pre >
16
+ </aside >
32
17
33
18
<aside class =" info " >
34
19
Replace <i >YOUR_COLLECTOR_APPLICATION_ID</i > with your real Application Id
@@ -79,6 +64,35 @@ moesif.track('Clicked Sign Up', {
79
64
});
80
65
```
81
66
67
+ ``` javascript--nodejs
68
+ var moesifapi = require('moesifapi');
69
+ var apiClient = moesifapi.ApiController;
70
+
71
+ moesifapi.configuration.ApplicationId = "YOUR_COLLECTOR_APPLICATION_ID";
72
+
73
+ var action = {
74
+ transactionId: "a3765025-46ec-45dd-bc83-b136c8d1d257",
75
+ actionName: "Clicked Sign Up",
76
+ sessionToken: "23jdf0owekfmcn4u3qypxg08w4d8ayrcdx8nu2nz]s98y18cx98q3yhwmnhcfx43f",
77
+ userId: "12345",
78
+ companyId: "67890",
79
+ metadata: {
80
+
81
+ button_label: 'Get Started',
82
+ sign_up_method: 'Google SSO'
83
+ },
84
+ request: {
85
+ time: new Date(),
86
+ uri: "https://api.acmeinc.com/items/reviews/",
87
+ ipAddress: "61.48.220.123",
88
+ }
89
+ };
90
+ // Send the Action
91
+ apiClient.sendAction(new moesifapi.ActionModel(action), function(error, response, context) {
92
+ // Do Something
93
+ });
94
+ ```
95
+
82
96
| Name| Type| Required| Description|
83
97
| -----------| -----------| -----------| -----------|
84
98
transaction_id | string | false | A random 36 char UUID for this event. If set, Moesif will deduplicate events using this id and ensure idempotency.
@@ -104,28 +118,14 @@ Actions represent events that occur within your application at a specific point
104
118
This API accepts an array of actions as the payload
105
119
The maximum batch size is ** 15MB** . Break up larger batches into smaller batches.
106
120
107
- <aside class =" warning " >
108
- Actions can be tracked from your frontend app using moesif-browser-js or directly from your backend using this API.
109
- </aside >
110
-
111
- ** An example tracking actions using moesif-browser-js:**
121
+ <aside class =" notice " >
112
122
113
- <div class =" center-column " ></div >
114
- ``` javascript
115
- var moesif = require (' moesif-browser-js' );
116
-
117
- moesif .init ({
118
- applicationId: ' YOUR_COLLECTOR_APPLICATION_ID'
119
- });
123
+ Actions can be tracked from your frontend app using <code >moesif-browser-js</code >
124
+ or directly from your backend using this API. You can also use
125
+ <a href =" https://github.com/Moesif/moesifapi-nodejs " >Moesif API library for Node.js</a > and
126
+ <a href =" https://github.com/Moesif/moesif-nodejs " >Moesif Node.js middleware</a >.
120
127
121
- // The first argument (required) contains the action name string.
122
- // The second argument (optional) contains event metadata.
123
- moesif .track (' Clicked Sign Up' , {
124
- button_label: ' Get Started' ,
125
- sign_up_method: ' Google SSO'
126
- });
127
- ```
128
- </pre >
128
+ </aside >
129
129
130
130
<aside class =" info " >
131
131
Replace <i >YOUR_COLLECTOR_APPLICATION_ID</i > with your real Application Id
@@ -192,6 +192,66 @@ moesif.track('Clicked Sign Up', {
192
192
});
193
193
```
194
194
195
+ ``` javascript--nodejs
196
+ var moesifapi = require('moesifapi');
197
+ var apiClient = moesifapi.ApiController;
198
+
199
+ moesifapi.configuration.ApplicationId = "YOUR_COLLECTOR_APPLICATION_ID";
200
+
201
+ // Define the request context objects for each action.
202
+ var req_contextA = {
203
+ time: new Date(),
204
+ uri: "https://api.acmeinc.com/items/reviews/",
205
+ ipAddress: "61.48.220.123",
206
+ userAgentString: "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"
207
+ };
208
+
209
+ var req_contextB = {
210
+ time: new Date(),
211
+ uri: "https://api.acmeinc.com/pricing/",
212
+ ipAddress: "61.48.220.126",
213
+ userAgentString: "PostmanRuntime/7.26.5"
214
+ };
215
+
216
+ // Define the actions.
217
+ var actionA = {
218
+ transactionId: "a3765025-46ec-45dd-bc83-b136a8d1d357",
219
+ actionName: "Clicked Sign Up",
220
+ sessionToken: "23abf0owekfmcn4u3qypxg09w4d8ayrcdx8nu2ng]s98y18cx98q3yhwmnhcfx43f",
221
+ userId: "18340",
222
+ companyId: "25100",
223
+ metadata: {
224
+
225
+ button_label: 'Get Started',
226
+ sign_up_method: 'Google SSO'
227
+ },
228
+ request: req_contextA
229
+ };
230
+
231
+ var actionB = {
232
+ transactionId: "a3765024-46ee-45dd-bc83-b136c8d1d250",
233
+ actionName: "Viewed pricing",
234
+ sessionToken: "23jdf0owejfmbn4u3qypxg09w4d8ayrxdx8nu2ng]s98y18cx98q3yhwmnhcfx43f",
235
+ userId: "12390",
236
+ companyId: "97895",
237
+ metadata: {
238
+
239
+ button_label: 'See pricing',
240
+ sign_up_method: 'Google SSO'
241
+ },
242
+ request: req_contextB
243
+ };
244
+
245
+ var actions = [
246
+ new moesifapi.ActionModel(actionA),
247
+ new moesifapi.ActionModel(actionB)
248
+ ];
249
+ // Send the batch of Actions
250
+ apiClient.sendActionsBatch(actions, function(error, response, context) {
251
+ // Do Something
252
+ });
253
+ ```
254
+
195
255
| Name| Type| Required| Description|
196
256
| -----------| -----------| -----------| -----------|
197
257
transaction_id | string | false | A random 36 char UUID for this event. If set, Moesif will deduplicate events using this id and ensure idempotency. Moesif will still deduplicate even across different size batches.
0 commit comments