From 3e76512f7e20258cc99f3aceea6cf3114bd080fa Mon Sep 17 00:00:00 2001 From: "aleksandar.marinkovi" Date: Wed, 22 Sep 2021 12:51:06 +0200 Subject: [PATCH] * Improve: Now the media can contain the name of the page --- CHANGELOG.md | 4 +++- android-sdk/gradle.properties | 2 +- .../java/webtrekk/android/sdk/Webtrekk.kt | 6 ++++++ .../webtrekk/android/sdk/core/WebtrekkImpl.kt | 19 ++++++++++++++++--- .../sdk/domain/external/TrackCustomMedia.kt | 6 ++++-- .../sdk/events/eventParams/MediaParameters.kt | 2 +- build.gradle | 2 -- .../androidsdk/MediaActivityExample.kt | 16 ++++++++-------- .../androidsdk/StandardVideoActivity.kt | 2 +- .../webtrekk/androidsdk/TrackedVideoView.kt | 12 ++++++------ .../webtrekk/androidsdk/VideoActivity.kt | 14 +++++++------- 11 files changed, 53 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31a36a95..e1603c70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/android-sdk/gradle.properties b/android-sdk/gradle.properties index 220c3538..b7b16ca5 100644 --- a/android-sdk/gradle.properties +++ b/android-sdk/gradle.properties @@ -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 diff --git a/android-sdk/src/main/java/webtrekk/android/sdk/Webtrekk.kt b/android-sdk/src/main/java/webtrekk/android/sdk/Webtrekk.kt index 32cda261..ccac36b5 100644 --- a/android-sdk/src/main/java/webtrekk/android/sdk/Webtrekk.kt +++ b/android-sdk/src/main/java/webtrekk/android/sdk/Webtrekk.kt @@ -174,6 +174,12 @@ abstract class Webtrekk protected constructor() { trackingParams: Map = emptyMap() ) + abstract fun trackMedia( + pageName: String, + mediaName: String, + trackingParams: Map = emptyMap() + ) + /** * Tracks specific exception event. * @param exception the exception object that caused crash diff --git a/android-sdk/src/main/java/webtrekk/android/sdk/core/WebtrekkImpl.kt b/android-sdk/src/main/java/webtrekk/android/sdk/core/WebtrekkImpl.kt index 1e559588..88682fb0 100644 --- a/android-sdk/src/main/java/webtrekk/android/sdk/core/WebtrekkImpl.kt +++ b/android-sdk/src/main/java/webtrekk/android/sdk/core/WebtrekkImpl.kt @@ -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) { @@ -213,6 +217,14 @@ constructor() : Webtrekk(), } override fun trackMedia(mediaName: String, trackingParams: Map) { + this.trackMedia(mediaName, mediaName, trackingParams) + } + + override fun trackMedia( + pageName: String, + mediaName: String, + trackingParams: Map + ) { if (!mediaParamValidation(trackingParams)) { return } @@ -220,7 +232,7 @@ constructor() : Webtrekk(), trackCustomMedia( TrackCustomMedia.Params( trackRequest = TrackRequest( - name = mediaName, + name = pageName, screenResolution = context.resolution(), forceNewSession = currentSession, appFirstOpen = appFirstOpen, @@ -229,7 +241,8 @@ constructor() : Webtrekk(), ), trackingParams = trackingParams, isOptOut = hasOptOut(), - context = context + context = context, + mediaName = mediaName ), coroutineDispatchers ) } diff --git a/android-sdk/src/main/java/webtrekk/android/sdk/domain/external/TrackCustomMedia.kt b/android-sdk/src/main/java/webtrekk/android/sdk/domain/external/TrackCustomMedia.kt index 20445620..e94db607 100644 --- a/android-sdk/src/main/java/webtrekk/android/sdk/domain/external/TrackCustomMedia.kt +++ b/android-sdk/src/main/java/webtrekk/android/sdk/domain/external/TrackCustomMedia.kt @@ -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( @@ -96,6 +97,7 @@ internal class TrackCustomMedia( val trackRequest: TrackRequest, val trackingParams: Map, val isOptOut: Boolean, - val context: Context? = null + val context: Context? = null, + val mediaName: String = "" ) } diff --git a/android-sdk/src/main/java/webtrekk/android/sdk/events/eventParams/MediaParameters.kt b/android-sdk/src/main/java/webtrekk/android/sdk/events/eventParams/MediaParameters.kt index 17a36a40..ed333a00 100644 --- a/android-sdk/src/main/java/webtrekk/android/sdk/events/eventParams/MediaParameters.kt +++ b/android-sdk/src/main/java/webtrekk/android/sdk/events/eventParams/MediaParameters.kt @@ -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()) diff --git a/build.gradle b/build.gradle index 3bf2d35b..2d9891a7 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,6 @@ buildscript { 'kotlinCoroutines' : '1.3.1', 'coreKtxVersion' : '1.1.0', - 'koinAndroidVersion' : '2.1.6', 'okHttpVersion' : '4.2.2', @@ -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", diff --git a/sample/src/main/java/com/example/webtrekk/androidsdk/MediaActivityExample.kt b/sample/src/main/java/com/example/webtrekk/androidsdk/MediaActivityExample.kt index a23a3e69..dc2a6d4b 100644 --- a/sample/src/main/java/com/example/webtrekk/androidsdk/MediaActivityExample.kt +++ b/sample/src/main/java/com/example/webtrekk/androidsdk/MediaActivityExample.kt @@ -37,7 +37,7 @@ class MediaActivityExample : AppCompatActivity() { ) ) - Webtrekk.getInstance().trackMedia("android-demo-media", trackingParams) + Webtrekk.getInstance().trackMedia("MediaActivityExample","android-demo-media", trackingParams) } @@ -52,7 +52,7 @@ 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 { @@ -60,7 +60,7 @@ class MediaActivityExample : AppCompatActivity() { 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 { @@ -68,7 +68,7 @@ class MediaActivityExample : AppCompatActivity() { 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() } @@ -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( @@ -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() } @@ -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) } } diff --git a/sample/src/main/java/com/example/webtrekk/androidsdk/StandardVideoActivity.kt b/sample/src/main/java/com/example/webtrekk/androidsdk/StandardVideoActivity.kt index f1882f56..1fed4370 100644 --- a/sample/src/main/java/com/example/webtrekk/androidsdk/StandardVideoActivity.kt +++ b/sample/src/main/java/com/example/webtrekk/androidsdk/StandardVideoActivity.kt @@ -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() } } \ No newline at end of file diff --git a/sample/src/main/java/com/example/webtrekk/androidsdk/TrackedVideoView.kt b/sample/src/main/java/com/example/webtrekk/androidsdk/TrackedVideoView.kt index 37888bfe..abd5df67 100644 --- a/sample/src/main/java/com/example/webtrekk/androidsdk/TrackedVideoView.kt +++ b/sample/src/main/java/com/example/webtrekk/androidsdk/TrackedVideoView.kt @@ -47,7 +47,7 @@ class TrackedVideoView : VideoView { ) ) - Webtrekk.getInstance().trackMedia("video name", trackingParams) + Webtrekk.getInstance().trackMedia("TrackedVideoView","video name", trackingParams) } override fun pause() { @@ -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) } @@ -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) } @@ -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) } @@ -93,7 +93,7 @@ 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( @@ -101,7 +101,7 @@ class TrackedVideoView : VideoView { MediaParam.MEDIA_ACTION to "play" ) ) - Webtrekk.getInstance().trackMedia("video name", trackingParams) + Webtrekk.getInstance().trackMedia("TrackedVideoView","video name", trackingParams) } diff --git a/sample/src/main/java/com/example/webtrekk/androidsdk/VideoActivity.kt b/sample/src/main/java/com/example/webtrekk/androidsdk/VideoActivity.kt index ef0174cd..d7c181f7 100644 --- a/sample/src/main/java/com/example/webtrekk/androidsdk/VideoActivity.kt +++ b/sample/src/main/java/com/example/webtrekk/androidsdk/VideoActivity.kt @@ -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 -> { @@ -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) } } @@ -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) } @@ -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() @@ -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() @@ -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) @@ -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(