Introduction
Welcome to the documentation for customeriocommon. This library provides various utilities and functions to support common tasks in customer.io integration.
Installation
Prerequisites
Before proceeding with the installation, please ensure you have the following:
- Active customer.io account
- Access to the project where customeriocommon will be used
- Basic knowledge of programming concepts and the programming language used in your project
Installing customeriocommon
To install customeriocommon, follow these steps:
- Open your project in a code editor
- Add customeriocommon to your project’s dependencies:
npm install customeriocommon
Usage
Importing customeriocommon
To use customeriocommon in your project, import it using the following code:
import customeriocommon from 'customeriocommon';
Example Usage
Here’s an example that demonstrates how to use customeriocommon for sending events to customer.io:
const eventName = 'UserLoggedOut';
const eventData = {
userId: '123456789',
timestamp: new Date().toISOString()
};
customeriocommon.sendEvent(eventName, eventData);
API Reference
Functions
sendEvent(eventName: string, eventData: object): void
Sends an event to customer.io with the specified event name and data.
Parameters:
- eventName (string): The name of the event.
- eventData (object): The data associated with the event.
Example:
const eventName = 'UserLoggedIn';
const eventData = {
userId: '123456789',
timestamp: new Date().toISOString()
};
customeriocommon.sendEvent(eventName, eventData);
getUserProfile(userId: string): object
Retrieves the user profile from customer.io based on the specified user ID.
Parameters:
- userId (string): The ID of the user.
Returns:
The user profile object if found, otherwise null.
Example:
const userId = '123456789';
const userProfile = customeriocommon.getUserProfile(userId);
if (userProfile) {
console.log(userProfile);
} else {
console.log('User profile not found');
}
Troubleshooting
Cannot import customeriocommon
If you encounter an error message stating “Cannot import customeriocommon”, make sure you have properly installed the library using the npm install command.
If the issue persists, try the following steps:
- Check your project’s package.json file to ensure customeriocommon is listed as a dependency.
- Delete your project’s node_modules directory and run npm install again.
- Ensure that your project has a valid package-lock.json file.
- If none of the above steps resolve the issue, consider reaching out to the customeriocommon support team for further assistance.