Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add actions docs for nodejs #71

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 100 additions & 40 deletions source/includes/collector-api/_actions-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,13 @@
Log a single action to Moesif.
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_.

<aside class="warning">
Actions can be tracked from your frontend app using moesif-browser-js or directly from your backend using this API.
</aside>

**An example tracking actions using moesif-browser-js:**
<aside class="notice">

<div class="center-column"></div>
```javascript
var moesif = require('moesif-browser-js');

moesif.init({
applicationId: 'YOUR_COLLECTOR_APPLICATION_ID'
});
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
<a href="https://github.com/Moesif/moesifapi-nodejs">Moesif API library for Node.js</a> and
<a href="https://github.com/Moesif/moesif-nodejs">Moesif Node.js middleware</a>.

// The first argument (required) contains the action name string.
// The second argument (optional) contains event metadata.
moesif.track('Clicked Sign Up', {
button_label: 'Get Started',
sign_up_method: 'Google SSO'
});
```
</pre>
</aside>

<aside class="info">
Replace <i>YOUR_COLLECTOR_APPLICATION_ID</i> with your real Application Id
Expand Down Expand Up @@ -79,6 +64,35 @@ moesif.track('Clicked Sign Up', {
});
```

```javascript--nodejs
var moesifapi = require('moesifapi');
var apiClient = moesifapi.ApiController;

moesifapi.configuration.ApplicationId = "YOUR_COLLECTOR_APPLICATION_ID";

var action = {
transactionId: "a3765025-46ec-45dd-bc83-b136c8d1d257",
actionName: "Clicked Sign Up",
sessionToken: "23jdf0owekfmcn4u3qypxg08w4d8ayrcdx8nu2nz]s98y18cx98q3yhwmnhcfx43f",
userId: "12345",
companyId: "67890",
metadata: {
email: "[email protected]",
button_label: 'Get Started',
sign_up_method: 'Google SSO'
},
request: {
time: new Date(),
uri: "https://api.acmeinc.com/items/reviews/",
ipAddress: "61.48.220.123",
}
};
// Send the Action
apiClient.sendAction(new moesifapi.ActionModel(action), function(error, response, context) {
// Do Something
});
```

|Name|Type|Required|Description|
|-----------|-----------|-----------|-----------|
transaction_id | string | false | A random 36 char UUID for this event. If set, Moesif will deduplicate events using this id and ensure idempotency.
Expand All @@ -104,28 +118,14 @@ Actions represent events that occur within your application at a specific point
This API accepts an array of actions as the payload
The maximum batch size is **15MB**. Break up larger batches into smaller batches.

<aside class="warning">
Actions can be tracked from your frontend app using moesif-browser-js or directly from your backend using this API.
</aside>

**An example tracking actions using moesif-browser-js:**
<aside class="notice">

<div class="center-column"></div>
```javascript
var moesif = require('moesif-browser-js');

moesif.init({
applicationId: 'YOUR_COLLECTOR_APPLICATION_ID'
});
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
<a href="https://github.com/Moesif/moesifapi-nodejs">Moesif API library for Node.js</a> and
<a href="https://github.com/Moesif/moesif-nodejs">Moesif Node.js middleware</a>.

// The first argument (required) contains the action name string.
// The second argument (optional) contains event metadata.
moesif.track('Clicked Sign Up', {
button_label: 'Get Started',
sign_up_method: 'Google SSO'
});
```
</pre>
</aside>

<aside class="info">
Replace <i>YOUR_COLLECTOR_APPLICATION_ID</i> with your real Application Id
Expand Down Expand Up @@ -192,6 +192,66 @@ moesif.track('Clicked Sign Up', {
});
```

```javascript--nodejs
var moesifapi = require('moesifapi');
var apiClient = moesifapi.ApiController;

moesifapi.configuration.ApplicationId = "YOUR_COLLECTOR_APPLICATION_ID";

// Define the request context objects for each action.
var req_contextA = {
time: new Date(),
uri: "https://api.acmeinc.com/items/reviews/",
ipAddress: "61.48.220.123",
userAgentString: "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"
};

var req_contextB = {
time: new Date(),
uri: "https://api.acmeinc.com/pricing/",
ipAddress: "61.48.220.126",
userAgentString: "PostmanRuntime/7.26.5"
};

// Define the actions.
var actionA = {
transactionId: "a3765025-46ec-45dd-bc83-b136a8d1d357",
actionName: "Clicked Sign Up",
sessionToken: "23abf0owekfmcn4u3qypxg09w4d8ayrcdx8nu2ng]s98y18cx98q3yhwmnhcfx43f",
userId: "18340",
companyId: "25100",
metadata: {
email: "[email protected]",
button_label: 'Get Started',
sign_up_method: 'Google SSO'
},
request: req_contextA
};

var actionB = {
transactionId: "a3765024-46ee-45dd-bc83-b136c8d1d250",
actionName: "Viewed pricing",
sessionToken: "23jdf0owejfmbn4u3qypxg09w4d8ayrxdx8nu2ng]s98y18cx98q3yhwmnhcfx43f",
userId: "12390",
companyId: "97895",
metadata: {
email: "[email protected]",
button_label: 'See pricing',
sign_up_method: 'Google SSO'
},
request: req_contextB
};

var actions = [
new moesifapi.ActionModel(actionA),
new moesifapi.ActionModel(actionB)
];
// Send the batch of Actions
apiClient.sendActionsBatch(actions, function(error, response, context) {
// Do Something
});
```

|Name|Type|Required|Description|
|-----------|-----------|-----------|-----------|
Copy link
Contributor

@praves77 praves77 Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@selectiveduplicate any reason for using table for type description?
I have seen that this format looks broken in nuget package repository

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.
Expand Down