tagworks-sdk-v1-react 1.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.
Files changed (33) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +33 -0
  3. package/android/build.gradle +101 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/AndroidManifestNew.xml +3 -0
  7. package/android/src/main/java/com/tagworkssdkv1/DataBundleModule.kt +229 -0
  8. package/android/src/main/java/com/tagworkssdkv1/StandardEventModule.kt +21 -0
  9. package/android/src/main/java/com/tagworkssdkv1/TagWorksModule.kt +317 -0
  10. package/android/src/main/java/com/tagworkssdkv1/TagworksSdkV1Module.kt +25 -0
  11. package/android/src/main/java/com/tagworkssdkv1/TagworksSdkV1Package.kt +18 -0
  12. package/ios/DataBundleModule.swift +271 -0
  13. package/ios/DataBundleModuleBridge.m +29 -0
  14. package/ios/StandardEventModule.swift +58 -0
  15. package/ios/StandardEventModuleBridge.m +17 -0
  16. package/ios/TagWorksModule.swift +262 -0
  17. package/ios/TagWorksModuleBridge.m +46 -0
  18. package/ios/TagworksSdkV1-Bridging-Header.h +2 -0
  19. package/ios/TagworksSdkV1.mm +14 -0
  20. package/ios/TagworksSdkV1.swift +8 -0
  21. package/lib/commonjs/index.js +38 -0
  22. package/lib/commonjs/index.js.map +1 -0
  23. package/lib/module/index.js +32 -0
  24. package/lib/module/index.js.map +1 -0
  25. package/lib/typescript/commonjs/package.json +1 -0
  26. package/lib/typescript/commonjs/src/index.d.ts +3 -0
  27. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  28. package/lib/typescript/module/package.json +1 -0
  29. package/lib/typescript/module/src/index.d.ts +3 -0
  30. package/lib/typescript/module/src/index.d.ts.map +1 -0
  31. package/package.json +189 -0
  32. package/src/index.tsx +25 -0
  33. package/tagworks-sdk-v1.podspec +43 -0
