-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into upload-worker-ui
- Loading branch information
Showing
10 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
plugins { | ||
alias(libs.plugins.android.library) | ||
alias(libs.plugins.kotlin.android) | ||
} | ||
|
||
android { | ||
namespace = "com.infomaniak.matomo" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
minSdk = 24 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
|
||
buildConfigField("String", "MATOMO_URL", "\"https://analytics.infomaniak.com/matomo.php\"") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
buildFeatures { | ||
buildConfig = true | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
api(core2.matomo) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
107 changes: 107 additions & 0 deletions
107
Core2/Matomo/src/main/java/com/infomaniak/matomo/Matomo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Infomaniak SwissTransfer - Android | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.matomo | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.util.Log | ||
import org.matomo.sdk.Matomo | ||
import org.matomo.sdk.Tracker | ||
import org.matomo.sdk.TrackerBuilder | ||
import org.matomo.sdk.extra.DownloadTracker | ||
import org.matomo.sdk.extra.TrackHelper | ||
|
||
interface Matomo { | ||
|
||
val Context.tracker: Tracker | ||
val siteId: Int | ||
|
||
fun Context.buildTracker(shouldOptOut: Boolean = false): Tracker { | ||
return TrackerBuilder(BuildConfig.MATOMO_URL, siteId, "AndroidTracker").build(Matomo.getInstance(this)).also { | ||
// Put a tracker on app installs to have statistics on the number of times the app is installed or updated | ||
TrackHelper.track().download().identifier(DownloadTracker.Extra.ApkChecksum(this)).with(it) | ||
it.isOptOut = shouldOptOut | ||
} | ||
} | ||
|
||
fun Context.addTrackingCallbackForDebugLog() { | ||
if (BuildConfig.DEBUG) { | ||
tracker.addTrackingCallback { trackMe -> | ||
trackMe.also { | ||
it.toMap().forEach { entry -> | ||
when (entry.key) { | ||
"action_name" -> Log.d("TrackerScreen", entry.value) | ||
"e_c" -> Log.d("TrackerEvent", "Category : ${entry.value}") | ||
"e_n" -> Log.d("TrackerEvent", "Name : ${entry.value}") | ||
"e_a" -> Log.d("TrackerEvent", "Action : ${entry.value}") | ||
"e_v" -> Log.d("TrackerEvent", "Value : ${entry.value}") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun Context.trackUserId(userId: Int) { | ||
tracker.userId = userId.toString() | ||
} | ||
|
||
//region Track screens | ||
fun Activity.trackScreen() { | ||
TrackHelper.track().screen(this).title(this::class.java.simpleName).with(tracker) | ||
} | ||
|
||
fun Context.trackScreen(path: String, title: String) { | ||
TrackHelper.track().screen(path).title(title).with(tracker) | ||
} | ||
//endregion | ||
|
||
//region Track events | ||
fun Context.trackEvent(category: String, name: String, action: TrackerAction = TrackerAction.CLICK, value: Float? = null) { | ||
TrackHelper.track() | ||
.event(category, action.toString()) | ||
.name(name) | ||
.let { if (value != null) it.value(value) else it } | ||
.with(tracker) | ||
} | ||
|
||
fun Context.trackAccountEvent(name: String, action: TrackerAction = TrackerAction.CLICK, value: Float? = null) { | ||
trackEvent("account", name, action, value) | ||
} | ||
//endregion | ||
|
||
fun Boolean.toFloat() = if (this) 1.0f else 0.0f | ||
|
||
fun shouldOptOut(context: Context, shouldOptOut: Boolean) { | ||
context.tracker.isOptOut = shouldOptOut | ||
} | ||
|
||
enum class TrackerAction { | ||
CLICK, | ||
DATA, | ||
DRAG, | ||
INPUT, | ||
LONG_PRESS; | ||
|
||
override fun toString() = name.lowercase().snakeToCamelCase() | ||
|
||
private fun String.snakeToCamelCase(): String { | ||
return replace("_[a-zA-Z]".toRegex()) { it.value.replace("_", "").uppercase() } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
[versions] | ||
sentry-android = "7.15.0" | ||
matomo = "4.1.4" | ||
|
||
[libraries] | ||
sentry-android = { module = "io.sentry:sentry-android", version.ref = "sentry-android" } | ||
matomo = { module = "com.github.matomo-org:matomo-sdk-android", version.ref = "matomo" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/infomaniak/swisstransfer/ui/MatomoSwissTransfer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Infomaniak SwissTransfer - Android | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.swisstransfer.ui | ||
|
||
import android.content.Context | ||
import com.infomaniak.matomo.Matomo | ||
import org.matomo.sdk.Tracker | ||
|
||
object MatomoSwissTransfer : Matomo { | ||
|
||
override val Context.tracker: Tracker get() = (this as MainActivity).buildTracker() //TODO fetch appSettings for opt out | ||
override val siteId: Int = -1 //TODO replace with the right site ID when we have one | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters