Skip to main content

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:

  1. The app updates the status of the play to "ended" in the Users > Plays collection.
    2. Upon status update, a Firestore trigger calculates and updates totalRepCount and totalSecondsSpent.
    3. The lastPlayed and totalPlays fields are updated both in the Users > UserLessons subcollection and the Lessons collection.
    4. If the lesson is completed, the status in Users > Plays is marked as ended.
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:

  1. The app updates the status to "cancelled" in the Users > Plays collection.
    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:

  1. The status of the planPlay in Users > PlanPlays is updated to "ended".
    2. Details like totalRepCount and totalSecondsSpent are computed and recorded in the Firestore document.
    3. The lastPlayed and totalPlays fields of the lesson plan in the Users > UserPlans subcollection, as well as the Plans collection, 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.

Installation & Setup

  1. Add the SDK Use OnePub to add gofa_lessons to your project.

    onepub pub add gofa_lessons
  2. Add Required Packages

    flutter pub add get_it
  3. Initialize the SDK Register and initialize LessonSdkManager with your client credentials and environment.

  4. Localization Add GofaLessonLocalizationsDelegate() to your MaterialApp's localizationsDelegates.

Versioning

See the SDK Versions page for the latest changes and upgrade instructions.