@rk911/tracker-sdk 1.7.0 → 1.7.1

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.
@@ -63,7 +63,15 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
63
63
  */
64
64
  public void init(Application app, String serverUrl, String deviceId, String userId, String phone, String storeName) {
65
65
  this.application = app;
66
- this.serverUrl = serverUrl;
66
+ if (serverUrl != null && !serverUrl.contains("/api/point/task/trackBatch")) {
67
+ if (serverUrl.endsWith("/")) {
68
+ this.serverUrl = serverUrl + "api/point/task/trackBatch";
69
+ } else {
70
+ this.serverUrl = serverUrl + "/api/point/task/trackBatch";
71
+ }
72
+ } else {
73
+ this.serverUrl = serverUrl;
74
+ }
67
75
  this.deviceId = deviceId;
68
76
  this.userId = userId;
69
77
  this.phone = phone;
@@ -80,7 +88,7 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
80
88
 
81
89
  // 启动定时 Flush 任务
82
90
  scheduleTimerFlush();
83
- Log.d(TAG, "AndroidTracker initialized with sessionId: " + sessionId);
91
+ Log.d(TAG, "AndroidTracker initialized with sessionId: " + sessionId + ", serverUrl: " + this.serverUrl);
84
92
  }
85
93
 
86
94
  public void updateUser(String userId, String phone, String storeName) {
@@ -143,6 +151,13 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
143
151
  event.put("sequence", sequence);
144
152
  event.put("pageRoute", currentPageRoute);
145
153
  event.put("os", "Android");
154
+
155
+ JSONObject extra = new JSONObject();
156
+ if (!TextUtils.isEmpty(phone)) extra.put("phone", phone);
157
+ if (!TextUtils.isEmpty(storeName)) extra.put("storeName", storeName);
158
+ if (!TextUtils.isEmpty(userId)) extra.put("userId", userId);
159
+ extra.put("platform", "android");
160
+ event.put("extraData", extra.toString());
146
161
  return event;
147
162
  }
148
163
 
@@ -189,9 +204,9 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
189
204
  body.put("appId", Integer.parseInt(appId));
190
205
  body.put("sessionId", sessionId);
191
206
  body.put("deviceId", deviceId);
192
- body.put("userId", userId);
193
- body.put("phone", phone);
194
- body.put("storeName", storeName);
207
+ body.put("userId", userId != null ? userId : "");
208
+ body.put("phone", phone != null ? phone : "");
209
+ body.put("storeName", storeName != null ? storeName : "");
195
210
  body.put("platform", "android");
196
211
 
197
212
  JSONArray eventsArr = new JSONArray();
@@ -204,6 +219,8 @@ public class AndroidTracker implements Application.ActivityLifecycleCallbacks {
204
219
  conn = (HttpURLConnection) url.openConnection();
205
220
  conn.setRequestMethod("POST");
206
221
  conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
222
+ conn.setRequestProperty("appId", appId);
223
+ conn.setRequestProperty("deviceId", deviceId != null ? deviceId : "");
207
224
  conn.setDoOutput(true);
208
225
  conn.setConnectTimeout(5000);
209
226
  conn.setReadTimeout(5000);
@@ -28,7 +28,15 @@ import UIKit
28
28
  }
29
29
 
30
30
  @objc public func initSDK(serverUrl: String, deviceId: String, userId: String, phone: String, storeName: String) {
31
- self.serverUrl = serverUrl
31
+ if !serverUrl.contains("/api/point/task/trackBatch") {
32
+ if serverUrl.hasSuffix("/") {
33
+ self.serverUrl = serverUrl + "api/point/task/trackBatch"
34
+ } else {
35
+ self.serverUrl = serverUrl + "/api/point/task/trackBatch"
36
+ }
37
+ } else {
38
+ self.serverUrl = serverUrl
39
+ }
32
40
  self.deviceId = deviceId.isEmpty ? (UIDevice.current.identifierForVendor?.uuidString ?? "") : deviceId
33
41
  self.userId = userId
34
42
  self.phone = phone
@@ -66,13 +74,23 @@ import UIKit
66
74
 
67
75
  private func createBaseEvent(eventType: String, eventName: String) -> [String: Any] {
68
76
  sequence += 1
77
+ var extra: [String: Any] = ["platform": "ios"]
78
+ if !phone.isEmpty { extra["phone"] = phone }
79
+ if !storeName.isEmpty { extra["storeName"] = storeName }
80
+ if !userId.isEmpty { extra["userId"] = userId }
81
+ var extraStr = ""
82
+ if let data = try? JSONSerialization.data(withJSONObject: extra), let str = String(data: data, encoding: .utf8) {
83
+ extraStr = str
84
+ }
85
+
69
86
  var event: [String: Any] = [
70
87
  "eventId": "e_\(Int(Date().timeIntervalSince1970 * 1000))_\(Int.random(in: 1000...9999))",
71
88
  "eventType": eventType,
72
89
  "eventName": eventName,
73
90
  "timestamp": Int(Date().timeIntervalSince1970 * 1000),
74
91
  "sequence": sequence,
75
- "os": "iOS"
92
+ "os": "iOS",
93
+ "extraData": extraStr
76
94
  ]
77
95
  return event
78
96
  }
@@ -106,6 +124,8 @@ import UIKit
106
124
  var request = URLRequest(url: url)
107
125
  request.httpMethod = "POST"
108
126
  request.setValue("application/json; charset=UTF-8", forHTTPHeaderField: "Content-Type")
127
+ request.setValue(appId, forHTTPHeaderField: "appId")
128
+ request.setValue(deviceId, forHTTPHeaderField: "deviceId")
109
129
 
110
130
  let body: [String: Any] = [
111
131
  "appId": Int(appId) ?? 13,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rk911/tracker-sdk",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "人康多端埋点 SDK — 跨端自动化采集 + 手动埋点双写兼容",
5
5
  "main": "index.js",
6
6
  "module": "index.js",