From 4598a73485456f33b9dca0211b877303353e01b0 Mon Sep 17 00:00:00 2001 From: Morteza Rastgoo <5219339+Morteza-Rastgoo@users.noreply.github.com> Date: Tue, 7 Sep 2021 12:11:10 +0200 Subject: [PATCH 1/4] Add app start event --- .../framework/TSMobileAnalyticsBackend.kt | 15 +++++++++++++++ .../framework/TagStringsAndValues.kt | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt index 86fd035..533e2d9 100644 --- a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt +++ b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt @@ -13,6 +13,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import se.kantarsifo.mobileanalytics.framework.Logger.fatalError import se.kantarsifo.mobileanalytics.framework.Logger.log +import se.kantarsifo.mobileanalytics.framework.TagStringsAndValues.SIFO_APP_START_EVENT_CATEGORY import se.kantarsifo.mobileanalytics.framework.Utils.isPackageInstalled import java.net.HttpCookie @@ -57,6 +58,8 @@ internal class TSMobileAnalyticsBackend : TSMobileAnalytics { initTags(activity, cpID!!, applicationName!!, onlyPanelist) + sendAppStartEvent() + PanelistHandler.syncCookies(activity, activity) { refreshCookiesAndKeys(activity,onlyPanelist) frameworkInstance!!.dataRequestHandler.setStateReady() @@ -126,6 +129,18 @@ internal class TSMobileAnalyticsBackend : TSMobileAnalytics { return true } + /** + * Sends the app start event + */ + private fun sendAppStartEvent() { + if (frameworkInstance ==null) { + log("Cannot create app start event") + return + } + + frameworkInstance!!.sendTag(SIFO_APP_START_EVENT_CATEGORY) + } + } } diff --git a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TagStringsAndValues.kt b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TagStringsAndValues.kt index e218767..0ccc86a 100644 --- a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TagStringsAndValues.kt +++ b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TagStringsAndValues.kt @@ -177,4 +177,9 @@ object TagStringsAndValues { */ internal const val SIFO_META_COOKIE_NAME = "sifo_config" + /** + * app start event category name + */ + internal const val SIFO_APP_START_EVENT_CATEGORY = "appstart" + } \ No newline at end of file From e0a0b18b1f99c6fad162ea2a11b5a1ec785dc958 Mon Sep 17 00:00:00 2001 From: Morteza Rastgoo <5219339+Morteza-Rastgoo@users.noreply.github.com> Date: Fri, 10 Sep 2021 10:31:36 +0200 Subject: [PATCH 2/4] Disable the SDK if onlyPanelist==true and the sifo internet app is not installed --- .../framework/TSMobileAnalyticsBackend.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt index 533e2d9..a4b64bc 100644 --- a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt +++ b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt @@ -62,7 +62,7 @@ internal class TSMobileAnalyticsBackend : TSMobileAnalytics { PanelistHandler.syncCookies(activity, activity) { refreshCookiesAndKeys(activity,onlyPanelist) - frameworkInstance!!.dataRequestHandler.setStateReady() + frameworkInstance?.dataRequestHandler?.setStateReady() } } else { log("Mobile Application Tagging Framework already initialized") @@ -76,13 +76,16 @@ internal class TSMobileAnalyticsBackend : TSMobileAnalytics { private fun refreshCookiesAndKeys(activity: ComponentActivity, onlyPanelist: Boolean) { val isInstalled = activity.isPackageInstalled(TagStringsAndValues.SIFO_PANELIST_PACKAGE_NAME_V2) if (!isInstalled) { - //TODO: 2021-09-02 Do we need logFatalError when onlyPanelist ==true? + if (onlyPanelist && !isInstalled) { + frameworkInstance = null + fatalError("To track panelists only you need to have the internet app installed") + } //No need to refresh the cookies since there is no panelist app to get the cookies from return } log("Refreshing panelist keys(Cookies)") val cookies = PanelistHandler.getCookies(activity, activity) - frameworkInstance!!.dataRequestHandler.apply { + frameworkInstance?.dataRequestHandler?.apply { if (cookies != null) { refreshCookies(cookies) } else { @@ -138,7 +141,7 @@ internal class TSMobileAnalyticsBackend : TSMobileAnalytics { return } - frameworkInstance!!.sendTag(SIFO_APP_START_EVENT_CATEGORY) + frameworkInstance?.sendTag(SIFO_APP_START_EVENT_CATEGORY) } } From 75ec1c8e263186ab95113a7a789fa5f5f62f5943 Mon Sep 17 00:00:00 2001 From: Morteza Rastgoo <5219339+Morteza-Rastgoo@users.noreply.github.com> Date: Fri, 10 Sep 2021 11:10:50 +0200 Subject: [PATCH 3/4] Send app version in all requests and include it in the cookie --- .../framework/TSMobileAnalyticsBackend.kt | 7 +++--- .../mobileanalytics/framework/TagHandler.kt | 23 +++++++++++-------- .../mobileanalytics/framework/Utils.kt | 10 ++++++++ 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt index a4b64bc..6336e86 100644 --- a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt +++ b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt @@ -6,7 +6,6 @@ package se.kantarsifo.mobileanalytics.framework import android.content.Context -import android.util.Log import androidx.activity.ComponentActivity import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -14,6 +13,7 @@ import kotlinx.coroutines.launch import se.kantarsifo.mobileanalytics.framework.Logger.fatalError import se.kantarsifo.mobileanalytics.framework.Logger.log import se.kantarsifo.mobileanalytics.framework.TagStringsAndValues.SIFO_APP_START_EVENT_CATEGORY +import se.kantarsifo.mobileanalytics.framework.Utils.getApplicationVersion import se.kantarsifo.mobileanalytics.framework.Utils.isPackageInstalled import java.net.HttpCookie @@ -46,8 +46,9 @@ internal class TSMobileAnalyticsBackend : TSMobileAnalytics { fatalError("Mobile Application Tagging Framework Failed to initiate - context must not be null") return frameworkInstance } - val version = BuildConfig.VERSION_NAME - val cookieValue = "trackPanelistOnly=$onlyPanelist&isWebViewBased=$isWebBased&sdkVersion=$version" + val sdkVersion = BuildConfig.VERSION_NAME + val appVersion = activity.getApplicationVersion() + val cookieValue = "trackPanelistOnly=$onlyPanelist&isWebViewBased=$isWebBased&sdkVersion=$sdkVersion&appVersion=$appVersion" val metaCookie = CookieHandler.createHttpCookie(TagStringsAndValues.SIFO_META_COOKIE_NAME, cookieValue) CookieHandler.setupPanelistCookies(listOf(metaCookie)) if (paramsAreValid(cpID, applicationName)) { diff --git a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TagHandler.kt b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TagHandler.kt index 80e0b4e..3da1e6a 100644 --- a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TagHandler.kt +++ b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TagHandler.kt @@ -8,6 +8,7 @@ package se.kantarsifo.mobileanalytics.framework import android.annotation.SuppressLint import android.content.Context import android.content.pm.PackageManager +import android.net.Uri import android.os.Build.VERSION import android.os.Build.VERSION_CODES import android.provider.Settings.Secure @@ -16,6 +17,7 @@ import org.json.JSONObject import se.kantarsifo.mobileanalytics.framework.Logger.error import se.kantarsifo.mobileanalytics.framework.Logger.fatalError import se.kantarsifo.mobileanalytics.framework.Logger.log +import se.kantarsifo.mobileanalytics.framework.Utils.getApplicationVersion import java.io.UnsupportedEncodingException import java.net.CookieStore import java.net.HttpCookie @@ -54,7 +56,7 @@ internal class TagHandler( init { generateEuId(context) cookies?.let { initCookies(it) } - getApplicationVersion(context) + applicationVersion = context.getApplicationVersion() } fun refresh(panelistKey: String?) { @@ -86,6 +88,16 @@ internal class TagHandler( .replace("{appNameValue}", type) // This seems like a mistake but the client confirmed they want it like this. .replace("{appRefValue}", encodedRef) + applicationVersion?.apply { + val encodedVersion = urlEncode(trim()) + val uri = Uri.parse(url) + .buildUpon() + .appendQueryParameter("appVersion",encodedVersion) + .build() + url = uri.toString() + } + + } return url } @@ -128,15 +140,6 @@ internal class TagHandler( } } - private fun getApplicationVersion(context: Context) { - try { - applicationVersion = - context.packageManager.getPackageInfo(context.packageName, 0).versionName - } catch (e: Exception) { - error("Failed to retrieve application version, will not set be set in request header") - } - } - private fun initCookies(cookieList: List) { val setupPanelListCookies = SetupPanelListCookies(context, cookieList) setupPanelListCookies.run() diff --git a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/Utils.kt b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/Utils.kt index e99e148..ef7a52e 100644 --- a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/Utils.kt +++ b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/Utils.kt @@ -12,4 +12,14 @@ object Utils { false } } + + fun Context.getApplicationVersion(): String? { + return try { + packageManager.getPackageInfo(packageName, 0).versionName + } catch (e: Exception) { + Logger.error("Failed to retrieve application version, will not set be set in request header") + null + } + } + } \ No newline at end of file From ec6a64014d2cf42c36d1f881b88bb1cad82ce1e1 Mon Sep 17 00:00:00 2001 From: Morteza Rastgoo <5219339+Morteza-Rastgoo@users.noreply.github.com> Date: Fri, 10 Sep 2021 11:32:52 +0200 Subject: [PATCH 4/4] Version 4.1.1 --- libmobiletagging/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmobiletagging/build.gradle b/libmobiletagging/build.gradle index 852ef2e..bb7698a 100644 --- a/libmobiletagging/build.gradle +++ b/libmobiletagging/build.gradle @@ -5,7 +5,7 @@ apply plugin: 'com.github.dcendents.android-maven' group='myGroups' -version = "4.1.0" +version = "4.1.1" android {