|
1 | | -import { LogEventOptions, SetScreenNameOptions, SetUserPropertyOptions } from "./analytics"; |
| 1 | +import { LogEventOptions, SetScreenNameOptions, SetUserPropertyOptions, LogComplexEventOptions, LogComplexEventParameter } from "./analytics"; |
2 | 2 |
|
3 | 3 | export function logEvent(options: LogEventOptions): Promise<void> { |
4 | 4 | return new Promise<void>((resolve, reject) => { |
@@ -27,6 +27,127 @@ export function logEvent(options: LogEventOptions): Promise<void> { |
27 | 27 | } |
28 | 28 | }); |
29 | 29 | } |
| 30 | +/* |
| 31 | +function getArrayList(array: Array<LogComplexEventOptions>): Array<NSMutableDictionary<string, any>> { |
| 32 | + let returnArray: Array<NSMutableDictionary<string, any>> = new Array(); |
| 33 | + for (const p in array) { |
| 34 | + const param = array[p]; |
| 35 | + if (param.parameters !== undefined) { |
| 36 | + let bundle: NSMutableDictionary<string, any> = buildBundle(param.parameters); |
| 37 | + returnArray.push(bundle); |
| 38 | + } else { |
| 39 | + console.log("BE CARREFUL, no parameters into your complex event"); |
| 40 | + } |
| 41 | + } |
| 42 | + return returnArray; |
| 43 | +} |
| 44 | +
|
| 45 | +function buildBundle(params: Array<LogComplexEventParameter>): NSMutableDictionary<string, any> { |
| 46 | + const bundle: NSMutableDictionary<string, any> = NSMutableDictionary.new(); |
| 47 | + for (const p in params) { |
| 48 | + const param = params[p]; |
| 49 | + if (param.value !== undefined) { |
| 50 | + let nsString = NSMutableString.new(); |
| 51 | + nsString.setString(param.key); |
| 52 | + if (param.type === "string" || param.type === "double" || param.type === "float" || param.type === "int" || param.type === "long" || param.type === "boolean") { |
| 53 | + bundle.setObjectForKey(param.value, param.key); |
| 54 | + } |
| 55 | + else if (param.type === "array") { |
| 56 | + let arrayList = getArrayList(param.value); |
| 57 | + bundle.setObjectForKey(arrayList, param.key); |
| 58 | + } |
| 59 | + // bundle.putString(param.key, param.value); |
| 60 | + } |
| 61 | + } |
| 62 | + return bundle; |
| 63 | +}*/ |
| 64 | + |
| 65 | +/*export function logComplexEvent(options: LogComplexEventOptions): Promise<void> { |
| 66 | + return new Promise<void>((resolve, reject) => { |
| 67 | + try { |
| 68 | + const dic: any = NSMutableDictionary.new(); |
| 69 | + if (options.parameters !== undefined) { |
| 70 | + for (let p in options.parameters) { |
| 71 | + const param = options.parameters[p]; |
| 72 | + if (param.value !== undefined) { |
| 73 | + let dic1: NSMutableDictionary<string, any> = buildBundle(options.parameters); |
| 74 | + dic.setObjectForKey(dic1, param.key); |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + FIRAnalytics.logEventWithNameParameters(options.key, dic); |
| 79 | + resolve(); |
| 80 | + } |
| 81 | + catch (ex) { |
| 82 | + console.log("Error in firebase.analytics.logEvent: " + ex); |
| 83 | + reject(ex); |
| 84 | + } |
| 85 | + }); |
| 86 | +}*/ |
| 87 | + |
| 88 | +/* |
| 89 | +export function logComplexEvent(options: LogComplexEventOptions): Promise<void> { |
| 90 | + return new Promise<void>((resolve, reject) => { |
| 91 | + try { |
| 92 | + const dic: any = NSMutableDictionary.new(); |
| 93 | + if (options.parameters !== undefined) { |
| 94 | + for (let p in options.parameters) { |
| 95 | + const param = options.parameters[p]; |
| 96 | + if (param.value !== undefined) { |
| 97 | + const dic1: any = NSMutableDictionary.new(); |
| 98 | + dic1.setObjectForKey("value56", "testval"); |
| 99 | + dic.setObjectForKey(new Array(dic1), param.key); |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + FIRAnalytics.logEventWithNameParameters(options.key, dic); |
| 104 | + resolve(); |
| 105 | + } |
| 106 | + catch (ex) { |
| 107 | + console.log("Error in firebase.analytics.logEvent: " + ex); |
| 108 | + reject(ex); |
| 109 | + } |
| 110 | + }); |
| 111 | +}*/ |
| 112 | + |
| 113 | + |
| 114 | +export function logComplexEvent(options: LogComplexEventOptions): Promise<void> { |
| 115 | + return new Promise<void>((resolve, reject) => { |
| 116 | + try { |
| 117 | + const dic: any = NSMutableDictionary.new(); |
| 118 | + if (options.parameters !== undefined) { |
| 119 | + for (let p in options.parameters) { |
| 120 | + const param = options.parameters[p]; |
| 121 | + if (param.type === "array" && param.value !== undefined ) { |
| 122 | + const listArray = new Array(); |
| 123 | + for (let val in param.value) { |
| 124 | + const value = param.value[val]; |
| 125 | + if (value.parameters !== undefined) { |
| 126 | + const dicTemp: any = NSMutableDictionary.new(); |
| 127 | + for (let i in value.parameters) { |
| 128 | + const item = value.parameters[i]; |
| 129 | + if (item.type !== "array" && item.value !== undefined && item.key !== undefined ) { |
| 130 | + dicTemp.setObjectForKey(item.value, item.key); |
| 131 | + } |
| 132 | + } |
| 133 | + listArray.push(dicTemp); |
| 134 | + } |
| 135 | + } |
| 136 | + dic.setObjectForKey(listArray, param.key); |
| 137 | + } else if (param.type === "string" || param.type === "double" || param.type === "float" || param.type === "int" || param.type === "long" || param.type === "boolean") { |
| 138 | + dic.setObjectForKey(param.value, param.key); |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + FIRAnalytics.logEventWithNameParameters(options.key, dic); |
| 143 | + resolve(); |
| 144 | + } catch (ex) { |
| 145 | + console.log("Error in firebase.analytics.logEvent: " + ex); |
| 146 | + reject(ex); |
| 147 | + } |
| 148 | + }); |
| 149 | +} |
| 150 | + |
30 | 151 |
|
31 | 152 | export function setUserId(arg): Promise<void> { |
32 | 153 | return new Promise<void>((resolve, reject) => { |
|
0 commit comments