@evlop/user-activity-analysis-api
v1.0.7
Published
A TypeScript client library for interacting with the Segment Reach API, providing functionality to track user properties and send templated emails.
Readme
User Activity Analysis API Client
A TypeScript client library for interacting with the Segment Reach API, providing functionality to track user properties and send templated emails.
Installation
npm install @evlop/user-activity-analysis-apiConfiguration
Before using the client, you need to create an instance with your API credentials:
import UserActivityAnalysis from '@evlop/user-activity-analysis-api';
const client = new UserActivityAnalysis({
apiKey: 'your-api-key',
apiBaseUrl: 'https://segment-reach-api.evlop.com', // Optional: defaults to this URL
propertiesToTrack: ['name', 'email', 'phone'] // Optional: defaults to these properties
});
// You can update the configuration later if needed
client.updateConfig({
apiKey: 'new-api-key',
propertiesToTrack: ['name', 'email', 'phone', 'company']
});Features
Track User Properties
Update user properties in the system:
await client.setUserProperty('user123', {
name: 'John Doe',
email: '[email protected]',
phone: '+1234567890'
});Send Templated Emails
Send emails using predefined templates. You can send either by user ID or directly to an email address:
// Send to a user by ID
await client.sendEmail({
userId: 'user123',
templateId: 'template-id',
params: {
firstName: 'John',
customData: 'value'
}
});
// Or send directly to an email address
await client.sendEmail({
email: '[email protected]',
templateId: 'template-id',
params: {
firstName: 'John',
customData: 'value'
}
});API Reference
new UserActivityAnalysis(config)
Create a new client instance with configuration.
config.apiKey(required): Your API key for authenticationconfig.apiBaseUrl(optional): Base URL for the API (defaults to 'https://segment-reach-api.evlop.com')config.propertiesToTrack(optional): Array of property names to track (defaults to ['name', 'email', 'phone'])
client.updateConfig(config)
Update the client configuration.
config: Same options as constructor
client.setUserProperty(userId, properties)
Update user properties in the system.
userId(required): Unique identifier for the userproperties(required): Object containing user properties to update
client.sendEmail(params)
Send a templated email to a user or email address.
params(required): Object containing either:userIdandtemplateIdfor user-based sendingemailandtemplateIdfor direct email sendingparams: Object containing template parameters
Error Handling
The client includes built-in error handling and will log errors to the console when API calls fail. All methods are safe to call even when the API client is not initialized.
License
MIT
