Tags by Foresight API is a free service to help you monitor specific activities on your website.
npm install foresight-sdkA TypeScript/JavaScript SDK for sending tracking events to the Foresight platform.
Install the package using npm:
``bash`
npm install foresight-sdk
Or using yarn:
`bash`
yarn add foresight-sdk
`typescript
import tracker from 'foresight-sdk';
// Track an event
try {
await tracker({
tag: 'event_name',
apiKey: 'your_api_key',
userId: 'user_123'
});
console.log('Event tracked successfully');
} catch (error) {
console.error('Failed to track event:', error);
}
`
`javascript
const tracker = require('foresight-sdk').default;
// Track an event
try {
await tracker({
tag: 'event_name',
apiKey: 'your_api_key',
userId: 'user_123'
});
console.log('Event tracked successfully');
} catch (error) {
console.error('Failed to track event:', error);
}
`
Sends a tracking event to the Foresight platform.
#### Parameters
params - Object with the following properties:
- tag (string, required): The name or identifier of the event you want to trackapiKey
- (string, required): Your Foresight API keyuserId` (string, required): The identifier of the user performing the action
-
#### Returns
Returns a Promise that resolves when the event is successfully tracked, or rejects with an error if the tracking fails.
The SDK includes built-in error handling and will throw an error if:
- The request to the Foresight API fails
- Required parameters are missing or invalid
- Network connectivity issues occur
It's recommended to wrap the tracker calls in try-catch blocks to handle potential errors gracefully.
MIT