1
1
/* eslint-disable class-methods-use-this */
2
2
import get from 'get-value' ;
3
3
import { ScriptLoader } from '@rudderstack/analytics-js-common/v1.1/utils/ScriptLoader' ;
4
- import { NAME } from '@rudderstack/analytics-js-common/constants/integrations/Iterable/constants' ;
4
+ import {
5
+ NAME ,
6
+ DISPLAY_NAME ,
7
+ } from '@rudderstack/analytics-js-common/constants/integrations/Iterable/constants' ;
5
8
import Logger from '../../utils/logger' ;
6
9
import {
7
10
formPurchaseEventPayload ,
@@ -53,22 +56,21 @@ class Iterable {
53
56
}
54
57
55
58
init ( ) {
56
- logger . debug ( '===In init Iterable===' ) ;
57
59
ScriptLoader ( 'iterable-web' , 'https://unpkg.com/@iterable/web-sdk/index.js' ) ;
58
60
}
59
61
60
62
isLoaded ( ) {
61
- logger . debug ( '=== In isLoaded Iterable===' ) ;
63
+ logger . debug ( ` In isLoaded ${ DISPLAY_NAME } ` ) ;
62
64
return ! ! window [ iterableWebSdk ] ;
63
65
}
64
66
65
67
isReady ( ) {
66
- logger . debug ( '=== In isReady Iterable===' ) ;
68
+ logger . debug ( ` In isReady ${ DISPLAY_NAME } ` ) ;
67
69
return ! ! window [ iterableWebSdk ] ;
68
70
}
69
71
70
72
identify ( rudderElement ) {
71
- logger . debug ( '=== In identify Iterable' ) ;
73
+ logger . debug ( ` In ${ DISPLAY_NAME } identify` ) ;
72
74
73
75
const { message } = rudderElement ;
74
76
const { integrations, traits, context, userId } = message ;
@@ -77,7 +79,9 @@ class Iterable {
77
79
const jwtToken = extractJWT ( integrations ) ;
78
80
79
81
if ( ! jwtToken ) {
80
- logger . error ( 'The JWT token was not passed, The SDK could not be initialised' ) ;
82
+ logger . error (
83
+ `${ DISPLAY_NAME } : The JWT token was not passed, The SDK could not be initialized` ,
84
+ ) ;
81
85
return ;
82
86
}
83
87
@@ -86,11 +90,11 @@ class Iterable {
86
90
87
91
if ( this . initialisationIdentifier === 'userId' ) {
88
92
wd . setUserID ( userId ) . then ( ( ) => {
89
- logger . debug ( ' userId set' ) ;
93
+ logger . debug ( ` ${ DISPLAY_NAME } : userId set` ) ;
90
94
} ) ;
91
95
} else {
92
96
wd . setEmail ( userEmail ) . then ( ( ) => {
93
- logger . debug ( ' userEmail set' ) ;
97
+ logger . debug ( ` ${ DISPLAY_NAME } : userEmail set` ) ;
94
98
} ) ;
95
99
}
96
100
/* Available pop-up push notification settings configurable from UI
@@ -123,15 +127,15 @@ class Iterable {
123
127
}
124
128
125
129
track ( rudderElement ) {
126
- logger . debug ( '=== In track Iterable===' ) ;
130
+ logger . debug ( ` In ${ DISPLAY_NAME } track` ) ;
127
131
128
132
const { message } = rudderElement ;
129
133
const { event, properties } = message ;
130
134
const eventPayload = removeUndefinedAndNullValues ( properties ) ;
131
135
const userEmail = get ( message , 'context.traits.email' ) ;
132
136
const userId = get ( message , 'userId' ) ;
133
137
if ( ! event ) {
134
- logger . error ( ' Event name not present' ) ;
138
+ logger . error ( ` ${ DISPLAY_NAME } : Event name not present` ) ;
135
139
return ;
136
140
}
137
141
if (
@@ -148,7 +152,7 @@ class Iterable {
148
152
eventName : 'Track getInAppMessages' ,
149
153
dataFields : eventPayload ,
150
154
} )
151
- . then ( logger . debug ( ' Web in-app push triggered' ) ) ;
155
+ . then ( logger . debug ( ` ${ DISPLAY_NAME } : Web in-app push triggered` ) ) ;
152
156
}
153
157
} else if (
154
158
isNotEmpty ( this . purchaseEventMapping ) &&
@@ -173,10 +177,12 @@ class Iterable {
173
177
*/
174
178
// Either email or userId must be passed in to identify the user.
175
179
// If both are passed in, email takes precedence.
176
- logger . debug ( `The event ${ event } is not mapped in the dashboard, firing a custom event` ) ;
180
+ logger . debug (
181
+ `${ DISPLAY_NAME } : The event ${ event } is not mapped in the dashboard, firing a custom event` ,
182
+ ) ;
177
183
window [ iterableWebSdk ]
178
184
. track ( { email : userEmail , userId, eventName : event , dataFields : eventPayload } )
179
- . then ( logger . debug ( ' Track a custom event.' ) ) ;
185
+ . then ( logger . debug ( ` ${ DISPLAY_NAME } : Track a custom event` ) ) ;
180
186
}
181
187
}
182
188
}
0 commit comments