Skip to content

Commit

Permalink
* Improve: Now the media can contain the name of the page
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandar.marinkovi committed Sep 22, 2021
1 parent 17b1b36 commit 3e76512
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 32 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Change Log
## Version 5.1.1-beta3 *(InProgress)*

## Version 5.1.1-beta2 *(InProgress)*
## Version 5.1.1-beta2 *(2021-09-22)*
* Improve: Now the media can contain the name of the page

## Version 5.1.1-beta1 *(2021-09-2)*
* Improve: Koin is removed from the project
Expand Down
2 changes: 1 addition & 1 deletion android-sdk/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# SOFTWARE.
#
#
LIBRARY_VERSION=5.1.1-beta1
LIBRARY_VERSION=5.1.1-beta2
BINTRAY_REPO=webtrekk-android-sdk
BINRTAY_NAME=webtrekk-android-sdk
PUBLISHED_GROUP_ID=com.mapp.sdk
Expand Down
6 changes: 6 additions & 0 deletions android-sdk/src/main/java/webtrekk/android/sdk/Webtrekk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ abstract class Webtrekk protected constructor() {
trackingParams: Map<String, String> = emptyMap()
)

abstract fun trackMedia(
pageName: String,
mediaName: String,
trackingParams: Map<String, String> = emptyMap()
)

