Skip to content

Commit fde5364

Browse files
committed
Clean up: README
Clean up updateUser and updateCompany section. Specify it's for Node.js
1 parent d4e20b5 commit fde5364

File tree

1 file changed

+143
-31
lines changed

1 file changed

+143
-31
lines changed

README.md

Lines changed: 143 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
# Moesif AWS Lambda Middleware
1+
# Moesif AWS Lambda Middleware for Node.js
22

33
[![NPM](https://nodei.co/npm/moesif-aws-lambda-nodejs.png?compact=true&stars=true)](https://nodei.co/npm/moesif-aws-lambda/)
44

55
[![Built For][ico-built-for]][link-built-for]
66
[![Software License][ico-license]][link-license]
77
[![Source Code][ico-source]][link-source]
88

9-
Middleware (NodeJS) to automatically log API calls from AWS Lambda functions
9+
Node.js Middleware for AWS Lambda that automatically logs API calls
1010
and sends to [Moesif](https://www.moesif.com) for API analytics and log analysis.
1111

12-
Designed for APIs that are hosted on AWS Lambda using Amazon API Gateway as a trigger.
13-
14-
This middleware expects the
15-
[Lambda proxy integration type.](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html#api-gateway-set-up-lambda-proxy-integration-on-proxy-resource)
16-
If you're using AWS Lambda with API Gateway, you are most likely using the proxy integration type.
12+
Designed for APIs that are hosted on AWS Lambda using Amazon API Gateway or Application Load Balancer
13+
as a trigger.
1714

1815
[Source Code on GitHub](https://github.com/moesif/moesif-aws-lambda-nodejs)
1916

@@ -23,9 +20,9 @@ If you're using AWS Lambda with API Gateway, you are most likely using the proxy
2320
</h4>
2421
<br>
2522
<p>
26-
Alternatively, if you're running the Express Framework on AWS Lambda and prefer to use Express middleware, Moesif has
27-
<a href="https://www.moesif.com/docs/server-integration/express/">Express Middleware</a> also available. The Express Middleware isn't
28-
specific to AWS lambda but won't capture AWS specific stuff like Trace Id.
23+
Alternatively, if you're running the Node.js Express Framework on AWS Lambda and prefer to not have any AWS specific dependencies,
24+
Moesif has <a href="https://www.moesif.com/docs/server-integration/express/">Express Middleware</a> also available.
25+
However, `moesif-express` won't capture lambda specific context like Trace Id.
2926
</p>
3027
</div>
3128

@@ -294,55 +291,170 @@ user_id | _Recommend_ | Identifies this API call to a permanent user_id
294291
metadata | false | A JSON Object consisting of any custom metadata to be stored with this event.
295292

296293

297-
### updateUser method
298294

299-
A method is attached to the Moesif middleware object to update the user's profile or metadata.
295+
## Update a Single User
300296

297+
Create or update a user profile in Moesif.
298+
The metadata field can be any customer demographic or other info you want to store.
299+
Only the `userId` field is required.
300+
This method is a convenient helper that calls the Moesif API lib.
301+
For details, visit the [Node.js API Reference](https://www.moesif.com/docs/api?javascript--nodejs#update-a-user).
301302

302303
```javascript
303-
const moesifOptions = {
304-
applicationId: 'Your Moesif Application Id',
304+
var moesifMiddleware = moesif(options);
305+
306+
// Only userId is required.
307+
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
308+
// See https://www.moesif.com/docs/api#users for campaign schema
309+
// metadata can be any custom object
310+
var user = {
311+
userId: '12345',
312+
companyId: '67890', // If set, associate user with a company object
313+
campaign: {
314+
utmSource: 'google',
315+
utmMedium: 'cpc',
316+
utmCampaign: 'adwords',
317+
utmTerm: 'api+tooling',
318+
utmContent: 'landing'
319+
},
320+
metadata: {
321+
email: 'john@acmeinc.com',
322+
firstName: 'John',
323+
lastName: 'Doe',
324+
title: 'Software Engineer',
325+
salesInfo: {
326+
stage: 'Customer',
327+
lifetimeValue: 24000,
328+
accountOwner: 'mary@contoso.com'
329+
}
330+
}
305331
};
306332

333+
moesifMiddleware.updateUser(user, callback);
334+
```
335+
336+
## Update Users in Batch
337+
Similar to updateUser, but used to update a list of users in one batch.
338+
Only the `userId` field is required.
339+
This method is a convenient helper that calls the Moesif API lib.
340+
For details, visit the [Node.js API Reference](https://www.moesif.com/docs/api?javascript--nodejs#update-users-in-batch).
341+
342+
```javascript
307343
var moesifMiddleware = moesif(options);
344+
345+
// Only userId is required.
346+
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
347+
// See https://www.moesif.com/docs/api#users for campaign schema
348+
// metadata can be any custom object
308349
var user = {
309-
userId: 'your user id', // required.
350+
userId: '12345',
351+
companyId: '67890', // If set, associate user with a company object
352+
campaign: {
353+
utmSource: 'google',
354+
utmMedium: 'cpc',
355+
utmCampaign: 'adwords',
356+
utmTerm: 'api+tooling',
357+
utmContent: 'landing'
358+
},
310359
metadata: {
311-
email: 'user@email.com',
312-
name: 'George'
360+
email: 'john@acmeinc.com',
361+
firstName: 'John',
362+
lastName: 'Doe',
363+
title: 'Software Engineer',
364+
salesInfo: {
365+
stage: 'Customer',
366+
lifetimeValue: 24000,
367+
accountOwner: 'mary@contoso.com'
368+
}
313369
}
314-
}
370+
};
315371

316-
moesifMiddleware.updateUser(user, callback);
372+
var users = [user]
317373

374+
moesifMiddleware.updateUsersBatch(users, callback);
318375
```
319376

320-
### updateCompany method
377+
## Update a Single Company
321378

322-
A method is attached to the Moesif middleware object to update the company's profile or metadata.
379+
Create or update a company profile in Moesif.
380+
The metadata field can be any company demographic or other info you want to store.
381+
Only the `companyId` field is required.
382+
This method is a convenient helper that calls the Moesif API lib.
383+
For details, visit the [Node.js API Reference](https://www.moesif.com/docs/api?javascript--nodejs#update-a-company).
323384

324385

325386
```javascript
326-
const moesifOptions = {
327-
applicationId: 'Your Moesif Application Id',
387+
var moesifMiddleware = moesif(options);
388+
389+
// Only companyId is required.
390+
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
391+
// See https://www.moesif.com/docs/api#update-a-company for campaign schema
392+
// metadata can be any custom object
393+
var company = {
394+
companyId: '67890',
395+
companyDomain: 'acmeinc.com', // If domain is set, Moesif will enrich your profiles with publicly available info
396+
campaign: {
397+
utmSource: 'google',
398+
utmMedium: 'cpc',
399+
utmCampaign: 'adwords',
400+
utmTerm: 'api+tooling',
401+
utmContent: 'landing'
402+
},
403+
metadata: {
404+
orgName: 'Acme, Inc',
405+
planName: 'Free Plan',
406+
dealStage: 'Lead',
407+
mrr: 24000,
408+
demographics: {
409+
alexaRanking: 500000,
410+
employeeCount: 47
411+
}
412+
}
328413
};
329414

415+
moesifMiddleware.updateCompany(company, callback);
416+
```
417+
418+
## Update Companies in Batch
419+
Similar to updateCompany, but used to update a list of companies in one batch.
420+
Only the `companyId` field is required.
421+
This method is a convenient helper that calls the Moesif API lib.
422+
For details, visit the [Node.js API Reference](https://www.moesif.com/docs/api?javascript--nodejs#update-companies-in-batch).
423+
424+
```javascript
330425
var moesifMiddleware = moesif(options);
426+
427+
// Only companyId is required.
428+
// Campaign object is optional, but useful if you want to track ROI of acquisition channels
429+
// See https://www.moesif.com/docs/api#update-a-company for campaign schema
430+
// metadata can be any custom object
331431
var company = {
332-
companyId: 'your company id', // required.
333-
companyDomain: 'acmeinc.com',
432+
companyId: '67890',
433+
companyDomain: 'acmeinc.com', // If domain is set, Moesif will enrich your profiles with publicly available info
434+
campaign: {
435+
utmSource: 'google',
436+
utmMedium: 'cpc',
437+
utmCampaign: 'adwords',
438+
utmTerm: 'api+tooling',
439+
utmContent: 'landing'
440+
},
334441
metadata: {
335-
numEmployees: 9001
442+
orgName: 'Acme, Inc',
443+
planName: 'Free Plan',
444+
dealStage: 'Lead',
445+
mrr: 24000,
446+
demographics: {
447+
alexaRanking: 500000,
448+
employeeCount: 47
449+
}
336450
}
337-
}
451+
};
338452

339-
moesifMiddleware.updateCompany(user, callback);
453+
var companies = [company]
340454

455+
moesifMiddleware.updateCompaniesBatch(companies, callback);
341456
```
342457

343-
The metadata field can be any custom data you want to set on the user.
344-
The userId field is required.
345-
346458
## Examples
347459

348460
- [A complete example is available on GitHub](https://github.com/Moesif/moesif-aws-lambda-node-js-example).

0 commit comments

Comments
 (0)