@benshi.ai/react-native-bsh-e-learn
Version:
benshi.ai SDK for tracking logs for E-learning content block
112 lines (105 loc) • 6.26 kB
text/typescript
import {
NativeModules,
Platform
} from 'react-native';
import {
ModuleProperties,
ExamProperties,
QuestionProperties
} from "./typings";
const { BsLogELearn } = NativeModules;
/**
* logModuleEvent is required to log actions related to e-learning modules which includes
* the log for the user viewing the module. This is the first step towards interacting with the
* e-learning content. It can be a course itself the user is trying to view.
*
* @param id string type refers to the module id for which the user is viewing.
* @param action is required to set the Action type for the module event. SDK
* provides enum classes to support available log types. 1 main is
* view. SDK provides 2 approaches to log this event, one being an enum
* type and the other is a string type
* @param progress is required to pass current progress of the module which the user
* is viewing. Progress value is the percentage complete for the
* module that needs to pass as an integer.
* @param meta is to send any other data you want to send with the ingest, can be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logModuleEvent = (properties: ModuleProperties) => {
if(Platform.OS === 'android'){
console.log(properties)
BsLogELearn.logModuleEvent(properties.id, properties.action, properties.progress, null, false)
}
}
/**
* logExamEvent is required to log actions related to e-learning module exams. which includes
* the related to starting, submitting, or viewing results for the exam. BsLogExamEvent also
* updates the user level if they achieved a milestone.
*
* @param id is required to log examId for the Exam on which user is performing
* actions. Exam Id should be in a string format and must be in
* accordance with the catalog provided.
* @param action is required to set the Action type for the Exam event. SDK
* provides enum classes to support available log types. 3 main are
* start, submit, and result. SDK provides 2 approaches to log this
* event, one being enum type and the other is a string type
* @param duration is required to loge the duration (time elapsed) by the user to
* complete the exam. Duration should be in Seconds. This is required
* in case of examAction been submitted.
* @param score is required if there is some score provided ot the user in the result
* of the exam submitted. this is required in case of examAction been
* result.
* @param is_passed is required if the user passed or failed the exam. This log is
* required only in case when examAction is result.
* @param meta is to send any other data you want to send with the ingest, can be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logExamEvent = (properties: ExamProperties) => {
if(properties.duration === null || typeof properties.duration === "undefined"){
properties.duration = 0
}
if(properties.score === null || typeof properties.score === "undefined"){
properties.score = 0
}
if(properties.is_passed === null || typeof properties.is_passed === "undefined"){
properties.is_passed = false
}
if(Platform.OS === 'android'){
console.log(properties)
BsLogELearn.logExamEvent(properties.id, properties.action, properties.duration, properties.score, properties.is_passed, null, false)
}
}
/**
* logQuestionEvent is required to log user answers to the questions. To log this event you
* need to provide the question Id that User has attempted and also the id for the answer the
* the user has selected.
*
* @param id is required to log questionId for the Question on which user has
* attempted. Question Id should be in a string format and must be in
* accordance with the catalog provided.
* @param exam_id is required to log examId for the exam the Question belongs to.
* examId should be in a string format and must be in accordance to
* the catalog provided.
* @param action is required to set the Action type for the Question event. SDK
* provides enum classes to support available log types. 2 main are
* answer and skip. SDK provides 2 approaches to log this event, one
* being enum type and the other is string type.
* @param answer_id is required to log answerId for the answer provided by the user for
* the Question on which user has attempted. Answer Id should be in a
* string format and must be in accordance to the catalog provided.
* @param meta is to send any other data you want to send with the ingest, can be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logQuestionEvent = (properties: QuestionProperties) => {
if(Platform.OS === 'android'){
console.log(properties)
BsLogELearn.logQuestionEvent(properties.id, properties.exam_id, properties.action, properties.answer_id, null, false)
}
}
export default {
logModuleEvent,
logExamEvent,
logQuestionEvent
}