@useparallel/analytics v0.0.15
@useparallel/analytics
Overview
@useparallel/analytics
is a package that provides functionality for analytics and event tracking in the Parallel ecosystem. It offers a set of types and classes to interact with the analytics backend and handle various events.
Installation
To install the package, use npm or yarn:
npm install @useparallel/analytics
# or
yarn add @useparallel/analytics
Usage
types.ts
This file contains TypeScript type definitions used within the package. It defines various event names and their associated data structures.
PRLAnalytics.ts
PRLAnalytics
is the main class in the package, responsible for handling analytics-related operations. It allows you to send events to the analytics backend and provides a method for checking the package.
Constructor
constructor(host: string)
host
: The base URL of the analytics backend.
Methods
checkPackage
checkPackage(text: string): string;
Checks the package and returns a concatenated string with the given text.
readEvent
readEvent(data: ReadEventData): Promise<any>;
Sends an event to the analytics backend using a POST request. The data
parameter should be an object conforming to the ReadEventData
interface.
index.ts
The package's entry point exports the PRLAnalytics
class.
import { PRLAanalytics as PRLAanalyticSDK } from '@useparallel/analytics';
export default PRLAanalyticSDK;
Examples
import PRLAanalyticSDK from '@useparallel/analytics';
// Initialize PRLAnalytics with the backend URL
const analytics = new PRLAanalyticSDK('http://localhost:8002');
// Check the package
const result = analytics.checkPackage('Hello');
console.log(result); // Output: "Hello from the parallel analytics package"
// Prepare event data
const eventData = {
eventName: 'applicationCountByJobId',
inferenceObj: {
OpsModel: 'RequestOpModel',
eventCallId: 'some_job_id',
},
callType: 'event',
};
// Send the event to the analytics backend
analytics.readEvent(eventData).then((response) => {
console.log(response); // Handle the response from the analytics backend
});
Contributing
Contributions to the @useparallel/analytics
package are welcome. If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the GitHub repository.
License
@useparallel/analytics
is licensed under the MIT License.