@@ -16,6 +16,7 @@ import {
1616import IterableInAppManager from './IterableInAppManager'
1717import IterableInAppMessage from './IterableInAppMessage'
1818import IterableConfig from './IterableConfig'
19+ import { IterableLogger } from './IterableLogger'
1920
2021const RNIterableAPI = NativeModules . RNIterableAPI
2122const RNEventEmitter = new NativeEventEmitter ( RNIterableAPI )
@@ -121,15 +122,10 @@ enum EventName {
121122}
122123
123124class Iterable {
124- /**
125- * inAppManager instance
126- */
127125 static inAppManager = new IterableInAppManager ( )
128126
127+ static logger : IterableLogger
129128
130- /**
131- * savedConfig instance.
132- */
133129 static savedConfig : IterableConfig
134130
135131 /**
@@ -138,9 +134,12 @@ class Iterable {
138134 * @param {IterableConfig } config
139135 */
140136 static initialize ( apiKey : string , config : IterableConfig = new IterableConfig ( ) ) : Promise < boolean > {
141- console . log ( "initialize: " + apiKey ) ;
142-
143137 Iterable . savedConfig = config
138+
139+ Iterable . logger = new IterableLogger ( Iterable . savedConfig )
140+
141+ Iterable . logger . log ( "initialize: " + apiKey )
142+
144143 this . setupEventHandlers ( )
145144 const version = this . getVersionFromPackageJson ( )
146145
@@ -152,9 +151,12 @@ class Iterable {
152151 * This method is used internally to connect to staging environment.
153152 */
154153 static initialize2 ( apiKey : string , config : IterableConfig = new IterableConfig ( ) , apiEndPoint : string ) : Promise < boolean > {
155- console . log ( "initialize2: " + apiKey ) ;
156-
157154 Iterable . savedConfig = config
155+
156+ Iterable . logger = new IterableLogger ( Iterable . savedConfig )
157+
158+ Iterable . logger . log ( "initialize2: " + apiKey ) ;
159+
158160 this . setupEventHandlers ( )
159161 const version = this . getVersionFromPackageJson ( )
160162
@@ -166,15 +168,17 @@ class Iterable {
166168 * @param {string | undefined } email the email address of the user
167169 */
168170 static setEmail ( email : string | undefined ) {
169- console . log ( "setEmail: " + email )
171+ Iterable . logger . log ( "setEmail: " + email )
172+
170173 RNIterableAPI . setEmail ( email )
171174 }
172175
173176 /**
174177 * Get the email of the current user
175178 */
176179 static getEmail ( ) : Promise < string | undefined > {
177- console . log ( "getEmail" )
180+ Iterable . logger . log ( "getEmail" )
181+
178182 return RNIterableAPI . getEmail ( )
179183 }
180184
@@ -183,39 +187,44 @@ class Iterable {
183187 * @param {string | undefined } userId the ID of the user
184188 */
185189 static setUserId ( userId : string | undefined ) {
186- console . log ( "setUserId: " + userId )
190+ Iterable . logger . log ( "setUserId: " + userId )
191+
187192 RNIterableAPI . setUserId ( userId )
188193 }
189194
190195 /**
191196 * Get the user ID of the current user
192197 */
193198 static getUserId ( ) : Promise < string | undefined > {
194- console . log ( "getUserId" )
199+ Iterable . logger . log ( "getUserId" )
200+
195201 return RNIterableAPI . getUserId ( )
196202 }
197203
198204 /**
199205 *
200206 */
201207 static disableDeviceForCurrentUser ( ) {
202- console . log ( "disableDeviceForCurrentUser" )
208+ Iterable . logger . log ( "disableDeviceForCurrentUser" )
209+
203210 RNIterableAPI . disableDeviceForCurrentUser ( )
204211 }
205212
206213 /**
207214 *
208215 */
209216 static getLastPushPayload ( ) : Promise < any | undefined > {
210- console . log ( "getLastPushPayload" )
217+ Iterable . logger . log ( "getLastPushPayload" )
218+
211219 return RNIterableAPI . getLastPushPayload ( )
212220 }
213221
214222 /**
215223 *
216224 */
217225 static getAttributionInfo ( ) : Promise < IterableAttributionInfo | undefined > {
218- console . log ( "getAttributionInfo" )
226+ Iterable . logger . log ( "getAttributionInfo" )
227+
219228 return RNIterableAPI . getAttributionInfo ( ) . then ( ( dict : any | undefined ) => {
220229 if ( dict ) {
221230 return new IterableAttributionInfo ( dict [ "campaignId" ] as number , dict [ "templateId" ] as number , dict [ "messageId" ] as string )
@@ -231,7 +240,8 @@ class Iterable {
231240 * @param {attributionInfo } IterableAttributionInfo
232241 */
233242 static setAttributionInfo ( attributionInfo ?: IterableAttributionInfo ) {
234- console . log ( "setAttributionInfo" )
243+ Iterable . logger . log ( "setAttributionInfo" )
244+
235245 RNIterableAPI . setAttributionInfo ( attributionInfo )
236246 }
237247
@@ -244,7 +254,8 @@ class Iterable {
244254 * @param {any | undefined } dataFields
245255 */
246256 static trackPushOpenWithCampaignId ( campaignId : number , templateId : number , messageId : string | undefined , appAlreadyRunning : boolean , dataFields : any | undefined ) {
247- console . log ( "trackPushOpenWithCampaignId" )
257+ Iterable . logger . log ( "trackPushOpenWithCampaignId" )
258+
248259 RNIterableAPI . trackPushOpenWithCampaignId ( campaignId , templateId , messageId , appAlreadyRunning , dataFields )
249260 }
250261
@@ -253,13 +264,15 @@ class Iterable {
253264 * @param {Array<IterableCommerceItem> } items
254265 */
255266 static updateCart ( items : Array < IterableCommerceItem > ) {
256- console . log ( "updateCart" )
267+ Iterable . logger . log ( "updateCart" )
268+
257269 RNIterableAPI . updateCart ( items )
258270 }
259271
260272 static wakeApp ( ) {
261273 if ( Platform . OS === "android" ) {
262- console . log ( 'Attempting to wake the app' )
274+ Iterable . logger . log ( "Attempting to wake the app" )
275+
263276 RNIterableAPI . wakeApp ( ) ;
264277 }
265278 }
@@ -271,7 +284,8 @@ class Iterable {
271284 * @param {any | undefined } dataFields
272285 */
273286 static trackPurchase ( total : number , items : Array < IterableCommerceItem > , dataFields : any | undefined ) {
274- console . log ( "trackPurchase" )
287+ Iterable . logger . log ( "trackPurchase" )
288+
275289 RNIterableAPI . trackPurchase ( total , items , dataFields )
276290 }
277291
@@ -281,7 +295,8 @@ class Iterable {
281295 * @param {IterableInAppLocation } location
282296 */
283297 static trackInAppOpen ( message : IterableInAppMessage , location : IterableInAppLocation ) {
284- console . log ( "trackInAppOpen" )
298+ Iterable . logger . log ( "trackInAppOpen" )
299+
285300 RNIterableAPI . trackInAppOpen ( message . messageId , location )
286301 }
287302
@@ -292,7 +307,8 @@ class Iterable {
292307 * @param {string } clickedUrl
293308 */
294309 static trackInAppClick ( message : IterableInAppMessage , location : IterableInAppLocation , clickedUrl : string ) {
295- console . log ( "trackInAppClick" )
310+ Iterable . logger . log ( "trackInAppClick" )
311+
296312 RNIterableAPI . trackInAppClick ( message . messageId , location , clickedUrl )
297313 }
298314
@@ -304,7 +320,8 @@ class Iterable {
304320 * @param {string } clickedUrl
305321 */
306322 static trackInAppClose ( message : IterableInAppMessage , location : IterableInAppLocation , source : IterableInAppCloseSource , clickedUrl ?: string | undefined ) {
307- console . log ( "trackInAppClose" )
323+ Iterable . logger . log ( "trackInAppClose" )
324+
308325 RNIterableAPI . trackInAppClose ( message . messageId , location , source , clickedUrl )
309326 }
310327
@@ -315,7 +332,8 @@ class Iterable {
315332 * @param {IterableInAppDeleteSource } source
316333 */
317334 static inAppConsume ( message : IterableInAppMessage , location : IterableInAppLocation , source : IterableInAppDeleteSource ) {
318- console . log ( "inAppConsume" )
335+ Iterable . logger . log ( "inAppConsume" )
336+
319337 RNIterableAPI . inAppConsume ( message . messageId , location , source )
320338 }
321339
@@ -325,7 +343,8 @@ class Iterable {
325343 * @param {any | undefined } dataFields
326344 */
327345 static trackEvent ( name : string , dataFields : any | undefined ) {
328- console . log ( "trackEvent" )
346+ Iterable . logger . log ( "trackEvent" )
347+
329348 RNIterableAPI . trackEvent ( name , dataFields )
330349 }
331350
@@ -335,7 +354,8 @@ class Iterable {
335354 * @param {boolean } mergeNestedObjects Whether to merge top level objects instead of overwriting
336355 */
337356 static updateUser ( dataFields : any , mergeNestedObjects : boolean ) {
338- console . log ( "updateUser" )
357+ Iterable . logger . log ( "updateUser" )
358+
339359 RNIterableAPI . updateUser ( dataFields , mergeNestedObjects )
340360 }
341361
@@ -344,7 +364,8 @@ class Iterable {
344364 * @param email the new email to set
345365 */
346366 static updateEmail ( email : string ) {
347- console . log ( "updateEmail" )
367+ Iterable . logger . log ( "updateEmail" )
368+
348369 RNIterableAPI . updateEmail ( email )
349370 }
350371
@@ -353,7 +374,8 @@ class Iterable {
353374 * @param {string } link URL in string form to be either opened as an app link or as a normal one
354375 */
355376 static handleAppLink ( link : string ) : Promise < boolean > {
356- console . log ( "handleAppLink" )
377+ Iterable . logger . log ( "handleAppLink" )
378+
357379 return RNIterableAPI . handleAppLink ( link )
358380 }
359381
@@ -372,7 +394,8 @@ class Iterable {
372394 subscribedMessageTypeIds : Array < number > | undefined ,
373395 campaignId : number ,
374396 templateId : number ) {
375- console . log ( "updateSubscriptions" )
397+ Iterable . logger . log ( "updateSubscriptions" )
398+
376399 RNIterableAPI . updateSubscriptions ( emailListIds , unsubscribedChannelIds , unsubscribedMessageTypeIds , subscribedMessageTypeIds , campaignId , templateId )
377400 }
378401
@@ -391,6 +414,7 @@ class Iterable {
391414 const url = dict [ "url" ]
392415 const context = IterableActionContext . fromDict ( dict [ "context" ] )
393416 Iterable . wakeApp ( )
417+
394418 if ( Platform . OS === "android" ) {
395419 //Give enough time for Activity to wake up.
396420 setTimeout ( ( ) => {
@@ -443,7 +467,7 @@ class Iterable {
443467 . then ( canOpen => {
444468 if ( canOpen ) { Linking . openURL ( url ) }
445469 } )
446- . catch ( reason => { console . log ( "could not open url: " + reason ) } )
470+ . catch ( reason => { Iterable . logger . log ( "could not open url: " + reason ) } )
447471 }
448472 }
449473 }
0 commit comments