/**
* Tracks specific exception event.
* @param exception the exception object that caused crash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ constructor() : Webtrekk(),
}

override fun trackMedia(media: MediaEvent) {
trackMedia(media.pageName, media.toHasMap())
this.trackMedia(
pageName = media.pageName,
mediaName = media.parameters.name,
trackingParams = media.toHasMap()
)
}

override fun trackAction(action: ActionEvent) {
Expand Down Expand Up @@ -213,14 +217,22 @@ constructor() : Webtrekk(),
}

override fun trackMedia(mediaName: String, trackingParams: Map<String, String>) {
this.trackMedia(mediaName, mediaName, trackingParams)
}

override fun trackMedia(
pageName: String,
mediaName: String,
trackingParams: Map<String, String>
) {
if (!mediaParamValidation(trackingParams)) {
return
}
config.run {
trackCustomMedia(
TrackCustomMedia.Params(
trackRequest = TrackRequest(
name = mediaName,
name = pageName,
screenResolution = context.resolution(),
forceNewSession = currentSession,
appFirstOpen = appFirstOpen,
Expand All @@ -229,7 +241,8 @@ constructor() : Webtrekk(),
),
trackingParams = trackingParams,
isOptOut = hasOptOut(),
context = context
context = context,
mediaName = mediaName
), coroutineDispatchers
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ internal class TrackCustomMedia(
)
) {
val params = invokeParams.trackingParams.toMutableMap()
params[RequestType.MEDIA.value] = invokeParams.trackRequest.name
if (invokeParams.mediaName.isNotEmpty())
params[RequestType.MEDIA.value] = invokeParams.mediaName
params.remove(RequestType.EVENT.value)
// Cache the track request with its custom params.
cacheTrackRequestWithCustomParams(
Expand All @@ -96,6 +97,7 @@ internal class TrackCustomMedia(
val trackRequest: TrackRequest,
val trackingParams: Map<String, String>,
val isOptOut: Boolean,
val context: Context? = null
val context: Context? = null,
val mediaName: String = ""
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ data class MediaParameters(
map.addNotNull("${MediaParam.MEDIA_CATEGORY}$key", value)
}
}
map.addNotNull(MediaParam.NAME, name)
// map.addNotNull(MediaParam.NAME, name)
map.addNotNull(MediaParam.MEDIA_ACTION, action)
map.addNotNull(MediaParam.MEDIA_POSITION, position.formatNumber())
map.addNotNull(MediaParam.MEDIA_DURATION, duration.formatNumber())
Expand Down
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ buildscript {

'kotlinCoroutines' : '1.3.1',
'coreKtxVersion' : '1.1.0',
'koinAndroidVersion' : '2.1.6',

'okHttpVersion' : '4.2.2',

Expand Down Expand Up @@ -80,7 +79,6 @@ buildscript {
coroutinesCore : "org.jetbrains.kotlinx:kotlinx-coroutines-core:$versions.kotlinCoroutines",
coroutinesAndroid : "org.jetbrains.kotlinx:kotlinx-coroutines-android:$versions.kotlinCoroutines",
okHttp : "com.squareup.okhttp3:okhttp:$versions.okHttpVersion",
koinAndroid : "io.insert-koin:koin-android:$versions.koinAndroidVersion",
room : "androidx.room:room-runtime:$versions.roomVersion",
roomKtx : "androidx.room:room-ktx:$versions.roomVersion",
roomCompiler : "androidx.room:room-compiler:$versions.roomVersion",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MediaActivityExample : AppCompatActivity() {
)
)

Webtrekk.getInstance().trackMedia("android-demo-media", trackingParams)
Webtrekk.getInstance().trackMedia("MediaActivityExample","android-demo-media", trackingParams)


}
Expand All @@ -52,23 +52,23 @@ class MediaActivityExample : AppCompatActivity() {
currentState = "play"
trackingParams[MediaParam.MEDIA_ACTION] = "play"
trackingParams[MediaParam.MEDIA_POSITION] = progress.toString()
Webtrekk.getInstance().trackMedia("android-demo-media", trackingParams)
Webtrekk.getInstance().trackMedia("MediaActivityExample","android-demo-media", trackingParams)
startTimerService()
}
pauseButton.setOnClickListener {
val progress: Int = currentPlayProgress
currentState = "pause"
trackingParams[MediaParam.MEDIA_ACTION] = "pause"
trackingParams[MediaParam.MEDIA_POSITION] = progress.toString()
Webtrekk.getInstance().trackMedia("android-demo-media", trackingParams)
Webtrekk.getInstance().trackMedia("MediaActivityExample","android-demo-media", trackingParams)
timerService?.shutdown()
}
stopButton.setOnClickListener {
val progress: Int = currentPlayProgress
currentState = "stop"
trackingParams[MediaParam.MEDIA_ACTION] = "stop"
trackingParams[MediaParam.MEDIA_POSITION] = progress.toString()
Webtrekk.getInstance().trackMedia("android-demo-media", trackingParams)
Webtrekk.getInstance().trackMedia("MediaActivityExample","android-demo-media", trackingParams)
timerService?.shutdown()
}

Expand All @@ -85,14 +85,14 @@ class MediaActivityExample : AppCompatActivity() {
startTimerService()
}
trackingParams[MediaParam.MEDIA_POSITION] = progress.toString()
Webtrekk.getInstance().trackMedia("android-demo-media", trackingParams)
Webtrekk.getInstance().trackMedia("MediaActivityExample","android-demo-media", trackingParams)
}

override fun onStartTrackingTouch(seekBar: SeekBar) {
val progress: Int = currentPlayProgress
trackingParams[MediaParam.MEDIA_ACTION] = "seek"
trackingParams[MediaParam.MEDIA_POSITION] = progress.toString()
Webtrekk.getInstance().trackMedia("android-demo-media", trackingParams)
Webtrekk.getInstance().trackMedia("MediaActivityExample","android-demo-media", trackingParams)
}

override fun onProgressChanged(
Expand All @@ -108,7 +108,7 @@ class MediaActivityExample : AppCompatActivity() {
override fun onDestroy() {
trackingParams[MediaParam.MEDIA_ACTION] = "eof"
trackingParams[MediaParam.MEDIA_POSITION] = currentPlayProgress.toString()
Webtrekk.getInstance().trackMedia("android-demo-media", trackingParams)
Webtrekk.getInstance().trackMedia("MediaActivityExample","android-demo-media", trackingParams)
super.onDestroy()
timerService?.shutdown()
}
Expand All @@ -132,7 +132,7 @@ class MediaActivityExample : AppCompatActivity() {
val progress: Int = currentPlayProgress
trackingParams[MediaParam.MEDIA_ACTION] = "pos"
trackingParams[MediaParam.MEDIA_POSITION] = progress.toString()
Webtrekk.getInstance().trackMedia("android-demo-media", trackingParams)
Webtrekk.getInstance().trackMedia("MediaActivityExample","android-demo-media", trackingParams)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class StandardVideoActivity : AppCompatActivity() {
MediaParam.MEDIA_ACTION to "eof"
)
)
Webtrekk.getInstance().trackMedia("video name", myVideoView?.trackingParams!!)
Webtrekk.getInstance().trackMedia("StandardVideoActivity","video name", myVideoView?.trackingParams!!)
super.onStop()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TrackedVideoView : VideoView {

)
)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("TrackedVideoView","video name", trackingParams)
}

override fun pause() {
Expand All @@ -58,7 +58,7 @@ class TrackedVideoView : VideoView {
MediaParam.MEDIA_ACTION to "pause"
)
)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("TrackedVideoView","video name", trackingParams)
}


Expand All @@ -70,7 +70,7 @@ class TrackedVideoView : VideoView {
MediaParam.MEDIA_ACTION to "play"
)
)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("TrackedVideoView","video name", trackingParams)

}

Expand All @@ -82,7 +82,7 @@ class TrackedVideoView : VideoView {
MediaParam.MEDIA_ACTION to "stop"
)
)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("TrackedVideoView","video name", trackingParams)
}


Expand All @@ -93,15 +93,15 @@ class TrackedVideoView : VideoView {
MediaParam.MEDIA_ACTION to "seek"
)
)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("TrackedVideoView","video name", trackingParams)
super.seekTo(msec)
trackingParams.putAll(
mapOf(
MediaParam.MEDIA_POSITION to (currentPosition / 1000).toString(),
MediaParam.MEDIA_ACTION to "play"
)
)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("TrackedVideoView","video name", trackingParams)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class VideoActivity : AppCompatActivity(), View.OnClickListener, PlaybackPrepare
MediaParam.MEDIA_ACTION to "eof"
)
)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("VideoActivity","video name", trackingParams)
clearStartPosition()
}
ExoPlayer.STATE_READY -> {
Expand Down Expand Up @@ -118,7 +118,7 @@ class VideoActivity : AppCompatActivity(), View.OnClickListener, PlaybackPrepare
MediaParam.MEDIA_ACTION to if (isPlaying) "play" else "pause"
)
)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("VideoActivity","video name", trackingParams)
}

}
Expand Down Expand Up @@ -215,7 +215,7 @@ class VideoActivity : AppCompatActivity(), View.OnClickListener, PlaybackPrepare
MediaParam.MEDIA_ACTION to "seek"
)
)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("VideoActivity","video name", trackingParams)


}
Expand Down Expand Up @@ -264,7 +264,7 @@ class VideoActivity : AppCompatActivity(), View.OnClickListener, PlaybackPrepare
MediaParam.MEDIA_ACTION to "stop"
)
)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("VideoActivity","video name", trackingParams)
if (Util.SDK_INT <= 23) {
if (playerView != null) {
playerView.onPause()
Expand All @@ -290,7 +290,7 @@ class VideoActivity : AppCompatActivity(), View.OnClickListener, PlaybackPrepare
MediaParam.MEDIA_ACTION to "eof"
)
)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("VideoActivity","video name", trackingParams)
if (player != null) {
updateTrackSelectorParameters()
updateStartPosition()
Expand Down Expand Up @@ -319,7 +319,7 @@ class VideoActivity : AppCompatActivity(), View.OnClickListener, PlaybackPrepare
)
)
muted = !muted
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("VideoActivity","video name", trackingParams)
return true
}
return super.onKeyDown(keyCode, event)
Expand All @@ -338,7 +338,7 @@ class VideoActivity : AppCompatActivity(), View.OnClickListener, PlaybackPrepare
)

)
Webtrekk.getInstance().trackMedia("video name", trackingParams)
Webtrekk.getInstance().trackMedia("VideoActivity","video name", trackingParams)
}
})
this.applicationContext.contentResolver.registerContentObserver(
Expand Down

0 comments on commit 3e76512

Please sign in to comment.