forked from openedx/openedx-app-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add video and discussion analytics #93
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
09683e6
chore: add video related events and calling of startup screen events
saeedbashir 95dee23
chore: add discussion analytics
saeedbashir e4cc212
fix: fix broken tests and address review feedback
saeedbashir 60a8e94
refactor: address review feedback
saeedbashir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,36 @@ public protocol CourseAnalytics { | |
sectionId: String, | ||
videos: Int | ||
) | ||
|
||
func videoLoaded(courseID: String, blockID: String, videoURL: String) | ||
|
||
func videoPlayed(courseID: String, blockID: String, videoURL: String) | ||
|
||
func videoChangeSpeed( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't |
||
courseID: String, | ||
blockID: String, | ||
videoURL: String, | ||
oldSpeed: Float, | ||
newSpeed: Float, | ||
currentTime: Double, | ||
duration: Double | ||
) | ||
|
||
func videoPaused( | ||
courseID: String, | ||
blockID: String, | ||
videoURL: String, | ||
currentTime: Double, | ||
duration: Double | ||
) | ||
|
||
func videoCompleted( | ||
courseID: String, | ||
blockID: String, | ||
videoURL: String, | ||
currentTime: Double, | ||
duration: Double | ||
) | ||
} | ||
|
||
#if DEBUG | ||
|
@@ -220,5 +250,35 @@ class CourseAnalyticsMock: CourseAnalytics { | |
sectionId: String, | ||
videos: Int | ||
) {} | ||
|
||
public func videoLoaded(courseID: String, blockID: String, videoURL: String) {} | ||
|
||
public func videoPlayed(courseID: String, blockID: String, videoURL: String) {} | ||
|
||
public func videoChangeSpeed( | ||
courseID: String, | ||
blockID: String, | ||
videoURL: String, | ||
oldSpeed: Float, | ||
newSpeed: Float, | ||
currentTime: Double, | ||
duration: Double | ||
) {} | ||
|
||
public func videoPaused( | ||
courseID: String, | ||
blockID: String, | ||
videoURL: String, | ||
currentTime: Double, | ||
duration: Double | ||
) {} | ||
|
||
public func videoCompleted( | ||
courseID: String, | ||
blockID: String, | ||
videoURL: String, | ||
currentTime: Double, | ||
duration: Double | ||
) {} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,17 +38,23 @@ public class VideoPlayerViewModel: ObservableObject { | |
} | ||
public let playerHolder: PlayerViewControllerHolderProtocol | ||
internal var subscription = Set<AnyCancellable>() | ||
private var appStorage: CoreStorage? | ||
private var analytics: CourseAnalytics? | ||
|
||
public init( | ||
languages: [SubtitleUrl], | ||
playerStateSubject: CurrentValueSubject<VideoPlayerState?, Never>? = nil, | ||
connectivity: ConnectivityProtocol, | ||
playerHolder: PlayerViewControllerHolderProtocol | ||
playerHolder: PlayerViewControllerHolderProtocol, | ||
appStorage: CoreStorage?, | ||
analytics: CourseAnalytics? | ||
) { | ||
self.languages = languages | ||
self.connectivity = connectivity | ||
self.playerHolder = playerHolder | ||
self.prepareLanguages() | ||
self.appStorage = appStorage | ||
self.analytics = analytics | ||
|
||
observePlayer(with: playerStateSubject) | ||
} | ||
|
@@ -88,6 +94,20 @@ public class VideoPlayerViewModel: ObservableObject { | |
.sink {[weak self] isReady in | ||
guard isReady else { return } | ||
self?.isLoading = false | ||
self?.trackVideoLoaded() | ||
} | ||
.store(in: &subscription) | ||
|
||
playerHolder.getRatePublisher() | ||
.sink {[weak self] rate in | ||
guard self?.isLoading == false else { return } | ||
self?.trackVideoChangeSpeed(rate: rate) | ||
} | ||
.store(in: &subscription) | ||
|
||
playerHolder.getFinishPublisher() | ||
.sink { [weak self] in | ||
self?.trackVideoCompleted() | ||
} | ||
.store(in: &subscription) | ||
|
||
|
@@ -184,4 +204,66 @@ public class VideoPlayerViewModel: ObservableObject { | |
}) | ||
} | ||
} | ||
|
||
private func trackVideoLoaded() { | ||
analytics?.videoLoaded( | ||
courseID: playerHolder.courseID, | ||
blockID: playerHolder.blockID, | ||
videoURL: playerHolder.url?.absoluteString ?? "" | ||
) | ||
} | ||
|
||
private func trackVideoPlayed() { | ||
analytics?.videoLoaded( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we should use |
||
courseID: playerHolder.courseID, | ||
blockID: playerHolder.blockID, | ||
videoURL: playerHolder.url?.absoluteString ?? "" | ||
) | ||
} | ||
|
||
private func trackVideoChangeSpeed(rate: Float) { | ||
if rate == 0 { | ||
analytics?.videoPaused( | ||
courseID: playerHolder.courseID, | ||
blockID: playerHolder.blockID, | ||
videoURL: playerHolder.url?.absoluteString ?? "", | ||
currentTime: currentTime, | ||
duration: playerHolder.duration | ||
) | ||
} else { | ||
guard let storage = appStorage, | ||
let userSettings = storage.userSettings | ||
else { | ||
return | ||
} | ||
|
||
if userSettings.videoPlaybackSpeed == rate { | ||
analytics?.videoPlayed( | ||
courseID: playerHolder.courseID, | ||
blockID: playerHolder.blockID, | ||
videoURL: playerHolder.url?.absoluteString ?? "" | ||
) | ||
} else { | ||
analytics?.videoChangeSpeed( | ||
courseID: playerHolder.courseID, | ||
blockID: playerHolder.blockID, | ||
videoURL: playerHolder.url?.absoluteString ?? "", | ||
oldSpeed: userSettings.videoPlaybackSpeed, | ||
newSpeed: rate, | ||
currentTime: currentTime, | ||
duration: playerHolder.duration | ||
) | ||
} | ||
} | ||
} | ||
|
||
private func trackVideoCompleted() { | ||
analytics?.videoCompleted( | ||
courseID: playerHolder.courseID, | ||
blockID: playerHolder.blockID, | ||
videoURL: playerHolder.url?.absoluteString ?? "", | ||
currentTime: currentTime, | ||
duration: playerHolder.duration | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
We can replace:
with:
It will avoid to pass mandatory
nil
parameter:To: