tagworks-sdk-v1-react 1.1.13 → 1.1.15

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.
@@ -1,323 +1,402 @@
1
- package com.tagworks_sdk_react
2
-
3
- import android.util.Log
4
- import com.facebook.react.bridge.Arguments
5
- import com.facebook.react.bridge.Callback
6
- import com.facebook.react.bridge.ReactApplicationContext
7
- import com.facebook.react.bridge.ReactContextBaseJavaModule
8
- import com.facebook.react.bridge.ReactMethod
9
- import com.facebook.react.bridge.ReadableMap
10
- import com.obzen.tagworks.TagWorks
11
- import com.obzen.tagworks.TagWorksConfig
12
- import com.obzen.tagworks.data.DataBundle
13
- import com.obzen.tagworks.data.Dimension
14
- import com.obzen.tagworks.data.DimensionType
15
- import com.obzen.tagworks.util.Logger
16
- import com.obzen.tagworks.util.Logger.Companion.d
17
- import com.obzen.tagworks.util.WebAppInterface.Companion.MessageHandlerName
18
- import org.json.JSONArray
19
- import org.json.JSONObject
20
-
21
- class TagWorksModule(reactContext: ReactApplicationContext):ReactContextBaseJavaModule(reactContext) {
22
-
23
- /**
24
- * js에서 호출하는 TagWorksModule 네이밍
25
- */
26
- override fun getName(): String {
27
- return "TagWorksModule"
28
- }
29
-
30
- /**
31
- * config SDK 초기화 함수
32
- */
33
- @ReactMethod
34
- fun initializeTagWorks(
35
- siteId:String,
36
- baseUrl:String,
37
- isUseIntervals:Boolean,
38
- dispatchInterval:Double,
39
- sessionTimeout:Double,
40
- isManualDispatch:Boolean,
41
- appVersion:String?,
42
- appName:String?
43
- ) {
44
- val config = TagWorksConfig.Builder()
45
- .setSiteId(siteId)
46
- .setBaseUrl(baseUrl)
47
- .setDispatchInterval(dispatchInterval.toLong())
48
- .setSessionTimeOut(sessionTimeout.toLong() * 1000)
49
- .setAppVersion(appVersion)
50
- .setAppName(appName)
51
- .setManualDispatch(isManualDispatch)
52
- .setIsUseIntervals(isUseIntervals)
53
- .build()
54
-
55
- TagWorks.initializeSdk(reactApplicationContext, config)
56
-
57
- }
58
-
59
-
60
- /**
61
- * siteId, baseUrl SDK 초기화 함수
62
- */
63
- @ReactMethod
64
- fun initTagWorksWithSiteIdAndBaseUrl(siteId: String,baseUrl: String) {
65
- TagWorks.initializeSdk(reactApplicationContext,siteId,baseUrl)
66
- }
67
-
68
-
69
- @ReactMethod
70
- fun setLogLevel(level:Int) {
71
- TagWorks.getInstance().setLogLevel(level)
72
- }
73
-
74
- @ReactMethod
75
- fun setOptOut(isOptOut:Boolean) {
76
- TagWorks.getInstance().optOut = isOptOut
77
- }
78
-
79
- @ReactMethod
80
- fun setUserId(userId:String) {
81
- TagWorks.getInstance().userId = userId
82
- }
83
-
84
- @ReactMethod
85
- fun setVisitorId(visitorId:String) {
86
- TagWorks.getInstance().setVisitorId(visitorId)
87
- }
88
-
89
- @ReactMethod
90
- fun getVisitorId(callback: Callback) {
91
- try {
92
- callback.invoke(TagWorks.getInstance().getVisitorId())
93
- }catch (e:Exception) {
94
- callback.invoke("error :",e.message)
95
- }
96
- }
97
-
98
- @ReactMethod
99
- fun getSiteId(callback: Callback) {
100
- try {
101
- callback.invoke(TagWorks.getInstance().getSiteId())
102
- } catch (e:Exception) {
103
- callback.invoke("error :",e.message)
104
- }
105
- }
106
-
107
-
108
- /**
109
- * 공용 dimension 설정
110
- */
111
-
112
-
113
- @ReactMethod
114
- fun setCommonDimensionWithDouble(index: Int,numValue:Double) {
115
- TagWorks.getInstance().setCommonDimension(index,numValue)
116
- }
117
-
118
- @ReactMethod
119
- fun setCommonDimensionWithString(index: Int,value:String) {
120
- TagWorks.getInstance().setCommonDimension(index,value)
121
- }
122
-
123
-
124
-
125
- @ReactMethod
126
- fun getCommonDimensions(callback: Callback) {
127
-
128
- try {
129
- val commonDimensions = TagWorks.getInstance().getDimensions()
130
-
131
- val generalDimensions = JSONObject()
132
- val factDimensions = JSONObject()
133
-
134
- commonDimensions.forEach { dimension ->
135
- when (dimension.type) {
136
- DimensionType.GENERAL_TYPE -> generalDimensions.put(dimension.index.toString(),dimension.value)
137
- DimensionType.FACT_TYPE -> factDimensions.put(dimension.index.toString(),dimension.numValue)
138
- }
139
- }
140
-
141
- val generalWrapper = JSONObject().apply {
142
- put("General", generalDimensions)
143
- }
144
-
145
- val factWrapper = JSONObject().apply {
146
- put("Fact", factDimensions)
147
- }
148
-
149
- val dimensionsArray = JSONArray().apply {
150
- put(generalWrapper)
151
- put(factWrapper)
152
- }
153
-
154
- val result = JSONObject().apply {
155
- put("Dimensions", dimensionsArray)
156
- }
157
-
158
- val jsonString = result.toString(4)
159
-
160
- callback.invoke(jsonString)
161
- } catch (e: Exception) {
162
- // 오류 처리
163
- e.printStackTrace()
164
- callback.invoke(null)
165
- }
166
-
167
-
168
- }
169
-
170
- @ReactMethod
171
- fun getCommonDimensionsOfArrayIndex(callback: Callback) {
172
- try {
173
- val commonDimensions = TagWorks.getInstance().getDimensions()
174
- Log.d(TAG, "getCommonDimensionsOfArrayIndex: ${commonDimensions}")
175
- val dimensions = JSONArray()
176
-
177
- commonDimensions.forEach { dimension ->
178
- val dimensionObject = JSONObject()
179
- if (dimension.type == DimensionType.FACT_TYPE) {
180
- dimensionObject.put("Fact_${dimension.index}", dimension.numValue)
181
- } else if (dimension.type == DimensionType.GENERAL_TYPE) {
182
- dimensionObject.put("General_${dimension.index}", dimension.value)
183
- }
184
- dimensions.put(dimensionObject)
185
- }
186
- val jsonString = dimensions.toString(4)
187
- callback.invoke(jsonString)
188
- }catch (e:Exception) {
189
- callback.invoke(null)
190
- }
191
- }
192
-
193
- @ReactMethod
194
- fun getCommonDimensionWithString(index: Int,callback: Callback) {
195
- val mCommonDimension = TagWorks.getInstance().getCommonDimension(DimensionType.GENERAL_TYPE,index)
196
- if (mCommonDimension != null) callback.invoke(mCommonDimension.value)
197
- else callback.invoke(null)
198
- }
199
-
200
- @ReactMethod
201
- fun getCommonDimensionWithDouble(index: Int,callback: Callback) {
202
- val mCommonDimension = TagWorks.getInstance().getCommonDimension(DimensionType.FACT_TYPE,index)
203
- if (mCommonDimension != null) callback.invoke(mCommonDimension.numValue)
204
- else callback.invoke(null)
205
- }
206
-
207
- @ReactMethod
208
- fun removeCommonDimensionInGeneralType(index: Int) {
209
- TagWorks.getInstance().removeCommonDimension(DimensionType.GENERAL_TYPE,index)
210
- }
211
-
212
- @ReactMethod
213
- fun removeCommonDimensionInFactType(index: Int) {
214
- TagWorks.getInstance().removeCommonDimension(DimensionType.FACT_TYPE,index)
215
- }
216
-
217
- @ReactMethod
218
- fun removeAllCommonDimension() {
219
- TagWorks.getInstance().removeAllCommonDimension()
220
- }
221
-
222
- @ReactMethod
223
- fun removeCommonDimensionWithArrayIndex(index:Int) {
224
- TagWorks.getInstance().removeCommonDimensionWithArrayIndex(index)
225
- }
226
-
227
-
228
- @ReactMethod
229
- fun dispatch(callback: Callback) {
230
- val result = TagWorks.getInstance().dispatch()
231
- callback.invoke(result)
232
- }
233
-
234
- @ReactMethod
235
- fun sendReferrerEventWithOpenUrlString(openUrl: String) {
236
- TagWorks.getInstance().sendReferrerEvent(openUrl)
237
- }
238
-
239
-
240
- @ReactMethod
241
- fun logEvent(eventType:String,data:ReadableMap,callback: Callback) {
242
-
243
- val bundle = DataBundle()
244
-
245
- val dataBundleMap = data.getMap("dataBundle")
246
- dataBundleMap?.let {
247
- val keySetIterator = it.keySetIterator()
248
- while (keySetIterator.hasNextKey()) {
249
- val key = keySetIterator.nextKey()
250
- bundle.putString(key,it.getString(key))
251
- }
252
- }
253
-
254
- val dimensionsArray = data.getArray("dimensions")
255
- dimensionsArray?.let {
256
- for (i in 0 until it.size()) {
257
- val dimensionMap = it.getMap(i)
258
- val type = dimensionMap.getString("type")
259
- val index = dimensionMap.getInt("index")
260
- val value = dimensionMap.getString("value")
261
- val numValue = dimensionMap.getDouble("numValue")
262
-
263
- bundle.setDimension(Dimension(DimensionType.valueOf(type!!),index,value,numValue))
264
- }
265
- }
266
-
267
- Log.d(TAG, "logEvent: ${bundle.dataBundle} + ${bundle.dimensions}")
268
- try {
269
-
270
- val result = TagWorks.getInstance().logEvent(eventType, bundle)
271
- callback.invoke(result)
272
-
273
- }catch (e:Exception) {
274
- Log.d(TAG, "log event error: ${e.message}")
275
- }
276
-
277
-
278
- }
279
-
280
- @ReactMethod
281
- fun webInterfaceDidReceive(jsonEventString: String) {
282
- d(MessageHandlerName,jsonEventString)
283
- try {
284
- val jsonObj = JSONObject(jsonEventString)
285
-
286
- val sender = if (jsonObj.isNull("e_a")) null else jsonObj.getString("e_a")
287
- if ( sender == "obzen") {
288
-
289
- val idSite = if (jsonObj.isNull("idsite")) null else jsonObj.getString("idsite")
290
- val url = if (jsonObj.isNull("url")) null else jsonObj.getString("url")
291
- val urlref = if (jsonObj.isNull("urlref")) null else jsonObj.getString("urlref")
292
- var eventCategory = if (jsonObj.isNull("e_c")) null else jsonObj.getString("e_c")
293
-
294
- if (eventCategory != null) {
295
- eventCategory =
296
- eventCategory.replace("{{vstor_id}}", TagWorks.getInstance().getVisitorId())
297
- }
298
-
299
- if (idSite != null && idSite != TagWorks.getInstance().getSiteId()) {
300
- Logger.i(MessageHandlerName, "WebView siteid is not equal App siteid!!")
301
- }
302
-
303
- TagWorks.getInstance().webInterfaceLogEventPush(
304
- idSite, url, urlref, eventCategory
305
- )
306
- }
307
-
308
- } catch (t: Throwable) {
309
- Logger.e(MessageHandlerName, "Could not parse malformed JSON: \"$jsonEventString\"");
310
- }
311
- }
312
-
313
- override fun getConstants(): MutableMap<String, Any> {
314
- return mutableMapOf(
315
- "EVENT_TYPE_PAGE" to TagWorks.EVENT_TYPE_PAGE,
316
- "EVENT_TYPE_USER_EVENT" to TagWorks.EVENT_TYPE_USER_EVENT,
317
- )
318
- }
319
-
320
- companion object {
321
- const val TAG = "TagWorksModule"
322
- }
323
- }
1
+ package com.tagworkssdkv1
2
+
3
+ import android.util.Log
4
+ import com.facebook.react.bridge.Callback
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
7
+ import com.facebook.react.bridge.ReactMethod
8
+ import com.facebook.react.bridge.ReadableMap
9
+ import com.obzen.tagworks.TagWorks
10
+ import com.obzen.tagworks.TagWorksConfig
11
+ import com.obzen.tagworks.data.DataBundle
12
+ import com.obzen.tagworks.data.Dimension
13
+ import com.obzen.tagworks.data.DimensionType
14
+ import com.obzen.tagworks.util.Logger
15
+ import com.obzen.tagworks.util.Logger.Companion.d
16
+ import com.obzen.tagworks.util.WebAppInterface.Companion.MessageHandlerName
17
+ import org.json.JSONArray
18
+ import org.json.JSONObject
19
+ import javax.security.auth.callback.Callback
20
+
21
+ class TagWorksModule(reactContext: ReactApplicationContext):ReactContextBaseJavaModule(reactContext) {
22
+
23
+ /**
24
+ * js에서 호출하는 TagWorksModule 네이밍
25
+ */
26
+ override fun getName(): String {
27
+ return "TagWorksModule"
28
+ }
29
+
30
+ /**
31
+ * config SDK 초기화 함수
32
+ */
33
+ @ReactMethod
34
+ fun initializeTagWorks(
35
+ siteId:String,
36
+ baseUrl:String,
37
+ isUseIntervals:Boolean,
38
+ dispatchInterval:Double,
39
+ sessionTimeout:Double,
40
+ isManualDispatch:Boolean,
41
+ appVersion:String?,
42
+ appName:String?,
43
+ isUseDynamicParameter:Boolean
44
+ ) {
45
+ val config = TagWorksConfig.Builder()
46
+ .setSiteId(siteId)
47
+ .setBaseUrl(baseUrl)
48
+ .setDispatchInterval(dispatchInterval.toLong())
49
+ .setSessionTimeOut(sessionTimeout.toLong()*1000)
50
+ .setAppVersion(appVersion)
51
+ .setAppName(appName)
52
+ .setManualDispatch(isManualDispatch)
53
+ .setIsUseIntervals(isUseIntervals)
54
+ .setIsUseDynamicParameter(isUseDynamicParameter)
55
+ .build()
56
+
57
+ TagWorks.initializeSdk(reactApplicationContext, config)
58
+
59
+ }
60
+
61
+
62
+ /**
63
+ * siteId, baseUrl SDK 초기화 함수
64
+ */
65
+ @ReactMethod
66
+ fun initTagWorksWithSiteIdAndBaseUrl(siteId: String,baseUrl: String) {
67
+ TagWorks.initializeSdk(reactApplicationContext,siteId,baseUrl)
68
+ }
69
+
70
+
71
+ @ReactMethod
72
+ fun setLogLevel(level:Int) {
73
+ TagWorks.getInstance().setLogLevel(level)
74
+ }
75
+
76
+ @ReactMethod
77
+ fun setOptOut(isOptOut:Boolean) {
78
+ TagWorks.getInstance().optOut = isOptOut
79
+ }
80
+
81
+ @ReactMethod
82
+ fun setUserId(userId:String) {
83
+ TagWorks.getInstance().userId = userId
84
+ }
85
+
86
+ @ReactMethod
87
+ fun setVisitorId(visitorId:String) {
88
+ TagWorks.getInstance().visitorId =visitorId
89
+ }
90
+
91
+ @ReactMethod
92
+ fun setAdId(adId:String) {
93
+ TagWorks.getInstance().adId = adId
94
+ }
95
+
96
+ @ReactMethod
97
+ fun getAdId(callback: Callback) {
98
+ try {
99
+ callback.invoke(TagWorks.getInstance().adId)
100
+ }catch (e:Exception) {
101
+ callback.invoke("error :",e.message)
102
+ }
103
+ }
104
+
105
+ @ReactMethod
106
+ fun getVisitorId(callback: Callback) {
107
+ try {
108
+ callback.invoke(TagWorks.getInstance().visitorId)
109
+ }catch (e:Exception) {
110
+ callback.invoke("error :",e.message)
111
+ }
112
+ }
113
+
114
+ @ReactMethod
115
+ fun getSiteId(callback: Callback) {
116
+ try {
117
+ callback.invoke(TagWorks.getInstance().siteId)
118
+ } catch (e:Exception) {
119
+ callback.invoke("error :",e.message)
120
+ }
121
+ }
122
+
123
+
124
+ /**
125
+ * 공용 dimension 설정
126
+ */
127
+
128
+
129
+ @ReactMethod
130
+ fun setCommonDimensionWithDouble(index: Int,numValue:Double) {
131
+ TagWorks.getInstance().setCommonDimension(index,numValue)
132
+ }
133
+
134
+ @ReactMethod
135
+ fun setCommonDimensionWithString(index: Int,value:String) {
136
+ TagWorks.getInstance().setCommonDimension(index,value)
137
+ }
138
+
139
+ @ReactMethod
140
+ fun setDynamicCommonDimensionWithDouble(key:String, numValue: Double) {
141
+ TagWorks.getInstance().setDynamicCommonDimension(key,numValue)
142
+ }
143
+
144
+ @ReactMethod
145
+ fun setDynamicCommonDimensionWithString(key: String, value:String) {
146
+ TagWorks.getInstance().setDynamicCommonDimension(key,value)
147
+ }
148
+
149
+
150
+ @ReactMethod
151
+ fun getCommonDimensions(callback: Callback) {
152
+
153
+ try {
154
+ val cDimensions = TagWorks.getInstance().getCommonDimensions()
155
+ val cDynamicDimensions = TagWorks.getInstance().getDynamicCommonDimensions()
156
+
157
+ val generalDimensions = JSONObject()
158
+ val factDimensions = JSONObject()
159
+
160
+ cDimensions.forEach { dimension ->
161
+ when (dimension.type) {
162
+ DimensionType.GENERAL_TYPE -> generalDimensions.put(dimension.index.toString(),dimension.value)
163
+ DimensionType.FACT_TYPE -> factDimensions.put(dimension.index.toString(),dimension.numValue)
164
+ }
165
+ }
166
+
167
+ cDynamicDimensions.forEach { dimension ->
168
+ when (dimension.type) {
169
+ DimensionType.GENERAL_TYPE -> generalDimensions.put(dimension.key,dimension.value)
170
+ DimensionType.FACT_TYPE -> factDimensions.put(dimension.key,dimension.numValue)
171
+ }
172
+ }
173
+
174
+ val generalWrapper = JSONObject().apply {
175
+ put("General", generalDimensions)
176
+ }
177
+
178
+ val factWrapper = JSONObject().apply {
179
+ put("Fact", factDimensions)
180
+ }
181
+
182
+ val dimensionsArray = JSONArray().apply {
183
+ put(generalWrapper)
184
+ put(factWrapper)
185
+ }
186
+
187
+ val result = JSONObject().apply {
188
+ put("Dimensions", dimensionsArray)
189
+ }
190
+
191
+ val jsonString = result.toString(4)
192
+
193
+ callback.invoke(jsonString)
194
+ } catch (e: Exception) {
195
+ // 오류 처리
196
+ e.printStackTrace()
197
+ callback.invoke(null)
198
+ }
199
+
200
+
201
+ }
202
+
203
+
204
+ @ReactMethod
205
+ fun getCommonDimensionsOfArrayIndex(callback: Callback) {
206
+ try {
207
+ val cDimensions = TagWorks.getInstance().getCommonDimensions()
208
+ val dimensions = JSONArray()
209
+
210
+ cDimensions.forEach { dimension ->
211
+ val dimensionObject = JSONObject()
212
+ if (dimension.type == DimensionType.FACT_TYPE) {
213
+ dimensionObject.put("Fact_${dimension.index}", dimension.numValue)
214
+ } else if (dimension.type == DimensionType.GENERAL_TYPE) {
215
+ dimensionObject.put("General_${dimension.index}", dimension.value)
216
+ }
217
+ dimensions.put(dimensionObject)
218
+ }
219
+ val jsonString = dimensions.toString(4)
220
+ callback.invoke(jsonString)
221
+ }catch (e:Exception) {
222
+ callback.invoke(null)
223
+ }
224
+ }
225
+
226
+ @ReactMethod
227
+ fun getCommonDimensionWithString(index: Int,callback: Callback) {
228
+ val mCommonDimension = TagWorks.getInstance().getCommonDimension(DimensionType.GENERAL_TYPE,index)
229
+ if (mCommonDimension != null) callback.invoke(mCommonDimension.value)
230
+ else callback.invoke(null)
231
+ }
232
+
233
+ @ReactMethod
234
+ fun getCommonDimensionWithDouble(index: Int,callback: Callback) {
235
+ val mCommonDimension = TagWorks.getInstance().getCommonDimension(DimensionType.FACT_TYPE,index)
236
+ if (mCommonDimension != null) callback.invoke(mCommonDimension.numValue)
237
+ else callback.invoke(null)
238
+ }
239
+
240
+ @ReactMethod
241
+ fun getDynamicCommonDimension(key: String, callback: Callback) {
242
+ val mCommonDimension = TagWorks.getInstance().getDynamicCommonDimension(key)
243
+ if(mCommonDimension != null) callback.invoke(if(mCommonDimension.type==DimensionType.GENERAL_TYPE) mCommonDimension.value else mCommonDimension.numValue)
244
+ else callback.invoke(null)
245
+ }
246
+
247
+ @ReactMethod
248
+ fun getDynamicCommonDimensionsOfArrayIndex(callback: Callback) {
249
+ try {
250
+ val cDynamicDimensions = TagWorks.getInstance().getDynamicCommonDimensions()
251
+ val dimensions = JSONArray()
252
+
253
+ cDynamicDimensions.forEach { dimension ->
254
+ val dimensionObject = JSONObject()
255
+ if (dimension.type == DimensionType.GENERAL_TYPE) {
256
+ dimensionObject.put(dimension.key,dimension.value)
257
+ }else{
258
+ dimensionObject.put(dimension.key,dimension.numValue)
259
+ }
260
+ dimensions.put(dimensionObject)
261
+ }
262
+ val jsonString = dimensions.toString(4)
263
+ callback.invoke(jsonString)
264
+ }catch (e:Exception) {
265
+ callback.invoke(null)
266
+ }
267
+ }
268
+
269
+
270
+ @ReactMethod
271
+ fun removeCommonDimensionInGeneralType(index: Int) {
272
+ TagWorks.getInstance().removeCommonDimension(DimensionType.GENERAL_TYPE,index)
273
+ }
274
+
275
+ @ReactMethod
276
+ fun removeCommonDimensionInFactType(index: Int) {
277
+ TagWorks.getInstance().removeCommonDimension(DimensionType.FACT_TYPE,index)
278
+ }
279
+
280
+ @ReactMethod
281
+ fun removeDynamicCommonDimension(key: String) {
282
+ TagWorks.getInstance().removeDynamicCommonDimension(key)
283
+ }
284
+
285
+ @ReactMethod
286
+ fun removeCommonDimensionWithArrayIndex(index:Int) {
287
+ TagWorks.getInstance().removeCommonDimensionWithArrayIndex(index)
288
+ }
289
+
290
+ @ReactMethod
291
+ fun removeDynamicCommonDimensionWithArrayIndex(index: Int) {
292
+ TagWorks.getInstance().removeDynamicCommonDimensionWithArrayIndex(index)
293
+ }
294
+
295
+ @ReactMethod
296
+ fun removeAllCommonDimension() {
297
+ TagWorks.getInstance().removeAllCommonDimension()
298
+ }
299
+
300
+ @ReactMethod
301
+ fun removeAllDynamicCommonDimension() {
302
+ TagWorks.getInstance().removeAllCommonDimension()
303
+ }
304
+
305
+ @ReactMethod
306
+ fun dispatch(callback: Callback) {
307
+ val result = TagWorks.getInstance().dispatch()
308
+ callback.invoke(result)
309
+ }
310
+
311
+ @ReactMethod
312
+ fun sendReferrerEventWithOpenUrlString(openUrl: String) {
313
+ TagWorks.getInstance().sendReferrerEvent(openUrl)
314
+ }
315
+
316
+
317
+ @ReactMethod
318
+ fun logEvent(eventType:String,data:ReadableMap,callback: Callback) {
319
+
320
+ val bundle = DataBundle()
321
+
322
+ val dataBundleMap = data.getMap("dataBundle")
323
+ dataBundleMap?.let {
324
+ val keySetIterator = it.keySetIterator()
325
+ while (keySetIterator.hasNextKey()) {
326
+ val key = keySetIterator.nextKey()
327
+ bundle.putString(key,it.getString(key))
328
+ }
329
+ }
330
+
331
+ val dimensionsArray = data.getArray("dimensions")
332
+ dimensionsArray?.let {
333
+ for (i in 0 until it.size()) {
334
+ val dimensionMap = it.getMap(i)
335
+
336
+ val type = dimensionMap.getString("type")
337
+ val index = if (dimensionMap.hasKey("index")) dimensionMap.getInt("index") else -1
338
+ val key = if(dimensionMap.hasKey("key")) dimensionMap.getString("key") else index.toString()
339
+ val value = if(dimensionMap.hasKey("value")) dimensionMap.getString("value") else ""
340
+ val numValue = if(dimensionMap.hasKey("numValue")) dimensionMap.getDouble("numValue") else 0.0
341
+
342
+ bundle.setDimension(Dimension(DimensionType.valueOf(type!!),index,key!!,value!!,numValue))
343
+ }
344
+ }
345
+
346
+ Log.d(TAG, "logEvent: ${bundle.dataBundle} + ${bundle.dimensions}")
347
+ try {
348
+
349
+ val result = TagWorks.getInstance().logEvent(eventType, bundle)
350
+ callback.invoke(result)
351
+
352
+ }catch (e:Exception) {
353
+ Log.d(TAG, "log event error: ${e.message}")
354
+ }
355
+
356
+
357
+ }
358
+
359
+ @ReactMethod
360
+ fun webInterfaceDidReceive(jsonEventString: String) {
361
+ d(MessageHandlerName,jsonEventString)
362
+ try {
363
+ val jsonObj = JSONObject(jsonEventString)
364
+
365
+ val sender = if (jsonObj.isNull("e_a")) null else jsonObj.getString("e_a")
366
+ if ( sender == "obzen") {
367
+
368
+ val idSite = if (jsonObj.isNull("idsite")) null else jsonObj.getString("idsite")
369
+ val url = if (jsonObj.isNull("url")) null else jsonObj.getString("url")
370
+ val urlref = if (jsonObj.isNull("urlref")) null else jsonObj.getString("urlref")
371
+ var eventCategory = if (jsonObj.isNull("e_c")) null else jsonObj.getString("e_c")
372
+
373
+ if (eventCategory != null) {
374
+ eventCategory =
375
+ eventCategory.replace("{{vstor_id}}", TagWorks.getInstance().visitorId)
376
+ }
377
+
378
+ if (idSite != null && idSite != TagWorks.getInstance().siteId) {
379
+ Logger.i(MessageHandlerName, "WebView siteid is not equal App siteid!!")
380
+ }
381
+
382
+ TagWorks.getInstance().webInterfaceLogEventPush(
383
+ idSite, url, urlref, eventCategory
384
+ )
385
+ }
386
+
387
+ } catch (t: Throwable) {
388
+ Logger.e(MessageHandlerName, "Could not parse malformed JSON: \"$jsonEventString\"");
389
+ }
390
+ }
391
+
392
+ override fun getConstants(): MutableMap<String, Any> {
393
+ return mutableMapOf(
394
+ "EVENT_TYPE_PAGE" to TagWorks.EVENT_TYPE_PAGE,
395
+ "EVENT_TYPE_USER_EVENT" to TagWorks.EVENT_TYPE_USER_EVENT,
396
+ )
397
+ }
398
+
399
+ companion object {
400
+ const val TAG = "TagWorksModule"
401
+ }
402
+ }