|
| 1 | +import {NativeModules} from 'react-native'; |
| 2 | +import {Platform} from 'react-native'; |
| 3 | + |
| 4 | +const TDADT = NativeModules.TalkingDataAppCpa; |
| 5 | + |
| 6 | +class TalkingDataADTOrder { |
| 7 | + |
| 8 | + constructor(orderId,total,currencyType) { |
| 9 | + this.orderId = orderId; |
| 10 | + this.total = total; |
| 11 | + this.currencyType = currencyType; |
| 12 | + this.items = new Array(); |
| 13 | + } |
| 14 | + |
| 15 | + addItemWithItemId(itemId,category,name,unitPrice,amount){ |
| 16 | + this.items.push({'itemId':itemId,'category':category,'name':name,'unitPrice':unitPrice,'amount':amount}); |
| 17 | + } |
| 18 | + |
| 19 | + addItem(category,name,unitPrice,amount){ |
| 20 | + this.items.push({'category':category,'name':name,'unitPrice':unitPrice,'amount':amount}); |
| 21 | + } |
| 22 | + |
| 23 | + get orderString(){ |
| 24 | + return JSON.stringify({ |
| 25 | + 'orderId':this.orderId, |
| 26 | + 'total':this.total, |
| 27 | + 'currencyType':this.currencyType, |
| 28 | + 'items':this.items |
| 29 | + }); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +class TalkingDataADTShoppingCart { |
| 34 | + |
| 35 | + constructor(){ |
| 36 | + this.items = new Array(); |
| 37 | + } |
| 38 | + |
| 39 | + addItem(itemId,category,name,unitPrice,amount){ |
| 40 | + this.items.push({'itemId':itemId,'category':category,'name':name,'unitPrice':unitPrice,'amount':amount}); |
| 41 | + } |
| 42 | + |
| 43 | + get shoppingCartString(){ |
| 44 | + return JSON.stringify({ |
| 45 | + 'items':this.items |
| 46 | + }); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +class TalkingDataAdSearch { |
| 51 | + |
| 52 | + constructor(){ |
| 53 | + this.custom = new Object(); |
| 54 | + } |
| 55 | + |
| 56 | + setDestination(destination){ |
| 57 | + this.destination = destination; |
| 58 | + } |
| 59 | + |
| 60 | + setOrigin(origin){ |
| 61 | + this.origin = origin; |
| 62 | + } |
| 63 | + |
| 64 | + setItemId(item_id){ |
| 65 | + this.item_id = item_id; |
| 66 | + } |
| 67 | + |
| 68 | + setItemLocationId(item_location_id){ |
| 69 | + this.item_location_id = item_location_id; |
| 70 | + } |
| 71 | + |
| 72 | + setStartDate(start_date){ |
| 73 | + this.start_date = start_date; |
| 74 | + } |
| 75 | + |
| 76 | + setEndDate(end_date){ |
| 77 | + this.end_date = end_date; |
| 78 | + } |
| 79 | + |
| 80 | + setSearchTerm(search_term){ |
| 81 | + this.search_term = search_term; |
| 82 | + } |
| 83 | + |
| 84 | + setGoogleBusinessVertical(google_business_vertical){ |
| 85 | + this.google_business_vertical = google_business_vertical; |
| 86 | + } |
| 87 | + |
| 88 | + addCustom(key, value){ |
| 89 | + this.custom[key] = value; |
| 90 | + } |
| 91 | + |
| 92 | + get adSearchString(){ |
| 93 | + return JSON.stringify({ |
| 94 | + 'destination':this.destination, |
| 95 | + 'origin':this.origin, |
| 96 | + 'item_id':this.item_id, |
| 97 | + 'item_location_id':this.item_location_id, |
| 98 | + 'start_date':this.start_date, |
| 99 | + 'end_date':this.end_date, |
| 100 | + 'search_term':this.search_term, |
| 101 | + 'google_business_vertical':this.google_business_vertical, |
| 102 | + 'custom':this.custom |
| 103 | + }); |
| 104 | + } |
| 105 | + |
| 106 | +} |
| 107 | + |
| 108 | +class TalkingDataAdTracking { |
| 109 | + /** |
| 110 | + * 获取SDK所使用Device的ID |
| 111 | + * iOS Android |
| 112 | + * @return {string} deviceID |
| 113 | + */ |
| 114 | + static getDeviceID(callback){ |
| 115 | + TDADT.getDeviceID().then(callback); |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | +/** |
| 120 | + * 注册 |
| 121 | + * iOS Android |
| 122 | + * @param {string} accountId 账户ID |
| 123 | + * @param {TDAccountType} accountType 账户类型 详见 |
| 124 | + * @param {string} name 账户昵称 |
| 125 | + */ |
| 126 | + static onRegister(account){ |
| 127 | + if (typeof account !== 'string') { |
| 128 | + return ; |
| 129 | + } |
| 130 | + TDADT.onRegister(account); |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * 登录 |
| 135 | + * iOS Android |
| 136 | + * @param {string} account 账户ID |
| 137 | + */ |
| 138 | + static onLogin(account){ |
| 139 | + if (typeof account !== 'string') { |
| 140 | + return ; |
| 141 | + } |
| 142 | + TDADT.onLogin(account); |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * 创建角色 |
| 147 | + * iOS Android |
| 148 | + * @param {string} name 角色名称 |
| 149 | + */ |
| 150 | + static onCreateRole(name){ |
| 151 | + if (typeof name !== 'string') { |
| 152 | + return ; |
| 153 | + } |
| 154 | + TDADT.onCreateRole(name); |
| 155 | + } |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + /** |
| 160 | + * 下单。 |
| 161 | + * iOS Android |
| 162 | + * @param {string} accountId 账户ID |
| 163 | + * @param {object} order 订单对象 |
| 164 | + * order 订单对象 |
| 165 | + { |
| 166 | + orderId(string) 订单id |
| 167 | + total(number) 订单总价 |
| 168 | + currencyType(string) 币种 |
| 169 | + category(string) 商品类别 |
| 170 | +
|
| 171 | + } |
| 172 | + */ |
| 173 | + static onPlaceOrder(accountId,order){ |
| 174 | + if (typeof accountId !== 'string') { |
| 175 | + return; |
| 176 | + }; |
| 177 | + if (typeof order !== 'string') { |
| 178 | + return; |
| 179 | + }; |
| 180 | + TDADT.onPlaceOrder(accountId,order); |
| 181 | + } |
| 182 | + |
| 183 | + |
| 184 | + static onOrderPaySucc(account,orderId,amount,currencyType,payType){ |
| 185 | + if (typeof account !== 'string') { |
| 186 | + return; |
| 187 | + }; |
| 188 | + if (typeof orderId !== 'string') { |
| 189 | + return; |
| 190 | + }; |
| 191 | + if (typeof amount !== 'number') { |
| 192 | + return; |
| 193 | + }; |
| 194 | + if (typeof currencyType !== 'string') { |
| 195 | + return; |
| 196 | + }; |
| 197 | + if (typeof payType !== 'string') { |
| 198 | + return; |
| 199 | + }; |
| 200 | + TDADT.onOrderPaySucc(account,orderId,amount,currencyType,payType); |
| 201 | + } |
| 202 | + |
| 203 | + static onPay(account,orderId,amount,currencyType,payType) { |
| 204 | + if (typeof account !== 'string') { |
| 205 | + return; |
| 206 | + }; |
| 207 | + if (typeof orderId !== 'string') { |
| 208 | + return; |
| 209 | + }; |
| 210 | + if (typeof amount !== 'number') { |
| 211 | + return; |
| 212 | + }; |
| 213 | + if (typeof currencyType !== 'string') { |
| 214 | + return; |
| 215 | + }; |
| 216 | + if (typeof payType !=='string') { |
| 217 | + return; |
| 218 | + }; |
| 219 | + TDADT.onPay(account,orderId,amount,currencyType,payType) |
| 220 | + } |
| 221 | + |
| 222 | + static onPayWithItem(account,orderId,amount,currencyType,payType,itemId,itemCount) { |
| 223 | + if (typeof account !== 'string') { |
| 224 | + return; |
| 225 | + }; |
| 226 | + if (typeof orderId !== 'string') { |
| 227 | + return; |
| 228 | + }; |
| 229 | + if (typeof amount !== 'number') { |
| 230 | + return; |
| 231 | + }; |
| 232 | + if (typeof currencyType !== 'string') { |
| 233 | + return; |
| 234 | + }; |
| 235 | + if (typeof payType !=='string') { |
| 236 | + return; |
| 237 | + }; |
| 238 | + if (typeof itemId !=='string') { |
| 239 | + return; |
| 240 | + }; |
| 241 | + if (typeof itemCount !== 'number') { |
| 242 | + return; |
| 243 | + }; |
| 244 | + TDADT.onPayWithItem(account,orderId,amount,currencyType,payType,itemId,itemCount) |
| 245 | + } |
| 246 | + |
| 247 | + static onPayWithOrder(account,orderId,amount,currencyType,payType,orderString) { |
| 248 | + if (typeof account !== 'string') { |
| 249 | + return; |
| 250 | + }; |
| 251 | + if (typeof orderId !== 'string') { |
| 252 | + return; |
| 253 | + }; |
| 254 | + if (typeof amount !== 'number') { |
| 255 | + return; |
| 256 | + }; |
| 257 | + if (typeof currencyType !== 'string') { |
| 258 | + return; |
| 259 | + }; |
| 260 | + if (typeof payType !=='string') { |
| 261 | + return; |
| 262 | + }; |
| 263 | + if (typeof orderString !== 'string') { |
| 264 | + return; |
| 265 | + }; |
| 266 | + TDADT.onPayWithOrder(account,orderId,amount,currencyType,payType,orderString) |
| 267 | + } |
| 268 | + |
| 269 | + |
| 270 | + static onViewItem(itemId,category,name,unitPrice){ |
| 271 | + if (typeof itemId !== 'string') { |
| 272 | + return; |
| 273 | + }; |
| 274 | + if (typeof category !== 'string') { |
| 275 | + return; |
| 276 | + }; |
| 277 | + if (typeof name !== 'string') { |
| 278 | + return; |
| 279 | + }; |
| 280 | + if (typeof unitPrice !=='number') { |
| 281 | + return; |
| 282 | + }; |
| 283 | + TDADT.onViewItem(itemId,category,name,unitPrice); |
| 284 | + } |
| 285 | + |
| 286 | + static onAddItemToShoppingCart(itemId,category,name,unitPrice,amount){ |
| 287 | + if (typeof itemId !== 'string') { |
| 288 | + return; |
| 289 | + }; |
| 290 | + if (typeof category !== 'string') { |
| 291 | + return; |
| 292 | + }; |
| 293 | + if (typeof name !== 'string') { |
| 294 | + return; |
| 295 | + }; |
| 296 | + if (typeof unitPrice !=='number') { |
| 297 | + return; |
| 298 | + }; |
| 299 | + if (typeof amount !=='number') { |
| 300 | + return; |
| 301 | + }; |
| 302 | + TDADT.onAddItemToShoppingCart(itemId,category,name,unitPrice,amount); |
| 303 | + } |
| 304 | + |
| 305 | + |
| 306 | + |
| 307 | + |
| 308 | + static onViewShoppingCart(shoppingCart){ |
| 309 | + if (typeof shoppingCart !== 'string') { |
| 310 | + return; |
| 311 | + }; |
| 312 | + TDADT.onViewShoppingCart(shoppingCart); |
| 313 | + } |
| 314 | + |
| 315 | + |
| 316 | + |
| 317 | + |
| 318 | + |
| 319 | + static onCustEvent1(){TDADT.onCustEvent1();} |
| 320 | + static onCustEvent2(){TDADT.onCustEvent2();} |
| 321 | + static onCustEvent3(){TDADT.onCustEvent3();} |
| 322 | + static onCustEvent4(){TDADT.onCustEvent4();} |
| 323 | + static onCustEvent5(){TDADT.onCustEvent5();} |
| 324 | + static onCustEvent6(){TDADT.onCustEvent6();} |
| 325 | + static onCustEvent7(){TDADT.onCustEvent7();} |
| 326 | + static onCustEvent8(){TDADT.onCustEvent8();} |
| 327 | + static onCustEvent9(){TDADT.onCustEvent9();} |
| 328 | + static onCustEvent10(){TDADT.onCustEvent10();} |
| 329 | + |
| 330 | + static onAdSearch(adSearch){ |
| 331 | + TDADT.onAdSearch(adSearch); |
| 332 | + } |
| 333 | + |
| 334 | +} |
| 335 | + |
| 336 | +export {TalkingDataAdTracking,TalkingDataADTOrder,TalkingDataADTShoppingCart,TalkingDataAdSearch}; |
0 commit comments