@benshi.ai/react-native-bsh-e-learn
v1.1.4
Published
benshi.ai SDK for tracking logs for E-learning content block
Downloads
61
Readme
Benshi React Native (Android) SDK Setup - E-Learning
Benshi Android SDK E-Learning module consists of events for online learning platforms. You need to implement this module if your app offers learning content that may include learning content, viewing courses, attempting exams, or passing an exam to get certified. In order to use the e-learning, module you need to include the following dependency in your app-level build.gradle but make sure you have the core module already integrated.
This documentation covers the steps to integrating SDK in your react native (android) apps. We’ll also discuss a few fundamentals of how the dashboard works in tandem with your app usage to view your users and engage them with contextually personalized messages.
Getting Started
In order to use the SDK, Core is mandatory to include as it contains the elements regarding the basic app navigation and workflow including nudges. Moreover, all the modules require the core to be integrated in order to successfully log the events.
The easiest way to integrate Benshi react native (android) SDK in your project is using an NPM package. Add dependencies of react-native SDK in the dependencies
section of your package.json
of your project and Android Lifecycle Components in the app/build.gradle file.
"dependencies": {
"@benshi.ai/react-native-bsh-e-learn": "<version_number>"
},
for
version_number
please head to npm package.
After including the above, Open terminal/shell and go to your project directory, and run:
npm install
This will install the e-learn npm package in the node modules of your project. Now you need to link this module with your android app, for this in the same terminal in your project directory run:
react-native link @benshi.ai/react-native-bsh-e-learn
This will link your newly added module with your android app and you can also see the link in your android settings.gradle
file.
To add the dependency, open your android folder in Android Studio and open the app-level build.gradle file. now in your dependencies add the following:
dependencies {
implementation project(path: ':@benshi.ai_react-native-bsh-e-learn')
}
Please note that this package required you to already install and linked react-native-bsh-core
package in your app or else the logs will not be triggered.
Tracking System Events
We have several predefined actions that users can perform while interacting with your app. These actions are referred to as System Events that help in tracking elements on your app with user interaction.
Here's a list of System Events that can be tracked using the e-learning module:
| Event Name | Calling in SDK | Description | | ---------- | --------------- | ---------------------------------------------------------------- | | Module | EventType.module | Track user interactions with e-learning modules inside the app. | | Exam | EventType.exam | Track user interaction with the exam, when they start, submit or retake the exam. | | Question | EventType.question | Track user interaction with questions or quiz inside the app, what answers they choose. |
To log e-learning events you need to import BsELearn main class and contents to support different actions:
import BshELearn from '@benshi.ai/react-native-bsh-e-learn';
Here BsELearn is the main class for all the e-learning related events to help you implement logs in a functional approach. while rest are content classes to help you with actions for different logs. You can also pass strings instead of these content values but the params should be the same as provided in contents or else the log will not be triggered and an exception will be thrown by the SDK. BsELearn class contains a list of functions in the main module and every function has 2 extra params to help you, you can include them in the parent functions, one is meta
which you can use to pass data you want to the SDK but remember to pass it in as key-value pair and convert that to JSON string so that it may be parsed with the rest of the SDK content. The last param is the updateImmediately
boolean which helps you to send a specific log as soon as it happens as by default SDK logs the events at the end of the session in a batch.
Usage for the above-mentioned events is given below:
Module Event
logModuleEvent is required to log actions related to e-learning modules which include 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 moduleId 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 the view action. SDK provides 2 approaches to log this event, one being enum type and the other is a string type
- @param progress is required to pass the 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.
let moduleProperties = {
id: "testModuleId",
action: ModuleAction.View,
progress: 90
}
BshELearn.logModuleEvent(moduleProperties)
ModuleLogAction is required to set the log action for the module event. SDK provides enum ModuleAction
to support available log types.
View // for viewing a module element
Exam Event
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 string type, used to log the test user is attempting.
- @param action enum is the action performed y the user on the test, possible values start, submit, and result.
- @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 is submit.
- @param score is required if there is some score provided to the user as a result of the exam submitted. This is required in case of examAction is result.
- @param is_passed is required if the user passed or failed the exam. This log is required only in case of examAction is result.
let examStartProperties = {
id: "testExamId",
action: ExamAction.Start
}
let examSubmitProperties = {
id: "testExamId",
action: ExamAction.Submit,
duration: 36000
}
let examResultProperties = {
id: "testExamId",
action: ExamAction.Result,
score: 80,
is_passed: true
}
BshELearn.logExamEvent(examResultProperties)
ExamAction is required to set the Action type for the exam event. SDK provides enum class ExamAction
to support available log types.
Start // for logging start of the exam
Submit // for logging submission of exam
Result // for logging result of the exam
Question Event
logQuestionEvent is required to log user answers to the questions. To log this event you need to provide the question Id that the user has attempted and also the id for the answer 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 with 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 being string type.
- @param answer_id is required to log answerId for the answer provided by the user for the Question on which the user has attempted. Answer Id should be a string.
let questionProperties = {
id: "testQuestionId",
exam_id: "testExamId",
action: QuestionAction.Answer,
answer_id : "testAnswerId"
}
BshELearn.logQuestionEvent(questionProperties)
For implementation, you can also view the demo app.
Guidelines
- Including lifecycle components is required in order to use the SDK as SDK requires lifecycle components to listen for app events regarding app sessions and app moving to the background.
- Anything you include in the
meta
will be sent to the backend and be visible in the log monitoring section, but it will not be processed. Custom Event Attributes
can be of these data types: String, Number, Boolean, Date, List, Map.- Make sure to include your SDK key in the manifest of your Android App so that SDK can have that while initialization or else it would through an
IllegalAccessException
. - Make sure to initialize the SDK in the
Application
class or else if you trigger SDK events without that it will throughRuntimeException
. updateImmediately
is an optional param, by default its value is true. You can decide for each event if it needs to be updated immediately, or it can wait until the end of the app session.- Please ensure consistent usage of the names of Custom Events in meta and their Custom Attributes across all your apps (Android, iOS) and website.
- Please use the same name conventions as provided by the enums if you choose to pass strings as values or else the event will be discarded and an
IllegalArgumentException
will be thrown.
Please feel free to drop in a few lines at [email protected]
in case you have any further queries. We're always just an email away!