commit a1157cb3e97d74a45f7b2fc59b7099f33114002b Author: yangxisong Date: Tue Dec 9 15:09:16 2025 +0800 feat: 埋点数据收集SDK diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c37ccdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# ---> Android +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Log/OS Files +*.log + +# Android Studio generated files and folders +captures/ +.externalNativeBuild/ +.cxx/ +*.apk +output.json + +# IntelliJ +*.iml +.idea/ +misc.xml +deploymentTargetDropDown.xml +render.experimental.xml + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Android Profiling +*.hprof +app/release + diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..cb7aeb9 --- /dev/null +++ b/Readme.md @@ -0,0 +1,37 @@ +采用 Room 实现数据持久化,使用Worker管理上传任务,初次上传+重试共5次,重试间隔10s线性增加;多上传任务顺序处理; +网络请求 Retrofit +### aar位置 +根目录 aar/release/trackingPoint.aar +### 使用 +```kotlin +/** + * 初始化 + */ +TrackingManager.init( + context = this.application, + iTrackingPointUserInfo = TrackingPointUserInfoImp(), + systemCode = "999999999", //通过管理平台获取,硬编码 +) + +/** + * 实现 ITrackingPointUserInfo 获取 UserInfo 的方法 + */ +class TrackingPointUserInfoImp: ITrackingPointUserInfo { + override fun uploadUserInfo(): UserInfo { + return UserInfo( + userId = 123456, + userName = "username", + account = "account" + ) + } +} + +TrackingManager.push( + eventType = "dianji", //通过管理平台获取 + eventParams = EventParams( + buttonId = "${view.id}", + page = "Main", + url = "" + ) +) +``` diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..8344d75 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,66 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) +} + +android { + signingConfigs { + create("release") { + storeFile = file("../test.jks") + storePassword = "qwer1234.." + keyAlias = "key0" + keyPassword = "qwer1234.." + } + } + namespace = "com.yuanxuan.tracking_point" + compileSdk { + version = release(36) + } + + defaultConfig { + applicationId = "com.yuanxuan.tracking_point" + minSdk = 23 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + debug { + signingConfig = signingConfigs.getByName("release") + } + release { + signingConfig = signingConfigs.getByName("release") + isMinifyEnabled = true + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } + + buildFeatures { + buildConfig = true + } +} + +dependencies { + implementation(project(":library")) + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + implementation(libs.androidx.activity) + implementation(libs.androidx.constraintlayout) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/app/src/androidTest/java/com/yuanxuan/tracking_point/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/yuanxuan/tracking_point/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..fd5c46e --- /dev/null +++ b/app/src/androidTest/java/com/yuanxuan/tracking_point/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.yuanxuan.tracking_point + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.yuanxuan.tracking_point", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e0e1728 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/yuanxuan/tracking_point/MainActivity.kt b/app/src/main/java/com/yuanxuan/tracking_point/MainActivity.kt new file mode 100644 index 0000000..9c68930 --- /dev/null +++ b/app/src/main/java/com/yuanxuan/tracking_point/MainActivity.kt @@ -0,0 +1,44 @@ +package com.yuanxuan.tracking_point + +import android.os.Bundle +import android.widget.TextView +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import androidx.lifecycle.lifecycleScope +import com.yuanxuan.tracking_point.library.http.bean.EventParams +import com.yuanxuan.tracking_point.library.TrackingManager +import kotlinx.coroutines.launch + +class MainActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContentView(R.layout.activity_main) + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> + val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) + insets + } + TrackingManager.init( + context = this.application, + iTrackingPointUserInfo = TrackingPointUserInfoImp(), + systemCode = "999999999", + ) + + findViewById(R.id.text).setOnClickListener { view -> + lifecycleScope.launch { + TrackingManager.push( + eventType = "dianji", + eventParams = EventParams( + buttonId = "${view.id}", + page = "Main", + url = "xxxx.xx" + ) + ) + } + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/yuanxuan/tracking_point/TrackingPointUserInfoImp.kt b/app/src/main/java/com/yuanxuan/tracking_point/TrackingPointUserInfoImp.kt new file mode 100644 index 0000000..18527ac --- /dev/null +++ b/app/src/main/java/com/yuanxuan/tracking_point/TrackingPointUserInfoImp.kt @@ -0,0 +1,14 @@ +package com.yuanxuan.tracking_point + +import com.yuanxuan.tracking_point.library.ITrackingPointUserInfo +import com.yuanxuan.tracking_point.library.http.bean.UserInfo + +class TrackingPointUserInfoImp: ITrackingPointUserInfo { + override fun uploadUserInfo(): UserInfo { + return UserInfo( + userId = 123456, + userName = "username", + account = "account" + ) + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..b33ddf5 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,20 @@ + + + +