Skip to content

Commit

Permalink
Merge pull request #10 from shortcut/master
Browse files Browse the repository at this point in the history
Merge branch 'shortcut:master' into  'kantarsifo:master'
  • Loading branch information
Morteza-Rastgoo authored Jun 17, 2022
2 parents bb0a192 + 90cca43 commit 0e4fb7c
Show file tree
Hide file tree
Showing 19 changed files with 500 additions and 163 deletions.
13 changes: 0 additions & 13 deletions .idea/runConfigurations.xml

This file was deleted.

362 changes: 245 additions & 117 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ apply plugin: 'kotlin-android-extensions'
version = "4.0.1"

android {
compileSdkVersion 30
compileSdkVersion 31
defaultConfig {
applicationId "se.kantarsifo.mobileanalytics.sampleapp"
minSdkVersion 14
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName version
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
android:label="@string/title_content_id"
android:taskAffinity="@string/task_native_test" />


</application>



</manifest>
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package se.kantarsifo.mobileanalytics.sampleapp

import android.content.Context
import android.graphics.Color
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import androidx.activity.result.ActivityResultLauncher
import androidx.browser.trusted.TrustedWebActivityIntentBuilder
import com.google.androidbrowserhelper.trusted.TwaLauncher
import kotlinx.android.synthetic.main.activity_initialization.*
import se.kantarsifo.mobileanalytics.framework.TSMobileAnalytics
import se.kantarsifo.mobileanalytics.framework.TWAModel
import se.kantarsifo.mobileanalytics.framework.TagStringsAndValues
import se.kantarsifo.mobileanalytics.sampleapp.base.BaseActivity
import se.kantarsifo.mobileanalytics.sampleapp.native_view.NativeActivity
Expand Down Expand Up @@ -59,6 +64,7 @@ class InitializationActivity : BaseActivity() {
destroy_button.setOnClickListener { destroyCurrentFramework() }
btn_webview.setOnClickListener { onWebViewClicked() }
btn_native.setOnClickListener { onNativeClicked() }
twa_native.setOnClickListener { onTWAClicked() }
}

private fun onInitFrameworkClicked() {
Expand All @@ -72,14 +78,19 @@ class InitializationActivity : BaseActivity() {
}

private fun initializeFrameworkWithBuilder() {
TSMobileAnalytics.createInstance(
TSMobileAnalytics.createInstance(
this,
TSMobileAnalytics.Builder()
.setCpId(cpIdET.text.toString())
.setApplicationName(appNameET.text.toString())
.setPanelistTrackingOnly(panelistOnly.isChecked)
.setIsWebViewBased(isWebViewBased.isChecked)
.setLogPrintsActivated(logEnabled.isChecked)
.setTWAInfo(TWAModel(url = "https://www.mediafacts.se/").apply {
extraParams.apply {
put("customCustomerParam","foo")
}
})
.build()
)
}
Expand Down Expand Up @@ -118,6 +129,19 @@ class InitializationActivity : BaseActivity() {
}
}

private fun onTWAClicked() {
if (isFrameworkInitialized()) {
start(this)
}
}

fun start(context: Context) {

TSMobileAnalytics.instance?.openTwa()

}


private fun onNativeClicked() {
if (isFrameworkInitialized()) {
NativeActivity.start(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ abstract class BaseActivity : AppCompatActivity(), TagDataRequestCallbackListene
// TagDataRequestCallbackListener overrides

override fun onDataRequestComplete(request: TagDataRequest) {
Log.e("onDataRequestComplete","onDataRequestComplete")
runOnUiThread {
showToast("Request successful -> \"${getRequestMainInfo(request)}\"")
Log.d(Constants.LOG_TAG, request.uRL ?: "")
Expand All @@ -47,6 +48,7 @@ abstract class BaseActivity : AppCompatActivity(), TagDataRequestCallbackListene
}

override fun onDataRequestFailed(request: TagDataRequest) {
Log.e("onDataRequestFailed","onDataRequestComplete")
runOnUiThread {
showToast("Request failed -> \"${getRequestMainInfo(request)}\"")
Log.w(Constants.LOG_TAG, request.uRL ?: "")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package se.kantarsifo.mobileanalytics.sampleapp.util

object Constants {
const val CODIGO_CPID = "F53C7A3D013D4B89A1C1E697DC724467"
const val CODIGO_CPID = "F53C7A3D-013D-4B89-A1C1-E697DC724467"
const val LOG_TAG = "mobileAnalyticsLog"
const val CPID_PREFERENCE = "cpid"
const val APP_NAME_PREFERENCE = "app_name"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_initialization.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
android:id="@+id/cpIdET"
style="@style/CustomEditText"
android:layout_width="match_parent"
android:inputType="text"
android:layout_height="wrap_content"
android:hint="@string/cpid_label" />

Expand Down Expand Up @@ -87,6 +88,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/native_view_btn_label" />
<Button
android:id="@+id/twa_native"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/trusted_web_activity" />

<LinearLayout
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

<!-- WebViewActivity -->
<string name="title_web_activity">WebView Test</string>
<string name="trusted_web_activity">Trusted web activity</string>
<string-array name="web_view_sites">
<item>https://www.mediafacts.se</item>
<item>http://m.aftonbladet.se/</item>
Expand Down
4 changes: 3 additions & 1 deletion libmobiletagging/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'com.github.dcendents.android-maven'

group='myGroups'

version = "4.1.1"
version = "4.1.2"


android {
Expand Down Expand Up @@ -47,6 +47,8 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4'
api("com.google.androidbrowserhelper:androidbrowserhelper:2.3.0")

}

//android.libraryVariants.all { variant ->
Expand Down
4 changes: 4 additions & 0 deletions libmobiletagging/release-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ using Kantar Sifo’s services. The SDK zip file contains three folders:

RELEASE NOTES:

v4.1.2 2022-03-17

- Trusted Web Activity feature to open web activity in a secure way

v4.1.1 2021-09-10

- Send app version in all requests and include it in the cookie
Expand Down
1 change: 1 addition & 0 deletions libmobiletagging/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<package android:name="se.poll.android" />
<package android:name="se.tns_sifo.ipm" />
</queries>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ internal object PanelistHandler {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
ActivityResultHandler(activity, intent) { activityResult ->
if (activityResult != null) {
if (activityResult.resultCode == Activity.RESULT_OK) {
sharedPref.edit().putString(TagStringsAndValues.SIFO_PREFERENCE_COOKIES, activityResult.data?.dataString).commit()
sharedPref.edit().putLong(TagStringsAndValues.SIFO_PREFERENCE_COOKIES_SYNC_TIME, System.currentTimeMillis()).commit()
if (activityResult.resultCode == Activity.RESULT_OK ) {
sharedPref.edit().putString(TagStringsAndValues.SIFO_PREFERENCE_COOKIES, activityResult.data?.dataString).apply()
sharedPref.edit().putLong(TagStringsAndValues.SIFO_PREFERENCE_COOKIES_SYNC_TIME, System.currentTimeMillis()).apply()
}
}
onComplete()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package se.kantarsifo.mobileanalytics.framework

import android.os.Build
import android.util.Log
import android.webkit.WebView
import java.net.CookieHandler
import java.net.CookieManager
Expand Down Expand Up @@ -37,9 +38,11 @@ object SifoCookieManager {
}
val cookies = cookieManager.cookieStore.cookies
for (cookie in cookies) {
val cookieString = cookie.getName() + "=" + cookie.getValue() + "; Domain=" + cookie.getDomain()
val cookieString = cookie.name + "=" + cookie.value + "; Domain=" + cookie.domain
Log.e("cookieString",cookieString)
android.webkit.CookieManager.getInstance().setCookie(cookie.domain, cookieString)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package se.kantarsifo.mobileanalytics.framework
import android.content.Context
import android.webkit.WebView
import androidx.activity.ComponentActivity
import se.kantarsifo.mobileanalytics.framework.TagStringsAndValues.DOMAIN_CODIGO
import se.kantarsifo.mobileanalytics.framework.Utils.getApplicationVersion

/**
* Kantar Sifo Mobile Analytics Framework for Android:
Expand Down Expand Up @@ -68,6 +70,12 @@ open class TSMobileAnalytics protected constructor() {

protected var isWebViewBased = false

/**
* URL for trusted web activity
*/
lateinit var twaInfo: TWAModel


/**
* Call to immediately send a tag to the server using the framework's HTTPS-functionality.
*
Expand All @@ -87,6 +95,10 @@ open class TSMobileAnalytics protected constructor() {
fun sendTag(category: String?): Int {
return dataRequestHandler.performMetricsRequest(category)
}
fun openTwa() {
dataRequestHandler.openTwa()
}


/**
* Call to immediately send a tag to the server using the framework's HTTPS-functionality.
Expand All @@ -110,6 +122,8 @@ open class TSMobileAnalytics protected constructor() {
return dataRequestHandler.performMetricsRequest(category, contentID)
}



/**
* Call to immediately send a tag to the server using the framework's HTTPS-functionality.
*
Expand Down Expand Up @@ -147,6 +161,8 @@ open class TSMobileAnalytics protected constructor() {
dataRequestHandler.userCallbackListener = callbackListener
}



/**
* TSMobileAnalytics constructor with Builder class.
*
Expand All @@ -158,6 +174,7 @@ open class TSMobileAnalytics protected constructor() {
panelistTrackingOnly = builder.panelistTrackingOnly
logPrintsActivated = builder.logPrintsActivated
isWebViewBased = builder.isWebViewBased
twaInfo = builder.twaInfo
}

/**
Expand All @@ -179,6 +196,7 @@ open class TSMobileAnalytics protected constructor() {
private set
var isWebViewBased = false
private set
lateinit var twaInfo :TWAModel

/**
* Specify the cpId you want to set(required).
Expand Down Expand Up @@ -233,11 +251,22 @@ open class TSMobileAnalytics protected constructor() {
this.isWebViewBased = isWebViewBased
}

/**
* Specify the twaUrl you want to set(not required, default value is null).
*
* @param twaUrl Set web URL for trusted web activity
* @return the current builder object.
*/
fun setTWAInfo(twaInfo:TWAModel = TWAModel()) = apply {
this.twaInfo = twaInfo
}

/**
* @return return constructor of TSMobileAnalytics.
*/
fun build() = TSMobileAnalytics(this)


}

companion object {
Expand Down Expand Up @@ -276,16 +305,40 @@ open class TSMobileAnalytics protected constructor() {
* @return The framework instance created with your values. Returns null if creation failed due to invalid parameters.
*/
@JvmStatic
fun createInstance(activity: ComponentActivity, cpID: String?, applicationName: String?): TSMobileAnalytics? {
return TSMobileAnalyticsBackend.createInstance(activity, cpID, applicationName, false, false)
fun createInstance(
activity: ComponentActivity,
cpID: String?,
applicationName: String?
): TSMobileAnalytics? {
return TSMobileAnalyticsBackend.createInstance(
activity,
cpID,
applicationName,
false,
false
)
}

/**
* Call this method upon application start if you only want to measure Kantar Sifo Panelist users.
*/
@JvmStatic
fun createInstance(activity: ComponentActivity, cpID: String?, applicationName: String?, panelistTrackingOnly: Boolean, isWebViewBased: Boolean): TSMobileAnalytics? {
return TSMobileAnalyticsBackend.createInstance(activity, cpID, applicationName, panelistTrackingOnly, isWebViewBased)
fun createInstance(
activity: ComponentActivity,
cpID: String?,
applicationName: String?,
panelistTrackingOnly: Boolean,
isWebViewBased: Boolean,
twaInfo: TWAModel = TWAModel()
): TSMobileAnalytics? {
return TSMobileAnalyticsBackend.createInstance(
activity,
cpID,
applicationName,
panelistTrackingOnly,
isWebViewBased,
twaInfo
)
}

/**
Expand All @@ -297,8 +350,18 @@ open class TSMobileAnalytics protected constructor() {
* @return The framework instance created with your values. Returns null if creation failed due to invalid parameters.
*/
@JvmStatic
fun createInstance(activity: ComponentActivity, builder: TSMobileAnalytics): TSMobileAnalytics? {
return createInstance(activity, builder.cpId, builder.appName, builder.panelistTrackingOnly, builder.isWebViewBased)
fun createInstance(
activity: ComponentActivity,
builder: TSMobileAnalytics
): TSMobileAnalytics? {
return createInstance(
activity,
builder.cpId,
builder.appName,
builder.panelistTrackingOnly,
builder.isWebViewBased,
builder.twaInfo
)
}

/**
Expand All @@ -322,4 +385,8 @@ open class TSMobileAnalytics protected constructor() {

}





}
Loading

0 comments on commit 0e4fb7c

Please sign in to comment.