@@ -45,6 +45,7 @@ public class IterableApi {
45
45
46
46
IterableApiClient apiClient = new IterableApiClient (new IterableApiAuthProvider ());
47
47
private @ Nullable IterableInAppManager inAppManager ;
48
+ private @ Nullable IterableEmbeddedManager embeddedManager ;
48
49
private String inboxSessionId ;
49
50
private IterableAuthManager authManager ;
50
51
private HashMap <String , String > deviceAttributes = new HashMap <>();
@@ -225,6 +226,28 @@ void getInAppMessages(int count, @NonNull IterableHelper.IterableActionHandler o
225
226
apiClient .getInAppMessages (count , onCallback );
226
227
}
227
228
229
+ /**
230
+ * A package-private method to get a list of Embedded Messages from Iterable;
231
+ * Passes the result to the callback.
232
+ * To get list of messages as a list of EmbeddedMessages in memory, use
233
+ * {@link IterableEmbeddedManager#getEmbeddedMessages()} instead
234
+ *
235
+ * @param onCallback
236
+ */
237
+ void getEmbeddedMessages (@ NonNull IterableHelper .IterableActionHandler onCallback ) {
238
+ if (!checkSDKInitialization ()) {
239
+ return ;
240
+ }
241
+ apiClient .getEmbeddedMessages (onCallback );
242
+ }
243
+
244
+ void getEmbeddedMessages (@ NonNull IterableHelper .SuccessHandler onSuccess , @ NonNull IterableHelper .FailureHandler onFailure ) {
245
+ if (!checkSDKInitialization ()) {
246
+ return ;
247
+ }
248
+ apiClient .getEmbeddedMessages (onSuccess , onFailure );
249
+ }
250
+
228
251
/**
229
252
* Tracks in-app delivery events (per in-app)
230
253
* @param message the in-app message to be tracked as delivered */
@@ -241,6 +264,22 @@ void trackInAppDelivery(@NonNull IterableInAppMessage message) {
241
264
apiClient .trackInAppDelivery (message );
242
265
}
243
266
267
+ /**
268
+ * Tracks embedded message received events (per embedded message)
269
+ * @param message the embedded message to be tracked as received */
270
+ void trackEmbeddedMessageReceived (@ NonNull IterableEmbeddedMessage message ) {
271
+ if (!checkSDKInitialization ()) {
272
+ return ;
273
+ }
274
+
275
+ if (message == null ) {
276
+ IterableLogger .e (TAG , "trackEmbeddedMessageReceived: message is null" );
277
+ return ;
278
+ }
279
+
280
+ apiClient .trackEmbeddedMessageReceived (message );
281
+ }
282
+
244
283
private String getPushIntegrationName () {
245
284
if (config .pushIntegrationName != null ) {
246
285
return config .pushIntegrationName ;
@@ -512,6 +551,10 @@ public static void initialize(@NonNull Context context, @NonNull String apiKey,
512
551
sharedInstance .config .useInMemoryStorageForInApps );
513
552
}
514
553
554
+ if (sharedInstance .embeddedManager == null ) {
555
+ sharedInstance .embeddedManager = new IterableEmbeddedManager (null , null );
556
+ }
557
+
515
558
loadLastSavedConfiguration (context );
516
559
IterablePushNotificationUtil .processPendingAction (context );
517
560
if (DeviceInfoUtils .isFireTV (context .getPackageManager ())) {
@@ -541,12 +584,20 @@ public static void setContext(Context context) {
541
584
this .inAppManager = inAppManager ;
542
585
}
543
586
587
+ @ VisibleForTesting
588
+ IterableApi (IterableInAppManager inAppManager , IterableEmbeddedManager embeddedManager ) {
589
+ config = new IterableConfig .Builder ().build ();
590
+ this .inAppManager = inAppManager ;
591
+ this .embeddedManager = embeddedManager ;
592
+ }
593
+
544
594
@ VisibleForTesting
545
595
IterableApi (IterableApiClient apiClient , IterableInAppManager inAppManager ) {
546
596
config = new IterableConfig .Builder ().build ();
547
597
this .apiClient = apiClient ;
548
598
this .inAppManager = inAppManager ;
549
599
}
600
+
550
601
//endregion
551
602
552
603
//region SDK public functions
@@ -564,6 +615,15 @@ public IterableInAppManager getInAppManager() {
564
615
return inAppManager ;
565
616
}
566
617
618
+ @ NonNull
619
+ public IterableEmbeddedManager embeddedManager () {
620
+ if (embeddedManager == null ) {
621
+ throw new RuntimeException ("IterableApi must be initialized before calling getFlexManager(). " +
622
+ "Make sure you call IterableApi#initialize() in Application#onCreate" );
623
+ }
624
+ return embeddedManager ;
625
+ }
626
+
567
627
/**
568
628
* Returns the attribution information ({@link IterableAttributionInfo}) for last push open
569
629
* or app link click from an email.
@@ -1089,6 +1149,26 @@ public void trackInAppClose(@NonNull IterableInAppMessage message, @Nullable Str
1089
1149
1090
1150
apiClient .trackInAppClose (message , clickedURL , closeAction , clickLocation , inboxSessionId );
1091
1151
}
1152
+
1153
+ /**
1154
+ * Tracks when a link inside an embedded message is clicked
1155
+ * @param message the embedded message to be tracked
1156
+ * @param buttonIdentifier identifier that determines which button or if embedded message itself was clicked
1157
+ * @param clickedUrl the URL of the clicked button or assigned to the embedded message itself
1158
+ */
1159
+ public void trackEmbeddedClick (@ NonNull IterableEmbeddedMessage message , @ Nullable String buttonIdentifier , @ Nullable String clickedUrl ) {
1160
+ if (!checkSDKInitialization ()) {
1161
+ return ;
1162
+ }
1163
+
1164
+ if (message == null ) {
1165
+ IterableLogger .e (TAG , "trackEmbeddedClick: message is null" );
1166
+ return ;
1167
+ }
1168
+
1169
+ apiClient .trackEmbeddedClick (message , buttonIdentifier , clickedUrl );
1170
+ }
1171
+
1092
1172
//endregion
1093
1173
1094
1174
//region DEPRECATED - API public functions
@@ -1203,5 +1283,24 @@ public void setInboxSessionId(@Nullable String inboxSessionId) {
1203
1283
public void clearInboxSessionId () {
1204
1284
this .inboxSessionId = null ;
1205
1285
}
1286
+
1287
+ @ RestrictTo (RestrictTo .Scope .LIBRARY_GROUP )
1288
+ public void trackEmbeddedSession (@ NonNull IterableEmbeddedSession session ) {
1289
+ if (!checkSDKInitialization ()) {
1290
+ return ;
1291
+ }
1292
+
1293
+ if (session == null ) {
1294
+ IterableLogger .e (TAG , "trackEmbeddedSession: session is null" );
1295
+ return ;
1296
+ }
1297
+
1298
+ if (session .getStart () == null || session .getEnd () == null ) {
1299
+ IterableLogger .e (TAG , "trackEmbeddedSession: sessionStartTime and sessionEndTime must be set" );
1300
+ return ;
1301
+ }
1302
+
1303
+ apiClient .trackEmbeddedSession (session );
1304
+ }
1206
1305
//endregion
1207
1306
}
0 commit comments