Analytics
When our app is using an SDK sometimes we need to have more insights into what is happening inside that SDK. This page is going to describe this toolset.
Playback Lifecycle Observer: What if the consumer application wants to observe events that are happening for each video that is playing for the user? Firework SDK made it easy for the host app.
Each event has extra metadata with it. This metadata is generally a playable object that contains the list of variables below:
- id: String
- videoDuration: Long
- variant: String
- externalVastConfigFileUrl: String
- uri: String
- title: String
- triggers: List
- subtitles: List
- clip: Clip
- adTagUri: String
- isAd: Boolean
- isImaAd: Boolean
List of playback events:
- 1.OnPrepared: When the playable item is prepared for play, but it has not started to play yet.
- 2.OnPlayingChanged: When the playable item playing status is changed, It means if it starts playing this event is sent and if it is paused this event is sent as well. Extra metadata: isPlaying:Boolean
- 3.OnBuffering: When a playable item is buffering.
- 4.OnIdle: When a playable item is buffered and prepared fully but has not started to play.
- 5.OnRepeat: When a playable item is repeated.
- 6.OnEnded: When a playable is finished this event is sent.
- 7.OnError: When playback has an error to play a playable item. Extra metadata: PlayerError
- 8.OnSeek: When a playable item has been sought to a new position. Extra metadata: newPosition: Long
- 9.OnVideoSizeChanged: When the dimension of the video has been changed. Extra metadata: AspectRatio object
- 10.OnProgress: Every 1000 milliseconds this event is sent while the playable is playing. Extra metadata: Progress object
- 11.OnFirstQuartile: When the first 25% of the video has passed Extra metadata: Progress object
- 12.OnSecondQuartile: When the first 50% of the video has passed Extra metadata: Progress object
- 13.OnThirdQuartile: When the first 75% of the video has passed Extra metadata: Progress object
- 14.OnLast90PercentOfTheVideo: When the first 90% of the video has passed Extra metadata: Progress object
Now the question is how to listen to these events?
val config = FireworkSdkConfig
.Builder(this)
.checksumRequired(false)
.clientId(BuildConfig.FW_CLIENT_ID)
.userId(BuildConfig.FW_USER_ID)
.imageLoader(GlideImageLoaderFactory.createInstance())
.build()
FireworkSdk.init(config)
// Call this function after your init phase
FireworkSdk.registerPlaybackLifecycleObserver(this)
// Now let's your application implement PlaybackLifecycleObserver interface
// Then on this overrided function you will get the events
override fun onStateChanged(lifecycleState: LifecycleState) {
Log.i("XXXX-lifecycle", "$lifecycleState - ${lifecycleState.playable.id}")
}
ATTENTION: Keep in mind that you should not pass an anonymous class to the registerPlaybackLifecycleObserver function. If you pass an anonymous function then that function will never be called. You should always pass an object that has a reference to it, like the application class or any other class that you know will be alive for the lifetime of your app.
ShareButtonClickListener: This listener will be called when the share button on the video player page is being called by the user. The usage is super simple, You just set that lambda expression after initializing the SDK.\
val config = FireworkSdkConfig
.Builder(this)
.checksumRequired(false)
.clientId(BuildConfig.FW_CLIENT_ID)
.userId(BuildConfig.FW_USER_ID)
.imageLoader(GlideImageLoaderFactory.createInstance())
.build()
FireworkSdk.init(config)
// Make sure to call this after init phase
FireworkSdk.setShareButtonClickListener { feedElementAnalyticsData ->
// feedElementAnalyticsData has these values
// val autoplay: Boolean,
// val badge: String,
// val caption: String,
// val duration: Long,
// val hashtags: List<String>,
// val hasCta: Boolean,
// val height: Int,
// val width: Int,
// val videoId: String,
// val progress: Int,
// val playlistId: String,
// val channelId: String,
// val feedType: String,
Log.i("XXXX-share", "${feedElementAnalyticsData.caption}")
}
CtaButtonClickHandler: This handler is called when the CTA button is pressed by the user. If the consumer application implements this Handler and returns true, It means the SDK will not do anything, but if The consumer application does not implement that or implement it and return false at the end, The SDK will open the action url of the CTA button in a new tab of the default browser of the phone of the user.
val config = FireworkSdkConfig
.Builder(this)
.checksumRequired(false)
.clientId(BuildConfig.FW_CLIENT_ID)
.userId(BuildConfig.FW_USER_ID)
.imageLoader(GlideImageLoaderFactory.createInstance())
.build()
FireworkSdk.init(config)
// Make sure to call this after init phase
FireworkSdk.setCtaButtonClickHandler { label, actionUrl, feedElementAnalyticsData ->
// feedElementAnalyticsData has these values
// val autoplay: Boolean,
// val badge: String,
// val caption: String,
// val duration: Long,
// val hashtags: List<String>,
// val hasCta: Boolean,
// val height: Int,
// val width: Int,
// val videoId: String,
// val progress: Int,
// val playlistId: String,
// val channelId: String,
// val feedType: String,
startActivity(context, ProductActivity:class)
Log.i("XXXX-cta", "$label $actionUrl $feedElementAnalyticsData")
true
}
Last modified 22d ago