@@ -0,0 +1,317 @@
1
+ package com.tagworkssdkv1
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())
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 generalMap = Arguments.createMap()
132
+ val factMap = Arguments.createMap()
133
+
134
+ commonDimensions.forEach { dimension ->
135
+ when (dimension.type) {
136
+ DimensionType.GENERAL_TYPE -> generalMap.putString(dimension.index.toString(),dimension.value)
137
+ DimensionType.FACT_TYPE -> factMap.putDouble(dimension.index.toString(),dimension.numValue)
138
+ }
139
+ }
140
+
141
+ val generalWrapper = Arguments.createMap()
142
+ generalWrapper.putMap("General",generalMap)
143
+
144
+ val factWrapper = Arguments.createMap()
145
+ factWrapper.putMap("Fact",factMap)
146
+
147
+ val dimensionsArray = Arguments.createArray()
148
+ dimensionsArray.pushMap(generalWrapper)
149
+ dimensionsArray.pushMap(factWrapper)
150
+
151
+
152
+ val result = Arguments.createMap()
153
+ result.putArray("Dimensions", dimensionsArray)
154
+
155
+ callback.invoke(result)
156
+ } catch (e: Exception) {
157
+ // 오류 처리
158
+ e.printStackTrace()
159
+ callback.invoke(null)
160
+ }
161
+
162
+
163
+ }
164
+
165
+ @ReactMethod
166
+ fun getCommonDimensionsOfArrayIndex(callback: Callback) {
167
+ try {
168
+ val commonDimensions = TagWorks.getInstance().getDimensions()
169
+ Log.d(TAG, "getCommonDimensionsOfArrayIndex: ${commonDimensions}")
170
+ val dimensions = JSONArray()
171
+
172
+ commonDimensions.forEach { dimension ->
173
+ val dimensionObject = JSONObject()
174
+ if (dimension.type == DimensionType.FACT_TYPE) {
175
+ dimensionObject.put("Fact_${dimension.index}", dimension.numValue)
176
+ } else if (dimension.type == DimensionType.GENERAL_TYPE) {
177
+ dimensionObject.put("General_${dimension.index}", dimension.value)
178
+ }
179
+ dimensions.put(dimensionObject)
180
+ }
181
+ val jsonString = dimensions.toString(4)
182
+ callback.invoke(jsonString)
183
+ }catch (e:Exception) {
184
+ callback.invoke(null)
185
+ }
186
+ }
187
+
188
+ @ReactMethod
189
+ fun getCommonDimensionWithString(index: Int,callback: Callback) {
190
+ val mCommonDimension = TagWorks.getInstance().getCommonDimension(DimensionType.GENERAL_TYPE,index)
191
+ if (mCommonDimension != null) callback.invoke(mCommonDimension.value)
192
+ else callback.invoke(null)
193
+ }
194
+
195
+ @ReactMethod
196
+ fun getCommonDimensionWithDouble(index: Int,callback: Callback) {
197
+ val mCommonDimension = TagWorks.getInstance().getCommonDimension(DimensionType.FACT_TYPE,index)
198
+ if (mCommonDimension != null) callback.invoke(mCommonDimension.numValue)
199
+ else callback.invoke(null)
200
+ }
201
+
202
+ @ReactMethod
203
+ fun removeDimensionInGeneralType(index: Int) {
204
+ TagWorks.getInstance().removeCommonDimension(DimensionType.GENERAL_TYPE,index)
205
+ }
206
+
207
+ @ReactMethod
208
+ fun removeDimensionInFactType(index: Int) {
209
+ TagWorks.getInstance().removeCommonDimension(DimensionType.FACT_TYPE,index)
210
+ }
211
+
212
+ @ReactMethod
213
+ fun removeAllCommonDimension() {
214
+ TagWorks.getInstance().removeAllCommonDimension()
215
+ }
216
+
217
+ @ReactMethod
218
+ fun removeCommonDimensionWithArrayIndex(index:Int) {
219
+ TagWorks.getInstance().removeCommonDimensionWithArrayIndex(index)
220
+ }
221
+
222
+
223
+ @ReactMethod
224
+ fun dispatch(callback: Callback) {
225
+ val result = TagWorks.getInstance().dispatch()
226
+ callback.invoke(result)
227
+ }
228
+
229
+ @ReactMethod
230
+ fun sendReferrerEventWithOpenUrlString(openUrl: String) {
231
+ TagWorks.getInstance().sendReferrerEvent(openUrl)
232
+ }
233
+
234
+
235
+ @ReactMethod
236
+ fun logEvent(eventType:String,data:ReadableMap,callback: Callback) {
237
+
238
+ val bundle = DataBundle()
239
+
240
+ val dataBundleMap = data.getMap("dataBundle")
241
+ dataBundleMap?.let {
242
+ val keySetIterator = it.keySetIterator()
243
+ while (keySetIterator.hasNextKey()) {
244
+ val key = keySetIterator.nextKey()
245
+ bundle.putString(key,it.getString(key))
246
+ }
247
+ }
248
+
249
+ val dimensionsArray = data.getArray("dimensions")
250
+ dimensionsArray?.let {
251
+ for (i in 0 until it.size()) {
252
+ val dimensionMap = it.getMap(i)
253
+ val type = dimensionMap.getString("type")
254
+ val index = dimensionMap.getInt("index")
255
+ val value = dimensionMap.getString("value")
256
+ val numValue = dimensionMap.getDouble("numValue")
257
+
258
+ bundle.setDimension(Dimension(DimensionType.valueOf(type!!),index,value,numValue))
259
+ }
260
+ }
261
+
262
+ Log.d(TAG, "logEvent: ${bundle.dataBundle} + ${bundle.dimensions}")
263
+ try {
264
+
265
+ val result = TagWorks.getInstance().logEvent(eventType, bundle)
266
+ callback.invoke(result)
267
+
268
+ }catch (e:Exception) {
269
+ Log.d(TAG, "log event error: ${e.message}")
270
+ }
271
+
272
+
273
+ }
274
+
275
+ @ReactMethod
276
+ fun webInterfaceDidReceive(jsonEventString: String) {
277
+ d(MessageHandlerName,jsonEventString)
278
+ Log.d("TAG", "TagWorksWebEvent: ${jsonEventString}")
279
+ try {
280
+ d(name, jsonEventString)
281
+ val jsonObj = JSONObject(jsonEventString)
282
+
283
+ val idSite = if (jsonObj.isNull("idsite")) null else jsonObj.getString("idsite")
284
+ val url = if (jsonObj.isNull("url")) null else jsonObj.getString("url")
285
+ val urlref = if (jsonObj.isNull("urlref")) null else jsonObj.getString("urlref")
286
+ var eventCategory = if (jsonObj.isNull("e_c")) null else jsonObj.getString("e_c")
287
+
288
+ if (eventCategory != null) {
289
+ eventCategory =
290
+ eventCategory.replace("{{vstor_id}}", TagWorks.getInstance().getVisitorId())
291
+ }
292
+
293
+ if (idSite != null && idSite != TagWorks.getInstance().getSiteId()) {
294
+ Logger.i(MessageHandlerName, "WebView siteid is not equal App siteid!!")
295
+ }
296
+
297
+ TagWorks.getInstance().webInterfaceLogEventPush(
298
+ idSite, url, urlref, eventCategory
299
+ )
300
+
301
+ } catch (t: Throwable) {
302
+ Logger.e(MessageHandlerName,t.message);
303
+ Logger.e(MessageHandlerName, "Could not parse malformed JSON: \"$jsonEventString\"");
304
+ }
305
+ }
306
+
307
+ override fun getConstants(): MutableMap<String, Any> {
308
+ return mutableMapOf(
309
+ "EVENT_TYPE_PAGE" to TagWorks.EVENT_TYPE_PAGE,
310
+ "EVENT_TYPE_USER_EVENT" to TagWorks.EVENT_TYPE_USER_EVENT,
311
+ )
312
+ }
313
+
314
+ companion object {
315
+ const val TAG = "TagWorksModule"
316
+ }
317
+ }
@@ -0,0 +1,25 @@
1
+ package com.tagworkssdkv1
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
5
+ import com.facebook.react.bridge.ReactMethod
6
+ import com.facebook.react.bridge.Promise
7
+
8
+ class TagworksSdkV1Module(reactContext: ReactApplicationContext) :
9
+ ReactContextBaseJavaModule(reactContext) {
10
+
11
+ override fun getName(): String {
12
+ return NAME
13
+ }
14
+
15
+ // Example method
16
+ // See https://reactnative.dev/docs/native-modules-android
17
+ @ReactMethod
18
+ fun multiply(a: Double, b: Double, promise: Promise) {
19
+ promise.resolve(a * b)
20
+ }
21
+
22
+ companion object {
23
+ const val NAME = "TagworksSdkV1"
24
+ }
25
+ }
@@ -0,0 +1,18 @@
1
+ package com.tagworkssdkv1
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 TagworksSdkV1Package : ReactPackage {
10
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
+ // return listOf(TagworksSdkV1Module(reactContext))
12
+ return listOf(DataBundleModule(reactContext), TagWorksModule(reactContext), StandardEventModule(reactContext))
13
+ }
14
+
15
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
16
+ return emptyList()
17
+ }
18
+ }
@@ -0,0 +1,271 @@
1
+ //
2
+ // DataBundleModule.swift
3
+ // TagWorks_SDK_React
4
+ //
5
+ // Created by obzen on 11/29/24.
6
+ //
7
+
8
+ import Foundation
9
+ import React
10
+ import TagWorks_SDK_iOS
11
+
12
+ @objc(DataBundleModule)
13
+ class DataBundleModule: NSObject, RCTBridgeModule {
14
+
15
+ var dataDictionary: [String: String] = [:]
16
+ var eventDimensions: [TagWorks_SDK_iOS.Dimension] = []
17
+
18
+ static func moduleName() -> String {
19
+ return "DataBundleModule"
20
+ }
21
+
22
+ // 네이티브 모듈에서 사용할 상수값을 반환하는 함수
23
+ @objc static func requiresMainQueueSetup() -> Bool {
24
+ return true
25
+ }
26
+
27
+ @objc func getConstants() -> [AnyHashable: Any]! {
28
+ // 상수값을 반환합니다. JavaScript로 전달됩니다.
29
+ return [
30
+ "EVENT_TAG_NAME": "OBZEN_EVENT_NAME",
31
+ "EVENT_TAG_PARAM_PAGE_PATH": "EVENT_TAG_PARAM_PAGE_PATH",
32
+ "EVENT_TAG_PARAM_TITLE": "EVENT_TAG_PARAM_TITLE",
33
+ "EVENT_TAG_PARAM_KEYWORD": "EVENT_TAG_PARAM_KEYWORD",
34
+ "EVENT_TAG_PARAM_CUSTOM_PATH": "EVENT_TAG_PARAM_CUSTOM_PATH",
35
+ "EVENT_TAG_PARAM_ERROR_MSG": "EVENT_TAG_PARAM_ERROR_MSG",
36
+ ]
37
+ }
38
+
39
+ @objc func initialize() {
40
+ if !dataDictionary.isEmpty {
41
+ dataDictionary.removeAll()
42
+ }
43
+ if !eventDimensions.isEmpty {
44
+ eventDimensions.removeAll()
45
+ }
46
+ }
47
+
48
+ @objc func initDataBundle(_ jsonString: String) {
49
+ initialize()
50
+
51
+ // JSON 문자열을 Data로 변환
52
+ if let data = jsonString.data(using: .utf8) {
53
+ do {
54
+ // Data를 Dictionary로 변환
55
+ if let bundleDictionary = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
56
+ var dataDictionary: [String: Any] = [:]
57
+ var eventDemensionsArray: [[String: Any]] = []
58
+ var genericDimensions: [String: String] = [:]
59
+ var factDimensions: [String: Any] = [:]
60
+
61
+ // 기존 번들 내용을 복사
62
+ if bundleDictionary["dataDictionary"] != nil {
63
+ dataDictionary = bundleDictionary["dataDictionary"] as! [String: String]
64
+
65
+ for (key, value) in dataDictionary {
66
+ self.dataDictionary[key] = value as? String
67
+ }
68
+ }
69
+ if bundleDictionary["eventDimensions"] != nil {
70
+ eventDemensionsArray = bundleDictionary["eventDimensions"] as! [[String: Any]]
71
+
72
+ for dimension in eventDemensionsArray {
73
+ if dimension["General"] != nil {
74
+ genericDimensions = dimension["General"] as! [String: String]
75
+
76
+ for (key, value) in genericDimensions {
77
+ self.eventDimensions.append(TagWorks_SDK_iOS.Dimension(index: Int(key)!, stringValue: value))
78
+ }
79
+ }
80
+ if dimension["Fact"] != nil {
81
+ factDimensions = dimension["Fact"] as! [String: Any]
82
+
83
+ for (key, value) in factDimensions {
84
+ self.eventDimensions.append(TagWorks_SDK_iOS.Dimension(index: Int(key)!, numValue: Double(value as! String) ?? 0.0))
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ } catch {
91
+ print("JSON 변환 오류: \(error)")
92
+ }
93
+ }
94
+ }
95
+
96
+ @objc func getDataBundle(_ callback: @escaping RCTResponseSenderBlock) {
97
+ // DataBundle을 Dictionary 형태로 변환
98
+ var result: [String: Any] = [:]
99
+ result["dataDictionary"] = self.dataDictionary
100
+
101
+ var generalDimensions: [String: String] = [:]
102
+ var factDimensions: [String: Any] = [:]
103
+ for dimension in self.eventDimensions {
104
+ if dimension.type == Dimension.generalType {
105
+ generalDimensions[String(dimension.index)] = dimension.value
106
+ } else if dimension.type == Dimension.factType {
107
+ factDimensions[String(dimension.index)] = String(dimension.numValue)
108
+ }
109
+ }
110
+ let gDimension = ["General": generalDimensions]
111
+ let fDimension = ["Fact": factDimensions]
112
+ result["eventDimensions"] = [gDimension, fDimension]
113
+
114
+ do {
115
+ // Dictionary Array를 JSON으로 변환
116
+ let jsonData = try JSONSerialization.data(withJSONObject: result, options: .prettyPrinted)
117
+
118
+ // JSON 데이터를 문자열로 변환하여 반환
119
+ if let jsonString = String(data: jsonData, encoding: .utf8) {
120
+ callback([jsonString]) // JSON 문자열을 JavaScript로 전달
121
+ }
122
+ } catch {
123
+ print("JSON 변환 오류: \(error)")
124
+ callback([NSNull()])
125
+ }
126
+ }
127
+
128
+ ///
129
+ /// 파라미터 추가
130
+ /// 이벤트에 필요한 파라미터 항목들을, Key, Value의 String 형태로 Dictionary에 추가
131
+ ///
132
+ @objc func putString(_ key: String, value: String) {
133
+ dataDictionary[key] = value
134
+ }
135
+
136
+ ///
137
+ /// 이벤트에 필요한 Dimension 항목을 Array에 추가
138
+ /// 단, 추가하기 전 중복 항목 체크..
139
+ ///
140
+ @objc func putDimensionWithString(_ index: Int, value: String) {
141
+ removeDimensionInGeneralType(index)
142
+ eventDimensions.append(Dimension(index: index, stringValue: value))
143
+ }
144
+
145
+ @objc func putDimensionWithDouble(_ index: Int, value: Double) {
146
+ removeDimensionInFactType(index)
147
+ eventDimensions.append(Dimension(index: index, numValue: value))
148
+ }
149
+
150
+ /// General 과 Fact 별로 저장되어 있는 인덱스와 값들을 리턴i
151
+ @objc func getDimensions(_ callback: @escaping RCTResponseSenderBlock) {
152
+ var dictDimensions: [String: Any] = [:]
153
+ var generalDimensions: [String: String] = [:]
154
+ var factDimensions: [String: Any] = [:]
155
+
156
+ for dimension in self.eventDimensions {
157
+ if dimension.type == Dimension.generalType {
158
+ generalDimensions[String(dimension.index)] = dimension.value
159
+ } else if dimension.type == Dimension.factType {
160
+ factDimensions[String(dimension.index)] = String(dimension.numValue)
161
+ }
162
+ }
163
+ let gDimension = ["General": generalDimensions]
164
+ let fDimension = ["Fact": factDimensions]
165
+ dictDimensions["Dimensions"] = [gDimension, fDimension]
166
+
167
+ do {
168
+ // Dictionary Array를 JSON으로 변환
169
+ let jsonData = try JSONSerialization.data(withJSONObject: dictDimensions, options: .prettyPrinted)
170
+
171
+ // JSON 데이터를 문자열로 변환하여 반환
172
+ if let jsonString = String(data: jsonData, encoding: .utf8) {
173
+ callback([jsonString]) // JSON 문자열을 JavaScript로 전달
174
+ }
175
+ } catch {
176
+ print("JSON 변환 오류: \(error)")
177
+ callback([NSNull()])
178
+ }
179
+ }
180
+
181
+ /// ArrayIndex에 맞춰서 리턴
182
+ @objc func getDimensionsOfArrayIndex(_ callback: @escaping RCTResponseSenderBlock) {
183
+ var dimensionsArray: [[String:String]] = []
184
+
185
+ for dimension in self.eventDimensions {
186
+ if dimension.type == Dimension.generalType {
187
+ var dim: [String: String] = [:]
188
+ dim["General_\(dimension.index)"] = dimension.value
189
+ dimensionsArray.append(dim)
190
+ } else if dimension.type == Dimension.factType {
191
+ var dim: [String: String] = [:]
192
+ dim["Fact_\(dimension.index)"] = String(dimension.numValue)
193
+ dimensionsArray.append(dim)
194
+ }
195
+ }
196
+
197
+ do {
198
+ // Dictionary Array를 JSON으로 변환
199
+ let jsonData = try JSONSerialization.data(withJSONObject: dimensionsArray, options: .prettyPrinted)
200
+
201
+ // JSON 데이터를 문자열로 변환하여 반환
202
+ if let jsonString = String(data: jsonData, encoding: .utf8) {
203
+ callback([jsonString]) // JSON 문자열을 JavaScript로 전달
204
+ }
205
+ } catch {
206
+ print("JSON 변환 오류: \(error)")
207
+ callback([NSNull()])
208
+ }
209
+ }
210
+
211
+ @objc func getDimensionWithString(_ index: Int, callback: @escaping RCTResponseSenderBlock) {
212
+ let dimension: TagWorks_SDK_iOS.Dimension? = self.eventDimensions.filter {$0.index == index && $0.type == Dimension.generalType}.first
213
+ if let dimension {
214
+ callback([dimension.value])
215
+ } else {
216
+ callback([])
217
+ }
218
+ }
219
+
220
+ @objc func getDimensionWithDouble(_ index: Int, callback: @escaping RCTResponseSenderBlock) {
221
+ let dimension: TagWorks_SDK_iOS.Dimension? = self.eventDimensions.filter {$0.index == index && $0.type == Dimension.factType}.first
222
+ if let dimension {
223
+ callback([String(dimension.numValue)])
224
+ } else {
225
+ callback([])
226
+ }
227
+ }
228
+
229
+ @objc func removeDimensionInGeneralType(_ index: Int) {
230
+ eventDimensions.removeAll(where: {$0.index == index && $0.type == Dimension.generalType})
231
+ }
232
+
233
+ @objc func removeDimensionInFactType(_ index: Int) {
234
+ eventDimensions.removeAll(where: {$0.index == index && $0.type == Dimension.factType})
235
+ }
236
+
237
+ @objc func removeDimensionWithArrayIndex(_ index: Int) {
238
+ eventDimensions.remove(at: index)
239
+ }
240
+
241
+ @objc func removeAllDimension() {
242
+ eventDimensions.removeAll()
243
+ }
244
+
245
+
246
+ /// 이벤트에 필요한 파라미터 항목들이 비어 있는지 체크
247
+ @objc public func isParameterEmpty() -> Bool {
248
+ if dataDictionary.isEmpty {
249
+ return true
250
+ }
251
+ return false
252
+ }
253
+
254
+ /// 이벤트에 필요한 Dimension 항목들이 비어 있는지 체크
255
+ @objc public func isDimensionEmpty() -> Bool {
256
+ if eventDimensions.isEmpty {
257
+ return true
258
+ }
259
+ return false
260
+ }
261
+
262
+ /// 이벤트에 필요한 파라미터 항목들의 갯수를 리턴
263
+ @objc public func parameterCount() -> Int {
264
+ return dataDictionary.count
265
+ }
266
+
267
+ /// 이벤트에 필요한 Dimension 항목들의 갯수를 리턴
268
+ @objc public func dimensionCount() -> Int {
269
+ return eventDimensions.count
270
+ }
271
+ }
@@ -0,0 +1,29 @@
1
+ //
2
+ // DataBundleModuleBridge.m
3
+ // TagWorks_SDK_React
4
+ //
5
+ // Created by obzen on 11/29/24.
6
+ //
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import <React/RCTBridgeModule.h>
10
+
11
+ @interface RCT_EXTERN_MODULE(DataBundleModule, NSObject)
12
+
13
+ RCT_EXTERN_METHOD(initialize)
14
+ RCT_EXTERN_METHOD(initDataBundle:(NSString *) jsonString)
15
+ RCT_EXTERN_METHOD(getDataBundle:(RCTResponseSenderBlock) callback)
16
+
17
+ RCT_EXTERN_METHOD(putString:(NSString *)key value:(NSString *)value)
18
+ RCT_EXTERN_METHOD(putDimensionWithString:(int)index value:(NSString *)value)
19
+ RCT_EXTERN_METHOD(putDimensionWithDouble:(int)index value:(double)value)
20
+ RCT_EXTERN_METHOD(getDimensions:(RCTResponseSenderBlock) callback)
21
+ RCT_EXTERN_METHOD(getDimensionsOfArrayIndex:(RCTResponseSenderBlock) callback)
22
+ RCT_EXTERN_METHOD(getDimensionWithString:(int)index callback:(RCTResponseSenderBlock) callback)
23
+ RCT_EXTERN_METHOD(getDimensionWithDouble:(int)index callback:(RCTResponseSenderBlock) callback)
24
+ RCT_EXTERN_METHOD(removeDimensionInGeneralType:(int)index)
25
+ RCT_EXTERN_METHOD(removeDimensionInFactType:(int)index)
26
+ RCT_EXTERN_METHOD(removeDimensionWithArrayIndex:(int)index)
27
+ RCT_EXTERN_METHOD(removeAllDimension)
28
+
29
+ @end