@@ -16,6 +16,7 @@ import {
16
16
import IterableInAppManager from './IterableInAppManager'
17
17
import IterableInAppMessage from './IterableInAppMessage'
18
18
import IterableConfig from './IterableConfig'
19
+ import { IterableLogger } from './IterableLogger'
19
20
20
21
const RNIterableAPI = NativeModules . RNIterableAPI
21
22
const RNEventEmitter = new NativeEventEmitter ( RNIterableAPI )
@@ -121,15 +122,10 @@ enum EventName {
121
122
}
122
123
123
124
class Iterable {
124
- /**
125
- * inAppManager instance
126
- */
127
125
static inAppManager = new IterableInAppManager ( )
128
126
127
+ static logger : IterableLogger
129
128
130
- /**
131
- * savedConfig instance.
132
- */
133
129
static savedConfig : IterableConfig
134
130
135
131
/**
@@ -138,9 +134,12 @@ class Iterable {
138
134
* @param {IterableConfig } config
139
135
*/
140
136
static initialize ( apiKey : string , config : IterableConfig = new IterableConfig ( ) ) : Promise < boolean > {
141
- console . log ( "initialize: " + apiKey ) ;
142
-
143
137
Iterable . savedConfig = config
138
+
139
+ Iterable . logger = new IterableLogger ( Iterable . savedConfig )
140
+
141
+ Iterable . logger . log ( "initialize: " + apiKey )
142
+
144
143
this . setupEventHandlers ( )
145
144
const version = this . getVersionFromPackageJson ( )
146
145
@@ -152,9 +151,12 @@ class Iterable {
152
151
* This method is used internally to connect to staging environment.
153
152
*/
154
153
static initialize2 ( apiKey : string , config : IterableConfig = new IterableConfig ( ) , apiEndPoint : string ) : Promise < boolean > {
155
- console . log ( "initialize2: " + apiKey ) ;
156
-
157
154
Iterable . savedConfig = config
155
+
156
+ Iterable . logger = new IterableLogger ( Iterable . savedConfig )
157
+
158
+ Iterable . logger . log ( "initialize2: " + apiKey ) ;
159
+
158
160
this . setupEventHandlers ( )
159
161
const version = this . getVersionFromPackageJson ( )
160
162
@@ -166,15 +168,17 @@ class Iterable {
166
168
* @param {string | undefined } email the email address of the user
167
169
*/
168
170
static setEmail ( email : string | undefined ) {
169
- console . log ( "setEmail: " + email )
171
+ Iterable . logger . log ( "setEmail: " + email )
172
+
170
173
RNIterableAPI . setEmail ( email )
171
174
}
172
175
173
176
/**
174
177
* Get the email of the current user
175
178
*/
176
179
static getEmail ( ) : Promise < string | undefined > {
177
- console . log ( "getEmail" )
180
+ Iterable . logger . log ( "getEmail" )
181
+
178
182
return RNIterableAPI . getEmail ( )
179
183
}
180
184
@@ -183,39 +187,44 @@ class Iterable {
183
187
* @param {string | undefined } userId the ID of the user
184
188
*/
185
189
static setUserId ( userId : string | undefined ) {
186
- console . log ( "setUserId: " + userId )
190
+ Iterable . logger . log ( "setUserId: " + userId )
191
+
187
192
RNIterableAPI . setUserId ( userId )
188
193
}
189
194
190
195
/**
191
196
* Get the user ID of the current user
192
197
*/
193
198
static getUserId ( ) : Promise < string | undefined > {
194
- console . log ( "getUserId" )
199
+ Iterable . logger . log ( "getUserId" )
200
+
195
201
return RNIterableAPI . getUserId ( )
196
202
}
197
203
198
204
/**
199
205
*
200
206
*/
201
207
static disableDeviceForCurrentUser ( ) {
202
- console . log ( "disableDeviceForCurrentUser" )
208
+ Iterable . logger . log ( "disableDeviceForCurrentUser" )
209
+
203
210
RNIterableAPI . disableDeviceForCurrentUser ( )
204
211
}
205
212
206
213
/**
207
214
*
208
215
*/
209
216
static getLastPushPayload ( ) : Promise < any | undefined > {
210
- console . log ( "getLastPushPayload" )
217
+ Iterable . logger . log ( "getLastPushPayload" )
218
+
211
219
return RNIterableAPI . getLastPushPayload ( )
212
220
}
213
221
214
222
/**
215
223
*
216
224
*/
217
225
static getAttributionInfo ( ) : Promise < IterableAttributionInfo | undefined > {
218
- console . log ( "getAttributionInfo" )
226
+ Iterable . logger . log ( "getAttributionInfo" )
227
+
219
228
return RNIterableAPI . getAttributionInfo ( ) . then ( ( dict : any | undefined ) => {
220
229
if ( dict ) {
221
230
return new IterableAttributionInfo ( dict [ "campaignId" ] as number , dict [ "templateId" ] as number , dict [ "messageId" ] as string )
@@ -231,7 +240,8 @@ class Iterable {
231
240
* @param {attributionInfo } IterableAttributionInfo
232
241
*/
233
242
static setAttributionInfo ( attributionInfo ?: IterableAttributionInfo ) {
234
- console . log ( "setAttributionInfo" )
243
+ Iterable . logger . log ( "setAttributionInfo" )
244
+
235
245
RNIterableAPI . setAttributionInfo ( attributionInfo )
236
246
}
237
247
@@ -244,7 +254,8 @@ class Iterable {
244
254
* @param {any | undefined } dataFields
245
255
*/
246
256
static trackPushOpenWithCampaignId ( campaignId : number , templateId : number , messageId : string | undefined , appAlreadyRunning : boolean , dataFields : any | undefined ) {
247
- console . log ( "trackPushOpenWithCampaignId" )
257
+ Iterable . logger . log ( "trackPushOpenWithCampaignId" )
258
+
248
259
RNIterableAPI . trackPushOpenWithCampaignId ( campaignId , templateId , messageId , appAlreadyRunning , dataFields )
249
260
}
250
261
@@ -253,13 +264,15 @@ class Iterable {
253
264
* @param {Array<IterableCommerceItem> } items
254
265
*/
255
266
static updateCart ( items : Array < IterableCommerceItem > ) {
256
- console . log ( "updateCart" )
267
+ Iterable . logger . log ( "updateCart" )
268
+
257
269
RNIterableAPI . updateCart ( items )
258
270
}
259
271
260
272
static wakeApp ( ) {
261
273
if ( Platform . OS === "android" ) {
262
- console . log ( 'Attempting to wake the app' )
274
+ Iterable . logger . log ( "Attempting to wake the app" )
275
+
263
276
RNIterableAPI . wakeApp ( ) ;
264
277
}
265
278
}
@@ -271,7 +284,8 @@ class Iterable {
271
284
* @param {any | undefined } dataFields
272
285
*/
273
286
static trackPurchase ( total : number , items : Array < IterableCommerceItem > , dataFields : any | undefined ) {
274
- console . log ( "trackPurchase" )
287
+ Iterable . logger . log ( "trackPurchase" )
288
+
275
289
RNIterableAPI . trackPurchase ( total , items , dataFields )
276
290
}
277
291
@@ -281,7 +295,8 @@ class Iterable {
281
295
* @param {IterableInAppLocation } location
282
296
*/
283
297
static trackInAppOpen ( message : IterableInAppMessage , location : IterableInAppLocation ) {
284
- console . log ( "trackInAppOpen" )
298
+ Iterable . logger . log ( "trackInAppOpen" )
299
+
285
300
RNIterableAPI . trackInAppOpen ( message . messageId , location )
286
301
}
287
302
@@ -292,7 +307,8 @@ class Iterable {
292
307
* @param {string } clickedUrl
293
308
*/
294
309
static trackInAppClick ( message : IterableInAppMessage , location : IterableInAppLocation , clickedUrl : string ) {
295
- console . log ( "trackInAppClick" )
310
+ Iterable . logger . log ( "trackInAppClick" )
311
+
296
312
RNIterableAPI . trackInAppClick ( message . messageId , location , clickedUrl )
297
313
}
298
314
@@ -304,7 +320,8 @@ class Iterable {
304
320
* @param {string } clickedUrl
305
321
*/
306
322
static trackInAppClose ( message : IterableInAppMessage , location : IterableInAppLocation , source : IterableInAppCloseSource , clickedUrl ?: string | undefined ) {
307
- console . log ( "trackInAppClose" )
323
+ Iterable . logger . log ( "trackInAppClose" )
324
+
308
325
RNIterableAPI . trackInAppClose ( message . messageId , location , source , clickedUrl )
309
326
}
310
327
@@ -315,7 +332,8 @@ class Iterable {
315
332
* @param {IterableInAppDeleteSource } source
316
333
*/
317
334
static inAppConsume ( message : IterableInAppMessage , location : IterableInAppLocation , source : IterableInAppDeleteSource ) {
318
- console . log ( "inAppConsume" )
335
+ Iterable . logger . log ( "inAppConsume" )
336
+
319
337
RNIterableAPI . inAppConsume ( message . messageId , location , source )
320
338
}
321
339
@@ -325,7 +343,8 @@ class Iterable {
325
343
* @param {any | undefined } dataFields
326
344
*/
327
345
static trackEvent ( name : string , dataFields : any | undefined ) {
328
- console . log ( "trackEvent" )
346
+ Iterable . logger . log ( "trackEvent" )
347
+
329
348
RNIterableAPI . trackEvent ( name , dataFields )
330
349
}
331
350
@@ -335,7 +354,8 @@ class Iterable {
335
354
* @param {boolean } mergeNestedObjects Whether to merge top level objects instead of overwriting
336
355
*/
337
356
static updateUser ( dataFields : any , mergeNestedObjects : boolean ) {
338
- console . log ( "updateUser" )
357
+ Iterable . logger . log ( "updateUser" )
358
+
339
359
RNIterableAPI . updateUser ( dataFields , mergeNestedObjects )
340
360
}
341
361
@@ -344,7 +364,8 @@ class Iterable {
344
364
* @param email the new email to set
345
365
*/
346
366
static updateEmail ( email : string ) {
347
- console . log ( "updateEmail" )
367
+ Iterable . logger . log ( "updateEmail" )
368
+
348
369
RNIterableAPI . updateEmail ( email )
349
370
}
350
371
@@ -353,7 +374,8 @@ class Iterable {
353
374
* @param {string } link URL in string form to be either opened as an app link or as a normal one
354
375
*/
355
376
static handleAppLink ( link : string ) : Promise < boolean > {
356
- console . log ( "handleAppLink" )
377
+ Iterable . logger . log ( "handleAppLink" )
378
+
357
379
return RNIterableAPI . handleAppLink ( link )
358
380
}
359
381
@@ -372,7 +394,8 @@ class Iterable {
372
394
subscribedMessageTypeIds : Array < number > | undefined ,
373
395
campaignId : number ,
374
396
templateId : number ) {
375
- console . log ( "updateSubscriptions" )
397
+ Iterable . logger . log ( "updateSubscriptions" )
398
+
376
399
RNIterableAPI . updateSubscriptions ( emailListIds , unsubscribedChannelIds , unsubscribedMessageTypeIds , subscribedMessageTypeIds , campaignId , templateId )
377
400
}
378
401
@@ -391,6 +414,7 @@ class Iterable {
391
414
const url = dict [ "url" ]
392
415
const context = IterableActionContext . fromDict ( dict [ "context" ] )
393
416
Iterable . wakeApp ( )
417
+
394
418
if ( Platform . OS === "android" ) {
395
419
//Give enough time for Activity to wake up.
396
420
setTimeout ( ( ) => {
@@ -443,7 +467,7 @@ class Iterable {
443
467
. then ( canOpen => {
444
468
if ( canOpen ) { Linking . openURL ( url ) }
445
469
} )
446
- . catch ( reason => { console . log ( "could not open url: " + reason ) } )
470
+ . catch ( reason => { Iterable . logger . log ( "could not open url: " + reason ) } )
447
471
}
448
472
}
449
473
}
0 commit comments