react-native-quicktracking-analytics-module 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/QuicktrackingAnalyticsModule.podspec +29 -0
- package/README.md +211 -151
- package/android/build.gradle +40 -101
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/QTSDKManager.kt +112 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/QuicktrackingAnalyticsModuleModule.kt +259 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/QuicktrackingAnalyticsModulePackage.kt +17 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/property/QTViewProperties.kt +84 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/utils/QTLog.kt +119 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/utils/RNPropertyManager.kt +35 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/utils/RNTouchTargetHelper.kt +162 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/utils/RNUtils.kt +170 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/utils/RNViewUtils.kt +233 -0
- package/ios/QuicktrackingAnalyticsModule.h +1 -4
- package/ios/{QuicktrackingAnalyticsModule.m → QuicktrackingAnalyticsModule.mm} +144 -110
- package/lib/commonjs/hook.js +564 -0
- package/lib/commonjs/hook.js.map +1 -0
- package/lib/commonjs/index.js +276 -166
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/hook.js +564 -0
- package/lib/module/hook.js.map +1 -0
- package/lib/module/index.js +253 -164
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/index.d.ts +120 -79
- package/lib/typescript/index.d.ts.map +1 -0
- package/package.json +83 -67
- package/src/hook.js +3 -3
- package/src/index.tsx +266 -169
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -234
- package/android/gradlew.bat +0 -89
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/QTSDKManager.java +0 -93
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/QuicktrackingAnalyticsModule.java +0 -242
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/QuicktrackingAnalyticsModulePackage.java +0 -28
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/property/QTViewProperties.java +0 -48
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/QTLog.java +0 -122
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNPropertyManager.java +0 -29
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNTouchTargetHelper.java +0 -139
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNUtils.java +0 -188
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNViewUtils.java +0 -148
- package/ios/QuicktrackingAnalyticsModule.xcodeproj/project.pbxproj +0 -282
- package/ios/QuicktrackingAnalyticsModule.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/react-native-quicktracking-analytics-module.podspec +0 -37
package/android/build.gradle
CHANGED
|
@@ -1,49 +1,57 @@
|
|
|
1
1
|
buildscript {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
mavenCentral()
|
|
5
|
-
maven {url 'https://repo1.maven.org/maven2/'}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
dependencies {
|
|
9
|
-
classpath 'com.android.tools.build:gradle:3.5.3'
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['QuicktrackingAnalyticsModule_' + name]
|
|
10
4
|
}
|
|
11
|
-
}
|
|
12
5
|
|
|
13
|
-
allprojects {
|
|
14
6
|
repositories {
|
|
15
7
|
google()
|
|
16
8
|
mavenCentral()
|
|
17
9
|
maven { url 'https://repo1.maven.org/maven2/' }
|
|
18
10
|
}
|
|
19
|
-
}
|
|
20
11
|
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
dependencies {
|
|
13
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
14
|
+
// noinspection DifferentKotlinGradleVersion
|
|
15
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
16
|
+
}
|
|
23
17
|
}
|
|
24
18
|
|
|
25
|
-
apply plugin: 'com.android.library'
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
20
|
+
apply plugin: "com.android.library"
|
|
21
|
+
apply plugin: "kotlin-android"
|
|
30
22
|
|
|
31
|
-
def getExtOrDefault(name) {
|
|
32
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['QuicktrackingAnalyticsModule_' + name]
|
|
33
|
-
}
|
|
34
23
|
|
|
35
24
|
def getExtOrIntegerDefault(name) {
|
|
36
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties[
|
|
25
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["QuicktrackingAnalyticsModule_" + name]).toInteger()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
def supportsNamespace() {
|
|
29
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
30
|
+
def major = parsed[0].toInteger()
|
|
31
|
+
def minor = parsed[1].toInteger()
|
|
32
|
+
|
|
33
|
+
// Namespace support was added in 7.3.0
|
|
34
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
android {
|
|
40
|
-
|
|
38
|
+
if (supportsNamespace()) {
|
|
39
|
+
namespace "com.quicktrackinganalyticsmodule"
|
|
40
|
+
|
|
41
|
+
sourceSets {
|
|
42
|
+
main {
|
|
43
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
41
49
|
|
|
42
50
|
defaultConfig {
|
|
43
|
-
minSdkVersion getExtOrIntegerDefault(
|
|
44
|
-
targetSdkVersion getExtOrIntegerDefault(
|
|
45
|
-
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
51
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
52
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
46
53
|
}
|
|
54
|
+
|
|
47
55
|
buildTypes {
|
|
48
56
|
release {
|
|
49
57
|
minifyEnabled false
|
|
@@ -51,7 +59,7 @@ android {
|
|
|
51
59
|
}
|
|
52
60
|
|
|
53
61
|
lintOptions {
|
|
54
|
-
disable
|
|
62
|
+
disable "GradleCompatible"
|
|
55
63
|
}
|
|
56
64
|
|
|
57
65
|
compileOptions {
|
|
@@ -63,84 +71,15 @@ android {
|
|
|
63
71
|
repositories {
|
|
64
72
|
mavenCentral()
|
|
65
73
|
google()
|
|
66
|
-
|
|
67
|
-
def found = false
|
|
68
|
-
def defaultDir = null
|
|
69
|
-
def androidSourcesName = 'React Native sources'
|
|
70
|
-
|
|
71
|
-
if (rootProject.ext.has('reactNativeAndroidRoot')) {
|
|
72
|
-
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
|
|
73
|
-
} else {
|
|
74
|
-
defaultDir = new File(
|
|
75
|
-
projectDir,
|
|
76
|
-
'/../../../node_modules/react-native/android'
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (defaultDir.exists()) {
|
|
81
|
-
maven {
|
|
82
|
-
url defaultDir.toString()
|
|
83
|
-
name androidSourcesName
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
|
|
87
|
-
found = true
|
|
88
|
-
} else {
|
|
89
|
-
def parentDir = rootProject.projectDir
|
|
90
|
-
|
|
91
|
-
1.upto(5, {
|
|
92
|
-
if (found) return true
|
|
93
|
-
parentDir = parentDir.parentFile
|
|
94
|
-
|
|
95
|
-
def androidSourcesDir = new File(
|
|
96
|
-
parentDir,
|
|
97
|
-
'node_modules/react-native'
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
def androidPrebuiltBinaryDir = new File(
|
|
101
|
-
parentDir,
|
|
102
|
-
'node_modules/react-native/android'
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
if (androidPrebuiltBinaryDir.exists()) {
|
|
106
|
-
maven {
|
|
107
|
-
url androidPrebuiltBinaryDir.toString()
|
|
108
|
-
name androidSourcesName
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
|
|
112
|
-
found = true
|
|
113
|
-
} else if (androidSourcesDir.exists()) {
|
|
114
|
-
maven {
|
|
115
|
-
url androidSourcesDir.toString()
|
|
116
|
-
name androidSourcesName
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
|
|
120
|
-
found = true
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (!found) {
|
|
126
|
-
throw new GradleException(
|
|
127
|
-
"${project.name}: unable to locate React Native android sources. " +
|
|
128
|
-
"Ensure you have you installed React Native as a dependency in your project and try again."
|
|
129
|
-
)
|
|
130
|
-
}
|
|
74
|
+
maven { url 'https://repo1.maven.org/maven2/' }
|
|
131
75
|
}
|
|
132
76
|
|
|
77
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
78
|
+
|
|
133
79
|
dependencies {
|
|
134
|
-
|
|
135
|
-
implementation "
|
|
136
|
-
|
|
80
|
+
implementation "com.facebook.react:react-android"
|
|
81
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
82
|
+
// QuickTracking Android SDK
|
|
137
83
|
implementation "com.lydaas.qtsdk:qt-px-common:1.8.3.PX"
|
|
138
84
|
}
|
|
139
85
|
|
|
140
|
-
if (isNewArchitectureEnabled()) {
|
|
141
|
-
react {
|
|
142
|
-
jsRootDir = file("../src/")
|
|
143
|
-
libraryName = "QuicktrackingAnalyticsModule"
|
|
144
|
-
codegenJavaPackageName = "com.reactnativequicktrackinganalyticsmodule"
|
|
145
|
-
}
|
|
146
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
QuicktrackingAnalyticsModule_kotlinVersion=
|
|
2
|
-
QuicktrackingAnalyticsModule_minSdkVersion=
|
|
3
|
-
QuicktrackingAnalyticsModule_targetSdkVersion=
|
|
4
|
-
QuicktrackingAnalyticsModule_compileSdkVersion=
|
|
5
|
-
|
|
1
|
+
QuicktrackingAnalyticsModule_kotlinVersion=2.0.21
|
|
2
|
+
QuicktrackingAnalyticsModule_minSdkVersion=24
|
|
3
|
+
QuicktrackingAnalyticsModule_targetSdkVersion=34
|
|
4
|
+
QuicktrackingAnalyticsModule_compileSdkVersion=35
|
|
5
|
+
QuicktrackingAnalyticsModule_ndkVersion=27.1.12297006
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
package com.quicktrackinganalyticsmodule
|
|
2
|
+
|
|
3
|
+
import android.util.SparseArray
|
|
4
|
+
import android.view.MotionEvent
|
|
5
|
+
import android.view.ViewGroup
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap
|
|
8
|
+
import com.facebook.react.uimanager.JSTouchDispatcher
|
|
9
|
+
import com.facebook.react.uimanager.events.EventDispatcher
|
|
10
|
+
import com.quick.qt.analytics.QtTrackAgent
|
|
11
|
+
import com.quicktrackinganalyticsmodule.property.QTViewProperties
|
|
12
|
+
import com.quicktrackinganalyticsmodule.utils.*
|
|
13
|
+
import org.json.JSONObject
|
|
14
|
+
import java.lang.reflect.Field
|
|
15
|
+
import java.util.WeakHashMap
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Manager class for handling SDK operations and view tracking.
|
|
19
|
+
*/
|
|
20
|
+
object QTSDKManager {
|
|
21
|
+
private val jsTouchDispatcherViewGroupWeakHashMap = WeakHashMap<JSTouchDispatcher, ViewGroup>()
|
|
22
|
+
private val viewPropertiesArray = SparseArray<QTViewProperties>()
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Handles touch events for view tracking.
|
|
26
|
+
* @param jsTouchDispatcher The JS touch dispatcher
|
|
27
|
+
* @param event The motion event
|
|
28
|
+
* @param eventDispatcher The event dispatcher
|
|
29
|
+
*/
|
|
30
|
+
fun handleTouchEvent(
|
|
31
|
+
jsTouchDispatcher: JSTouchDispatcher,
|
|
32
|
+
event: MotionEvent,
|
|
33
|
+
eventDispatcher: EventDispatcher
|
|
34
|
+
) {
|
|
35
|
+
try {
|
|
36
|
+
if (event.action == MotionEvent.ACTION_DOWN) {
|
|
37
|
+
var viewGroup = jsTouchDispatcherViewGroupWeakHashMap[jsTouchDispatcher]
|
|
38
|
+
if (viewGroup == null) {
|
|
39
|
+
try {
|
|
40
|
+
val viewGroupField = jsTouchDispatcher.javaClass.getDeclaredField("mRootViewGroup")
|
|
41
|
+
viewGroupField.isAccessible = true
|
|
42
|
+
viewGroup = viewGroupField.get(jsTouchDispatcher) as? ViewGroup
|
|
43
|
+
viewGroup?.let {
|
|
44
|
+
jsTouchDispatcherViewGroupWeakHashMap[jsTouchDispatcher] = it
|
|
45
|
+
}
|
|
46
|
+
} catch (e: Exception) {
|
|
47
|
+
QTLog.printStackTrace(e)
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
val nativeTargetView = RNTouchTargetHelper.findTouchTargetView(
|
|
51
|
+
floatArrayOf(event.x, event.y),
|
|
52
|
+
viewGroup
|
|
53
|
+
)
|
|
54
|
+
val reactTargetView = RNTouchTargetHelper.findClosestReactAncestor(nativeTargetView)
|
|
55
|
+
RNViewUtils.setOnTouchView(reactTargetView ?: nativeTargetView)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} catch (e: Exception) {
|
|
59
|
+
// Ignored
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Tracks a view click event.
|
|
65
|
+
* @param viewId The ID of the clicked view
|
|
66
|
+
* @param ctx The React application context
|
|
67
|
+
*/
|
|
68
|
+
fun trackViewClick(viewId: Int, ctx: ReactApplicationContext) {
|
|
69
|
+
try {
|
|
70
|
+
val clickView = RNViewUtils.getViewByTag(viewId)
|
|
71
|
+
QTLog.t("current clickView === $clickView")
|
|
72
|
+
if (clickView != null) {
|
|
73
|
+
val properties = JSONObject().apply {
|
|
74
|
+
RNViewUtils.getTitle()?.let { put("title", it) }
|
|
75
|
+
RNViewUtils.getScreenName()?.let { put("\$screen_name", it) }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
val viewProperties = viewPropertiesArray.get(viewId)
|
|
79
|
+
if (viewProperties?.properties != null && viewProperties.properties.length() > 0) {
|
|
80
|
+
//TODO: ignore 这个字段名是否需要重构
|
|
81
|
+
if (viewProperties.properties.optBoolean("ignore", false)) {
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
viewProperties.properties.remove("ignore")
|
|
85
|
+
RNUtils.mergeJSONObject(viewProperties.properties, properties)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
val eventID = RNUtils.MD5(viewId.toString())
|
|
89
|
+
val mergedProperties = RNPropertyManager.mergeProperty(properties, true)
|
|
90
|
+
val map = RNUtils.convertToMap(mergedProperties)
|
|
91
|
+
QtTrackAgent.onEventObject(ctx, eventID, map)
|
|
92
|
+
}
|
|
93
|
+
} catch (e: Exception) {
|
|
94
|
+
QTLog.printStackTrace(e)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Saves view properties for tracking.
|
|
100
|
+
* @param viewTag The tag of the view
|
|
101
|
+
* @param clickable Whether the view is clickable
|
|
102
|
+
* @param viewProperties The properties of the view
|
|
103
|
+
*/
|
|
104
|
+
fun saveViewProperties(viewTag: Int, clickable: Boolean, viewProperties: ReadableMap?) {
|
|
105
|
+
QTLog.t("currentView Tag === $viewTag")
|
|
106
|
+
QTLog.t("currentView clickable === $clickable")
|
|
107
|
+
if (clickable) {
|
|
108
|
+
QTLog.t("before invoke viewPropertiesArray")
|
|
109
|
+
viewPropertiesArray.put(viewTag, QTViewProperties(clickable, viewProperties))
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
package/android/src/main/java/com/quicktrackinganalyticsmodule/QuicktrackingAnalyticsModuleModule.kt
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
package com.quicktrackinganalyticsmodule
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.facebook.react.bridge.*
|
|
5
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
6
|
+
import com.facebook.react.bridge.ReactMethod
|
|
7
|
+
import com.facebook.react.bridge.Promise
|
|
8
|
+
import com.facebook.react.bridge.LifecycleEventListener
|
|
9
|
+
import com.quick.qt.commonsdk.QtConfigure
|
|
10
|
+
import com.quick.qt.analytics.QtTrackAgent
|
|
11
|
+
import com.quick.qt.spm.SpmAgent
|
|
12
|
+
import java.util.*
|
|
13
|
+
import com.quicktrackinganalyticsmodule.utils.*
|
|
14
|
+
|
|
15
|
+
class QuicktrackingAnalyticsModuleModule(reactContext: ReactApplicationContext) :
|
|
16
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
17
|
+
|
|
18
|
+
private val context: ReactApplicationContext = reactContext
|
|
19
|
+
|
|
20
|
+
init {
|
|
21
|
+
try {
|
|
22
|
+
reactContext.addLifecycleEventListener(QTDataLifecycleListener())
|
|
23
|
+
} catch (e: Exception) {
|
|
24
|
+
// Handle exception if needed
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override fun getName(): String {
|
|
29
|
+
return NAME
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//***************************** SDK 埋点相关 ****************************************************/
|
|
33
|
+
@ReactMethod
|
|
34
|
+
fun onPageStart(pageName: String) {
|
|
35
|
+
QtTrackAgent.onPageStart(pageName)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@ReactMethod
|
|
39
|
+
fun onPageEnd(pageName: String) {
|
|
40
|
+
QtTrackAgent.onPageEnd(pageName)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@ReactMethod
|
|
44
|
+
fun uploadPageProperties(pageName: String, property: ReadableMap) {
|
|
45
|
+
val map = HashMap<String, Any>()
|
|
46
|
+
val iterator = property.keySetIterator()
|
|
47
|
+
while (iterator.hasNextKey()) {
|
|
48
|
+
val key = iterator.nextKey()
|
|
49
|
+
when (property.getType(key)) {
|
|
50
|
+
ReadableType.Array -> map[key] = property.getArray(key).toString()
|
|
51
|
+
ReadableType.Boolean -> map[key] = property.getBoolean(key).toString()
|
|
52
|
+
ReadableType.Number -> map[key] = property.getInt(key).toString()
|
|
53
|
+
ReadableType.String -> map[key] = property.getString(key) ?: ""
|
|
54
|
+
ReadableType.Map -> map[key] = property.getMap(key).toString()
|
|
55
|
+
else -> {} // Handle other cases if needed
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
QtTrackAgent.setPageProperty(context, pageName, map)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@ReactMethod
|
|
62
|
+
fun onEvent(eventID: String) {
|
|
63
|
+
QtTrackAgent.onEvent(context, eventID)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@ReactMethod
|
|
67
|
+
fun onEventWithPageName(eventID: String, pageName: String) {
|
|
68
|
+
QtTrackAgent.onEvent(context, eventID, pageName)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@ReactMethod
|
|
72
|
+
fun onEventWithParams(eventID: String, property: ReadableMap) {
|
|
73
|
+
val map = convertReadableMapToMap(property)
|
|
74
|
+
QtTrackAgent.onEventObject(context, eventID, map)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@ReactMethod
|
|
78
|
+
fun onEventWithParamsAndPageName(eventID: String, property: ReadableMap, pageName: String) {
|
|
79
|
+
val map = convertReadableMapToMap(property)
|
|
80
|
+
QtTrackAgent.onEventObject(context, eventID, map, pageName)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@ReactMethod
|
|
84
|
+
fun onEventForH5(content: String) {
|
|
85
|
+
try {
|
|
86
|
+
Log.e(TAG, "ReactMethod:onEventForH5" + content)
|
|
87
|
+
SpmAgent.CALL(content)
|
|
88
|
+
} catch (e: Exception) {
|
|
89
|
+
Log.e(TAG, "桥接事件发送失败!", e)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@ReactMethod
|
|
94
|
+
fun onEventAutoCLK(viewId: Int) {
|
|
95
|
+
QTSDKManager.trackViewClick(viewId, context)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//***************************** SDK 属性 相关 *********************************************/
|
|
99
|
+
@ReactMethod
|
|
100
|
+
fun registerGlobalProperties(map: ReadableMap) {
|
|
101
|
+
try {
|
|
102
|
+
val nativeMap = map as ReadableNativeMap
|
|
103
|
+
val map3 = nativeMap.toHashMap()
|
|
104
|
+
val globalProperties = HashMap<String, Any>()
|
|
105
|
+
map3.forEach { (key, value) ->
|
|
106
|
+
globalProperties[key.toString()] = value as Any
|
|
107
|
+
}
|
|
108
|
+
QtTrackAgent.registerGlobalProperties(context, globalProperties)
|
|
109
|
+
} catch (e: Exception) {
|
|
110
|
+
Log.e(TAG, "注册全局属性失败!", e)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@ReactMethod
|
|
115
|
+
fun unregisterGlobalProperty(propertyName: String) {
|
|
116
|
+
if (propertyName.isNullOrEmpty()) return
|
|
117
|
+
QtTrackAgent.unregisterGlobalProperty(context, propertyName)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@ReactMethod
|
|
121
|
+
fun getGlobalProperty(propertyName: String, promise: Promise) {
|
|
122
|
+
try {
|
|
123
|
+
if (propertyName.isNullOrEmpty()) return
|
|
124
|
+
val result = QtTrackAgent.getGlobalProperty(context, propertyName).toString()
|
|
125
|
+
promise.resolve(result)
|
|
126
|
+
} catch (e: Exception) {
|
|
127
|
+
Log.e(TAG, "获取单个全局属性失败", e)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@ReactMethod
|
|
132
|
+
fun getGlobalProperties(promise: Promise) {
|
|
133
|
+
try {
|
|
134
|
+
val result = QtTrackAgent.getGlobalProperties(context)
|
|
135
|
+
promise.resolve(result)
|
|
136
|
+
} catch (e: Exception) {
|
|
137
|
+
Log.e(TAG, "获取所有全局属性失败", e)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@ReactMethod
|
|
142
|
+
fun clearGlobalProperties() {
|
|
143
|
+
QtTrackAgent.clearGlobalProperties(context)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
//***************************** SDK用户 相关 *********************************************/
|
|
147
|
+
|
|
148
|
+
@ReactMethod
|
|
149
|
+
fun profileSignIn(ID: String) {
|
|
150
|
+
QtTrackAgent.onProfileSignIn(ID)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@ReactMethod
|
|
154
|
+
fun profileSignInWithProvider(ID: String, Provider: String) {
|
|
155
|
+
// 原生层这个是反的,Provider在前,ID在后
|
|
156
|
+
QtTrackAgent.onProfileSignIn(Provider, ID)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@ReactMethod
|
|
160
|
+
fun profileSignOff() {
|
|
161
|
+
QtTrackAgent.onProfileSignOff()
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
//***************************** SDK初始化 相关 *********************************************/
|
|
165
|
+
|
|
166
|
+
@ReactMethod
|
|
167
|
+
fun preInit(appkey: String, channel: String) {
|
|
168
|
+
QtConfigure.preInit(context, appkey, channel);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
@ReactMethod
|
|
172
|
+
fun initWithAppkey(appkey: String, channel: String) {
|
|
173
|
+
QtConfigure.init(context, appkey, channel, QtConfigure.DEVICE_TYPE_PHONE, "")
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@ReactMethod
|
|
177
|
+
fun setTrackDomain(primaryDomain: String, secondaryDomain: String) {
|
|
178
|
+
QtConfigure.setCustomDomain(primaryDomain, secondaryDomain);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@ReactMethod
|
|
182
|
+
fun enableLog(flag: Boolean) {
|
|
183
|
+
QtConfigure.setLogEnabled(flag);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@ReactMethod
|
|
187
|
+
fun setAppVersion(version: String, appVersionCode: Int) {
|
|
188
|
+
QtConfigure.setAppVersion(version, appVersionCode)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//***************************** SDK 其他 *********************************************/
|
|
192
|
+
|
|
193
|
+
@ReactMethod
|
|
194
|
+
fun disableSDK() {
|
|
195
|
+
QtTrackAgent.disableSDK()
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
@ReactMethod
|
|
199
|
+
fun enableSDK() {
|
|
200
|
+
QtTrackAgent.enableSDK()
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@ReactMethod
|
|
204
|
+
fun setCustomDeviceId(deviceId: String) {
|
|
205
|
+
QtConfigure.setCustomDeviceId(context, deviceId);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
@ReactMethod
|
|
209
|
+
fun getDeviceId(promise: Promise) {
|
|
210
|
+
try {
|
|
211
|
+
val deviceId = QtConfigure.getUMIDString(context);
|
|
212
|
+
promise.resolve(deviceId)
|
|
213
|
+
} catch (e: Exception) {
|
|
214
|
+
promise.reject("getDeviceId", e.message)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
@ReactMethod
|
|
219
|
+
fun saveViewProperties(viewId: Int, clickable: Boolean, viewProperties: ReadableMap?) {
|
|
220
|
+
QTSDKManager.saveViewProperties(viewId, clickable, viewProperties)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private fun convertReadableMapToMap(property: ReadableMap): Map<String, Any> {
|
|
224
|
+
val map = HashMap<String, Any>()
|
|
225
|
+
val iterator = property.keySetIterator()
|
|
226
|
+
while (iterator.hasNextKey()) {
|
|
227
|
+
val key = iterator.nextKey()
|
|
228
|
+
when (property.getType(key)) {
|
|
229
|
+
ReadableType.Array -> map[key] = property.getArray(key).toString()
|
|
230
|
+
ReadableType.Boolean -> map[key] = property.getBoolean(key).toString()
|
|
231
|
+
ReadableType.Number -> map[key] = property.getInt(key).toString()
|
|
232
|
+
ReadableType.String -> map[key] = property.getString(key) ?: ""
|
|
233
|
+
ReadableType.Map -> map[key] = property.getMap(key).toString()
|
|
234
|
+
else -> {} // Handle other cases if needed
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return map
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
inner class QTDataLifecycleListener : LifecycleEventListener {
|
|
241
|
+
override fun onHostResume() {
|
|
242
|
+
RNViewUtils.getCurrentActivity()?.let { RNViewUtils.onActivityResumed(it) }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
override fun onHostPause() {
|
|
246
|
+
RNViewUtils.onActivityPaused()
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
override fun onHostDestroy() {
|
|
250
|
+
// Implementation will be added later
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
companion object {
|
|
255
|
+
const val NAME = "QuicktrackingAnalyticsModule"
|
|
256
|
+
const val TAG = "[QT_RN] ------ "
|
|
257
|
+
}
|
|
258
|
+
//***************************** 其他 ****************************************************/
|
|
259
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.quicktrackinganalyticsmodule
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class QuicktrackingAnalyticsModulePackage : ReactPackage {
|
|
10
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
11
|
+
return listOf(QuicktrackingAnalyticsModuleModule(reactContext))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
15
|
+
return emptyList()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
package com.quicktrackinganalyticsmodule.property
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import android.view.View
|
|
6
|
+
import android.widget.ScrollView
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap
|
|
8
|
+
import com.quicktrackinganalyticsmodule.utils.RNUtils
|
|
9
|
+
import org.json.JSONObject
|
|
10
|
+
import java.util.concurrent.atomic.AtomicInteger
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Class for managing view properties in React Native tracking.
|
|
14
|
+
* @property clickable Whether the view is clickable
|
|
15
|
+
* @property properties JSON properties associated with the view
|
|
16
|
+
*/
|
|
17
|
+
class QTViewProperties(
|
|
18
|
+
private val clickable: Boolean,
|
|
19
|
+
params: ReadableMap?
|
|
20
|
+
) {
|
|
21
|
+
companion object {
|
|
22
|
+
const val TAG = "QuickTracking == "
|
|
23
|
+
private const val VIEW_TAG_KEY_NAME = "qt_rn_tag_view_rn_key"
|
|
24
|
+
private val viewTagKey = AtomicInteger(0)
|
|
25
|
+
private val viewTagKeyCache = mutableMapOf<String, Int>()
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Gets the view tag key for the given context.
|
|
29
|
+
* @param context The context to get the resource ID from
|
|
30
|
+
* @return The resource ID for the view tag key
|
|
31
|
+
*/
|
|
32
|
+
private fun getViewTagKey(context: Context): Int {
|
|
33
|
+
val packageName = context.packageName
|
|
34
|
+
return viewTagKeyCache.getOrPut(packageName) {
|
|
35
|
+
context.resources.getIdentifier(
|
|
36
|
+
VIEW_TAG_KEY_NAME,
|
|
37
|
+
"id",
|
|
38
|
+
packageName
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
val properties: JSONObject? = RNUtils.convertToJSONObject(params)
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Sets the clickable property of the view.
|
|
48
|
+
* @param view The view to set clickable property
|
|
49
|
+
*/
|
|
50
|
+
fun setViewClickable(view: View?) {
|
|
51
|
+
try {
|
|
52
|
+
if (view != null && view !is ScrollView) {
|
|
53
|
+
view.isClickable = clickable
|
|
54
|
+
}
|
|
55
|
+
} catch (e: Exception) {
|
|
56
|
+
Log.e(TAG, "设置viewClickable失败: ${e.message}")
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Sets the view tag for tracking.
|
|
62
|
+
* @param view The view to set tag
|
|
63
|
+
*/
|
|
64
|
+
fun setViewTag(view: View?) {
|
|
65
|
+
try {
|
|
66
|
+
if (view == null) return
|
|
67
|
+
|
|
68
|
+
if (viewTagKey.get() == 0) {
|
|
69
|
+
val context = view.context
|
|
70
|
+
viewTagKey.set(context.resources.getIdentifier(
|
|
71
|
+
"qt_rn_tag_view_rn_key",
|
|
72
|
+
"id",
|
|
73
|
+
context.packageName
|
|
74
|
+
));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (viewTagKey.get() != 0) {
|
|
78
|
+
view.setTag(viewTagKey.get(), true)
|
|
79
|
+
}
|
|
80
|
+
} catch (e: Exception) {
|
|
81
|
+
Log.e(TAG, "设置viewTag失败: ${e.message}")
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|