GOFA Lessons
GOFA Lessons SDK enables seamless integration of interactive video fitness lessons into your Flutter application, with robust tracking of user progress and engagement using Firebase Firestore.
Purpose
- Track user interactions with lessons and plans.
- Store and synchronize lesson data and user progress.
- Support personalized fitness journeys with lesson plans and analytics.
Key Concepts
Play
A "play" refers to a single instance of a user interacting with a specific lesson. It includes starting, pausing, resuming, and ending the lesson. Each play is uniquely identified by a playId and can have multiple sessions corresponding to different parts of the lesson.
Plan Play
A "plan play" is an interaction involving a lesson plan, which consists of a combination of lessons. It encompasses starting, pausing, resuming, resetting, and completing the entire plan. Each plan play is denoted by a unique planPlayId.
Firestore Structure
Data is organized into collections for Plans, Lessons, Users, UserLessons, Plays, PlanPlays, UserPlans, and DailyRecords.
Example Use Cases
Let's explore some common use cases and how they map to the technical structure:
1. Finish a Lesson
When a user finishes a lesson:
- The app updates the status of the play to "ended" in the
Users > Playscollection.
2. Upon status update, a Firestore trigger calculates and updatestotalRepCountandtotalSecondsSpent.
3. ThelastPlayedandtotalPlaysfields are updated both in theUsers > UserLessonssubcollection and theLessonscollection.
4. If the lesson is completed, the status inUsers > Playsis marked asended.
void finishLesson(String gofaUserId, String playId) async {
await FirebaseFirestore.instance.collection('Users').doc(gofaUserId).collection('Plays').doc(playId).update({
'status': 'ended',
});
}
2. Cancel a Lesson
When a user cancels a lesson play:
- The app updates the status to "cancelled" in the
Users > Playscollection.
2. The status change will be reflected in the frontend, indicating the user has cancelled the lesson.
void cancelLesson(String gofaUserId, String playId) async {
await FirebaseFirestore.instance.collection('Users').doc(gofaUserId).collection('Plays').doc(playId).update({
'status': 'cancelled',
});
}
3. Finish a Plan
When a user completes a lesson plan:
- The status of the
planPlayinUsers > PlanPlaysis updated to "ended".
2. Details liketotalRepCountandtotalSecondsSpentare computed and recorded in the Firestore document.
3. ThelastPlayedandtotalPlaysfields of the lesson plan in theUsers > UserPlanssubcollection, as well as thePlanscollection, are updated accordingly.
void finishPlan(String gofaUserId, String planPlayId) async {
await FirebaseFirestore.instance.collection('Users').doc(gofaUserId).collection('PlanPlays').doc(planPlayId).update({
'status': 'ended',
});
}
Firestore Structure Overview
Collections
- Plans
Stores information about lesson plans including names, descriptions, and the lessons they include. - Lessons
Keeps track of individual video lessons, views, plays, and completions. - Users
gofaUserId(Documents)- UserLessons
Records user-specific data related to lessons. - Plays
Manages individual lesson play data. - PlanPlays
Manages interactions with lesson plans. - UserPlans
Contains aggregated data on plans accessed by the user. - DailyRecords
Daily activity metrics for users.
- UserLessons
Installation & Setup
-
Add the SDK Use OnePub to add
gofa_lessonsto your project.onepub pub add gofa_lessons -
Add Required Packages
flutter pub add get_it -
Initialize the SDK Register and initialize
LessonSdkManagerwith your client credentials and environment. -
Localization Add
GofaLessonLocalizationsDelegate()to yourMaterialApp'slocalizationsDelegates.
Versioning
See the SDK Versions page for the latest changes and upgrade instructions.