From c2468aded8111e425047e8b64d61be6208d0b769 Mon Sep 17 00:00:00 2001 From: Percy Date: Tue, 11 Aug 2020 11:47:38 +0200 Subject: [PATCH 1/3] Add sifo config cookie. --- .../mobileanalytics/framework/CookieHandler.kt | 4 ++-- .../framework/PanelistHandler.kt | 17 ++++++----------- .../framework/TSMobileAnalyticsBackend.kt | 7 ++++--- .../framework/TagStringsAndValues.kt | 15 +++++---------- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/CookieHandler.kt b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/CookieHandler.kt index bc80c4a..731f79b 100644 --- a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/CookieHandler.kt +++ b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/CookieHandler.kt @@ -27,7 +27,7 @@ internal object CookieHandler { } @Throws(JSONException::class) - fun getCookieFromJson(json: JSONObject, isPanelistOnly: Boolean, isWebBased: Boolean, version: String): HttpCookie { + fun getCookieFromJson(json: JSONObject): HttpCookie { return createHttpCookie( name = json.getString("key"), value = json.getString("value"), @@ -57,7 +57,7 @@ internal object CookieHandler { return String.format("%s=%s", cookie.name, cookie.value) } - private fun createHttpCookie(name: String, + fun createHttpCookie(name: String, value: String?, path: String = "/", domain: String = TagStringsAndValues.DOMAIN_CODIGO diff --git a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/PanelistHandler.kt b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/PanelistHandler.kt index 005996a..11df2ad 100644 --- a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/PanelistHandler.kt +++ b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/PanelistHandler.kt @@ -6,7 +6,6 @@ import android.content.Intent import android.content.SharedPreferences import android.content.pm.PackageManager import android.net.Uri -import android.util.Log import androidx.activity.ComponentActivity import org.json.JSONArray import org.json.JSONException @@ -54,7 +53,6 @@ internal object PanelistHandler { } onComplete() } - //han.launchIntent(intent) }else{ onComplete() } @@ -66,16 +64,13 @@ internal object PanelistHandler { fun getCookies(context: Context, activity: ComponentActivity): List? { val sharedPref = activity.getSharedPreferences(TagStringsAndValues.SIFO_PREFERENCE_KEY, Context.MODE_PRIVATE) - val panelistOnly = sharedPref.getBoolean(TagStringsAndValues.SIFO_COOKIES_IS_PANELIST_ONLY, false) - val isWebBased = sharedPref.getBoolean(TagStringsAndValues.SIFO_COOKIES_IS_WEB_BASED, false) - val version = BuildConfig.VERSION_NAME if (sharedPref.contains(TagStringsAndValues.SIFO_PREFERENCE_COOKIES)) { - return readCookiesFromJson(sharedPref.getString(TagStringsAndValues.SIFO_PREFERENCE_COOKIES, "") ?: "", panelistOnly, isWebBased, version) + return readCookiesFromJson(sharedPref.getString(TagStringsAndValues.SIFO_PREFERENCE_COOKIES, "") ?: "") } else { // Fallback to old version of reading cookies from sifo panel app shared preference val inputStream = getSifoInputStream(context, TagStringsAndValues.SIFO_PANELIST_PACKAGE_NAME_V2, TagStringsAndValues.SIFO_PANELIST_CREDENTIALS_FILENAME_V2) - return inputStream?.let { readCookieStore(it, panelistOnly, isWebBased, version) } + return inputStream?.let { readCookieStore(it) } } } @@ -109,13 +104,13 @@ internal object PanelistHandler { } } - private fun readCookiesFromJson(content: String, panelistOnly: Boolean, isWebBased: Boolean, version: String): List { + private fun readCookiesFromJson(content: String): List { val cookieList = mutableListOf() try { val jsonArray = JSONArray(content) for (i in 0 until jsonArray.length()) { val entry = jsonArray.getJSONObject(i) - cookieList.add(CookieHandler.getCookieFromJson(entry, panelistOnly, isWebBased, version)) + cookieList.add(CookieHandler.getCookieFromJson(entry)) } } catch (e: JSONException) { TSMobileAnalyticsBackend.logError("Error parsing TNS Panelist JSON data") @@ -123,14 +118,14 @@ internal object PanelistHandler { return cookieList } - private fun readCookieStore(stream: FileInputStream, panelistOnly: Boolean, isWebBased: Boolean, version: String): List { + private fun readCookieStore(stream: FileInputStream): List { val content = readFile(stream, "Error reading TNS Panelist cookies") val cookieList = mutableListOf() try { val jsonArray = JSONArray(content) for (i in 0 until jsonArray.length()) { val entry = jsonArray.getJSONObject(i) - cookieList.add(CookieHandler.getCookieFromJson(entry, panelistOnly, isWebBased, version)) + cookieList.add(CookieHandler.getCookieFromJson(entry)) } } catch (e: JSONException) { TSMobileAnalyticsBackend.logError("Error parsing TNS Panelist JSON data") 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 361b2bd..07bb846 100644 --- a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt +++ b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TSMobileAnalyticsBackend.kt @@ -42,9 +42,10 @@ internal class TSMobileAnalyticsBackend : TSMobileAnalytics { logFatalError("Mobile Application Tagging Framework Failed to initiate - context must not be null") return frameworkInstance } - val sharedPref = activity.getSharedPreferences(TagStringsAndValues.SIFO_PREFERENCE_KEY, Context.MODE_PRIVATE) - sharedPref.edit().putBoolean(TagStringsAndValues.SIFO_COOKIES_IS_PANELIST_ONLY, onlyPanelist).commit() - sharedPref.edit().putBoolean(TagStringsAndValues.SIFO_COOKIES_IS_WEB_BASED, isWebBased).commit() + val version = BuildConfig.VERSION_NAME + val cookieValue = "trackPanelistOnly=$onlyPanelist&isWebViewBased=$isWebBased&sdkVersion=$version" + val metaCookie = CookieHandler.createHttpCookie(TagStringsAndValues.SIFO_META_COOKIE_NAME, cookieValue) + CookieHandler.setupPanelistCookies(listOf(metaCookie)) if (frameworkInstance == null) { if (paramsAreValid(cpID, applicationName)) { 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 f4c151c..e218767 100644 --- a/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TagStringsAndValues.kt +++ b/libmobiletagging/src/main/java/se/kantarsifo/mobileanalytics/framework/TagStringsAndValues.kt @@ -157,16 +157,6 @@ object TagStringsAndValues { */ internal const val SIFO_PREFERENCE_COOKIES = "SIFO_PREFERENCE_COOKIES" - /** - * Key for isPanelistOnly cookie tracking - */ - internal const val SIFO_COOKIES_IS_PANELIST_ONLY = "SIFO_COOKIES_IS_PANELIST_ONLY" - - /** - * Key for isWebBased cookie tracking - */ - internal const val SIFO_COOKIES_IS_WEB_BASED = "SIFO_COOKIES_IS_WEB_BASED" - /** * Key for last cookie sync time */ @@ -182,4 +172,9 @@ object TagStringsAndValues { */ internal const val SIFO_DEFAULT_CONFIG = "https://trafficgateway.research-int.se/TrafficCollector?siteId={siteIdValue}&appClientId={appClientIdValue}&cp={cpValue}&appId={appIDValue}&appName={appNameValue}&appRef={appRefValue}" + /** + * Meta cookie name + */ + internal const val SIFO_META_COOKIE_NAME = "sifo_config" + } \ No newline at end of file From e66f32033ea72d1d59fb3c2e4a9be51c6021460b Mon Sep 17 00:00:00 2001 From: Percy Date: Wed, 2 Sep 2020 14:37:37 +0200 Subject: [PATCH 2/3] Update readme. --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2cce426..ca2d655 100644 --- a/README.md +++ b/README.md @@ -239,7 +239,11 @@ Strings sent to the server will be encoded using UTF-8. If the String given to t # FAQ - +- **Why do I need to initialise the library by passing ComponentActivity and not just Context as before?** +To properly track information regarding Sifo panelist users the library needs to read information from the Sifo Internet app if it is also installed on the device. +In the past it was possible to read the needed information directly from the Sifo Internet app, however since the recent security updates on Android this is no longer possible. +The new solution is to request the information from the Sifo internet, app given it is installed on the same device. +This means on initialisation the app will send an intent request to the Sifo Internet app and wait for the result and this is why just passing the context is no longer enough. - **How do I test and verify that the framework is correct integrated?** See [Test Application](#test-application) and [Validation test with Kantar Sifo​](#validation-test-with-kantar-sifo) below. - **Native app - how do I integrate the framework?** From bcf1b423123274770b45569fbac1a00e03c5e189 Mon Sep 17 00:00:00 2001 From: Percy Date: Wed, 30 Sep 2020 10:52:55 +0200 Subject: [PATCH 3/3] Version bump 4.0.1. --- app/build.gradle | 2 +- libmobiletagging/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b324e4a..deb1ce4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' -version = "3.0.4" +version = "4.0.1" android { compileSdkVersion 29 diff --git a/libmobiletagging/build.gradle b/libmobiletagging/build.gradle index b558a58..bdb4721 100644 --- a/libmobiletagging/build.gradle +++ b/libmobiletagging/build.gradle @@ -5,7 +5,7 @@ apply plugin: 'com.github.dcendents.android-maven' group='myGroups' -version = "4.0.0" +version = "4.0.1" android {