Skip to content

Commit e8a6af9

Browse files
committed
dispatcher: add support for Batch WebView In-App format
1 parent d169b74 commit e8a6af9

File tree

4 files changed

+124
-5
lines changed

4 files changed

+124
-5
lines changed

atinternet-dispatcher/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ android {
3939
}
4040

4141
dependencies {
42-
api 'com.batch.android:batch-sdk:1.15.0'
42+
api 'com.batch.android:batch-sdk:1.17.0'
4343
api "com.atinternet:Tracker:$atInternetVersion"
4444
implementation "androidx.annotation:annotation:$androidXLibraryVersion"
4545

atinternet-dispatcher/src/main/java/com/batch/android/dispatcher/atinternet/AtInternetDispatcher.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import androidx.annotation.Nullable;
77

88
import com.atinternet.tracker.ATInternet;
9+
import com.atinternet.tracker.CustomVar;
910
import com.atinternet.tracker.Publisher;
1011
import com.atinternet.tracker.Screen;
1112
import com.atinternet.tracker.Tracker;
@@ -37,8 +38,10 @@ public class AtInternetDispatcher implements BatchEventDispatcher
3738
private static final String NOTIFICATION_DISMISS_NAME = "DismissedBatchPushNotification";
3839
private static final String MESSAGING_SHOW_NAME = "ShowedBatchInAppMessage";
3940
private static final String MESSAGING_CLOSE_NAME = "ClosedBatchInAppMessage";
41+
private static final String MESSAGING_CLOSE_ERROR_NAME = "ClosedErrorBatchInAppMessage";
4042
private static final String MESSAGING_AUTO_CLOSE_NAME = "AutoClosedBatchInAppMessage";
4143
private static final String MESSAGING_CLICK_NAME = "ClickedBatchInAppMessage";
44+
private static final String MESSAGING_WEBVIEW_CLICK_NAME = "WebViewClickedBatchInAppMessage";
4245
private static final String UNKNOWN_EVENT_NAME = "UnknownBatchMessage";
4346

4447
private final Map<String, Tracker> trackerCache;
@@ -70,8 +73,12 @@ public void dispatchEvent(@NonNull Batch.EventDispatcher.Type type,
7073
if (xtorTag != null) {
7174
screen.Campaign(xtorTag);
7275
}
73-
screen.sendView();
7476

77+
String webViewButtonId = payload.getWebViewAnalyticsID();
78+
if (webViewButtonId != null) {
79+
screen.CustomVars().add(1, webViewButtonId, CustomVar.CustomVarType.Screen);
80+
}
81+
screen.sendView();
7582
}
7683

7784
/**
@@ -137,9 +144,16 @@ private void dispatchAsOnSiteAd(Batch.EventDispatcher.Type type, Batch.EventDisp
137144
}
138145
publisher.setAdvertiserId("[batch]");
139146

147+
String webViewButtonId = payload.getWebViewAnalyticsID();
148+
if (webViewButtonId != null) {
149+
publisher.setVariant("[" + webViewButtonId + "]");
150+
}
151+
140152
if (isImpression(type)) {
141153
publisher.sendImpression();
142-
} else if (isClick(type) && payload.isPositiveAction()) {
154+
} else if (isClick(type) &&
155+
(payload.isPositiveAction() || type == Batch.EventDispatcher.Type.MESSAGING_WEBVIEW_CLICK)) {
156+
// We send the click if it's a positive action or if it's a click inside a WebView In-App
143157
publisher.sendTouch();
144158
}
145159
}
@@ -200,7 +214,8 @@ private static boolean isImpression(Batch.EventDispatcher.Type type) {
200214

201215
private static boolean isClick(Batch.EventDispatcher.Type type) {
202216
return type.equals(Batch.EventDispatcher.Type.NOTIFICATION_OPEN) ||
203-
type.equals(Batch.EventDispatcher.Type.MESSAGING_CLICK);
217+
type.equals(Batch.EventDispatcher.Type.MESSAGING_CLICK) ||
218+
type.equals(Batch.EventDispatcher.Type.MESSAGING_WEBVIEW_CLICK);
204219
}
205220

206221
private static Map<String, String> getFragmentMap(String fragment)
@@ -230,8 +245,12 @@ private static String getATEventName(Batch.EventDispatcher.Type type) {
230245
return MESSAGING_CLOSE_NAME;
231246
case MESSAGING_AUTO_CLOSE:
232247
return MESSAGING_AUTO_CLOSE_NAME;
248+
case MESSAGING_CLOSE_ERROR:
249+
return MESSAGING_CLOSE_ERROR_NAME;
233250
case MESSAGING_CLICK:
234251
return MESSAGING_CLICK_NAME;
252+
case MESSAGING_WEBVIEW_CLICK:
253+
return MESSAGING_WEBVIEW_CLICK_NAME;
235254
}
236255
return UNKNOWN_EVENT_NAME;
237256
}

atinternet-dispatcher/src/test/java/com/batch/android/dispatcher/atinternet/AtInternetDispatcherTest.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import android.os.Bundle;
55

66
import com.atinternet.tracker.ATInternet;
7+
import com.atinternet.tracker.CustomVar;
8+
import com.atinternet.tracker.CustomVars;
79
import com.atinternet.tracker.Publisher;
810
import com.atinternet.tracker.Publishers;
911
import com.atinternet.tracker.Screen;
@@ -74,6 +76,7 @@ public void testNotificationDisplay() {
7476
Mockito.when(screens.add("DisplayedBatchPushNotification")).thenReturn(screen);
7577

7678
TestEventPayload payload = new TestEventPayload(null,
79+
null,
7780
null,
7881
new Bundle());
7982

@@ -103,6 +106,7 @@ public void testNotificationDisplayCampaignLabelFragment() {
103106
Mockito.when(screens.add("DisplayedBatchPushNotification")).thenReturn(screen);
104107

105108
TestEventPayload payload = new TestEventPayload(null,
109+
null,
106110
"https://batch.com.com/test#xtor=" + xtor,
107111
new Bundle());
108112

@@ -133,6 +137,7 @@ public void testNotificationDisplayCampaignLabelFragmentEncode() {
133137
Mockito.when(screens.add("DisplayedBatchPushNotification")).thenReturn(screen);
134138

135139
TestEventPayload payload = new TestEventPayload(null,
140+
null,
136141
"https://batch.com/test#xtor=" + xtor,
137142
new Bundle());
138143

@@ -162,6 +167,7 @@ public void testNotificationDisplayHostLessDeeplinkQuery() {
162167
Mockito.when(screens.add("DisplayedBatchPushNotification")).thenReturn(screen);
163168

164169
TestEventPayload payload = new TestEventPayload(null,
170+
null,
165171
"batch://?xtor=" + xtor,
166172
new Bundle());
167173

@@ -191,6 +197,7 @@ public void testNotificationDisplayHostLessDeeplinkFragment() {
191197
Mockito.when(screens.add("DisplayedBatchPushNotification")).thenReturn(screen);
192198

193199
TestEventPayload payload = new TestEventPayload(null,
200+
null,
194201
"batch://#xtor=" + xtor,
195202
new Bundle());
196203

@@ -220,6 +227,7 @@ public void testNotificationOpenCampaignLabelQuery() {
220227
Mockito.when(screens.add("OpenedBatchPushNotification")).thenReturn(screen);
221228

222229
TestEventPayload payload = new TestEventPayload(null,
230+
null,
223231
"https://batch.com/test?xtor=" + xtor,
224232
new Bundle(), true);
225233

@@ -250,6 +258,7 @@ public void testNotificationOpenCampaignLabelQueryEncode() {
250258
Mockito.when(screens.add("OpenedBatchPushNotification")).thenReturn(screen);
251259

252260
TestEventPayload payload = new TestEventPayload(null,
261+
null,
253262
"https://batch.com/test?xtor=" + xtor,
254263
new Bundle(), true);
255264

@@ -281,6 +290,7 @@ public void testNotificationOpenCampaignLabelCustomPayload() {
281290
Bundle customPayload = new Bundle();
282291
customPayload.putString("xtor", xtor);
283292
TestEventPayload payload = new TestEventPayload(null,
293+
null,
284294
null,
285295
customPayload, true);
286296

@@ -311,6 +321,7 @@ public void testNotificationOpenCampaignLabelTrackingID() {
311321

312322
Bundle customPayload = new Bundle();
313323
TestEventPayload payload = new TestEventPayload(xtor,
324+
null,
314325
null,
315326
customPayload, true);
316327

@@ -338,6 +349,7 @@ public void testNotificationOpenNonPositive() {
338349

339350
Bundle customPayload = new Bundle();
340351
TestEventPayload payload = new TestEventPayload(null,
352+
null,
341353
null,
342354
customPayload, false);
343355

@@ -365,6 +377,7 @@ public void testNotificationOpenCampaignLabelPriority() {
365377
Bundle customPayload = new Bundle();
366378
customPayload.putString("xtor", xtor);
367379
TestEventPayload payload = new TestEventPayload(null,
380+
null,
368381
"https://batch.com/test?xtor=AD-[fake]#xtor=CS8-[fake2]",
369382
customPayload, true);
370383

@@ -394,6 +407,7 @@ public void testNotificationOpenCampaignLabelNonTrimmed() {
394407

395408
Bundle customPayload = new Bundle();
396409
TestEventPayload payload = new TestEventPayload(null,
410+
null,
397411
" \n https://batch.com/test?xtor=AD-[fake] \n ",
398412
customPayload, true);
399413

@@ -420,6 +434,7 @@ public void testNotificationOpen() {
420434
Mockito.when(screens.add("OpenedBatchPushNotification")).thenReturn(screen);
421435

422436
TestEventPayload payload = new TestEventPayload(null,
437+
null,
423438
null,
424439
new Bundle(), true);
425440

@@ -446,6 +461,7 @@ public void testNotificationDismiss() {
446461
Mockito.when(screens.add("DismissedBatchPushNotification")).thenReturn(screen);
447462

448463
TestEventPayload payload = new TestEventPayload(null,
464+
null,
449465
null,
450466
new Bundle(), true);
451467

@@ -468,6 +484,7 @@ public void testInAppShow() {
468484
Mockito.when(screens.add("ShowedBatchInAppMessage")).thenReturn(screen);
469485

470486
TestEventPayload payload = new TestEventPayload(null,
487+
null,
471488
null,
472489
new Bundle());
473490

@@ -495,6 +512,7 @@ public void testInAppShowCampaignId() {
495512
Mockito.when(screens.add("ShowedBatchInAppMessage")).thenReturn(screen);
496513

497514
TestEventPayload payload = new TestEventPayload(xtor,
515+
null,
498516
null,
499517
new Bundle());
500518

@@ -524,6 +542,7 @@ public void testInAppShowCampaignLabelFragmentUppercase() {
524542
Mockito.when(screens.add("ShowedBatchInAppMessage")).thenReturn(screen);
525543

526544
TestEventPayload payload = new TestEventPayload(null,
545+
null,
527546
"https://batch.com/test#XtOr=" + xtor,
528547
new Bundle());
529548

@@ -553,6 +572,7 @@ public void testInAppShowCampaignLabelQueryUppercase() {
553572
Mockito.when(screens.add("ShowedBatchInAppMessage")).thenReturn(screen);
554573

555574
TestEventPayload payload = new TestEventPayload(null,
575+
null,
556576
"https://batch.com/test?XTor=" + xtor,
557577
new Bundle());
558578

@@ -581,6 +601,7 @@ public void testInAppClickCampaignLabel() {
581601
Mockito.when(screens.add("ClickedBatchInAppMessage")).thenReturn(screen);
582602

583603
TestEventPayload payload = new TestEventPayload(xtor,
604+
null,
584605
null,
585606
new Bundle(), true);
586607

@@ -597,6 +618,42 @@ public void testInAppClickCampaignLabel() {
597618
Mockito.verify(screen).sendView();
598619
}
599620

621+
@Test
622+
public void testInAppWebViewClickCampaignLabel() {
623+
String xtor = "EPR-[mylabel]-totot-titi";
624+
String campaignExpected = "[mylabel]";
625+
String webViewButtonIdExpected = "jesuisunbouton";
626+
627+
Publisher publisher = PowerMockito.mock(Publisher.class);
628+
Mockito.when(publishers.add(campaignExpected)).thenReturn(publisher);
629+
630+
Screen screen = PowerMockito.mock(Screen.class);
631+
CustomVars customVars = PowerMockito.mock(CustomVars.class);
632+
Mockito.when(screens.add("WebViewClickedBatchInAppMessage")).thenReturn(screen);
633+
Mockito.when(screen.CustomVars()).thenReturn(customVars);
634+
635+
TestEventPayload payload = new TestEventPayload(xtor,
636+
webViewButtonIdExpected,
637+
null,
638+
new Bundle(), true);
639+
640+
atInternetDispatcher.dispatchEvent(Batch.EventDispatcher.Type.MESSAGING_WEBVIEW_CLICK, payload);
641+
642+
Mockito.verify(publishers).add(Mockito.eq(campaignExpected));
643+
Mockito.verify(publisher).setAdvertiserId(Mockito.eq("[batch]"));
644+
Mockito.verify(publisher).setFormat(Mockito.eq("[in-app]"));
645+
Mockito.verify(publisher).setVariant(Mockito.eq("[" + webViewButtonIdExpected + "]"));
646+
Mockito.verify(publisher).sendTouch();
647+
Mockito.verify(publisher, Mockito.never()).sendImpression();
648+
649+
Mockito.verify(screens).add(Mockito.eq("WebViewClickedBatchInAppMessage"));
650+
Mockito.verify(screen).Campaign(xtor);
651+
Mockito.verify(screen).sendView();
652+
653+
Mockito.verify(screen).CustomVars();
654+
Mockito.verify(customVars).add(1, webViewButtonIdExpected, CustomVar.CustomVarType.Screen);
655+
}
656+
600657
@Test
601658
public void testInAppClickNonPositive() {
602659

@@ -607,6 +664,7 @@ public void testInAppClickNonPositive() {
607664
Mockito.when(screens.add("ClickedBatchInAppMessage")).thenReturn(screen);
608665

609666
TestEventPayload payload = new TestEventPayload(null,
667+
null,
610668
null,
611669
new Bundle(), false);
612670

@@ -630,6 +688,7 @@ public void testInAppGlobalTap() {
630688
Mockito.when(screens.add("ClickedBatchInAppMessage")).thenReturn(screen);
631689

632690
TestEventPayload payload = new TestEventPayload(null,
691+
null,
633692
null,
634693
new Bundle(), true);
635694

@@ -656,6 +715,7 @@ public void testInAppClose() {
656715
Mockito.when(screens.add("ClosedBatchInAppMessage")).thenReturn(screen);
657716

658717
TestEventPayload payload = new TestEventPayload(null,
718+
null,
659719
null,
660720
new Bundle());
661721

@@ -668,6 +728,29 @@ public void testInAppClose() {
668728
Mockito.verify(screen).sendView();
669729
}
670730

731+
@Test
732+
public void testInAppCloseError() {
733+
734+
Publisher publisher = PowerMockito.mock(Publisher.class);
735+
Mockito.when(publishers.add("[batch-default-campaign]")).thenReturn(publisher);
736+
737+
Screen screen = PowerMockito.mock(Screen.class);
738+
Mockito.when(screens.add("ClosedErrorBatchInAppMessage")).thenReturn(screen);
739+
740+
TestEventPayload payload = new TestEventPayload(null,
741+
null,
742+
null,
743+
new Bundle());
744+
745+
atInternetDispatcher.dispatchEvent(Batch.EventDispatcher.Type.MESSAGING_CLOSE_ERROR, payload);
746+
Mockito.verify(publisher, Mockito.never()).sendImpression();
747+
Mockito.verify(publisher, Mockito.never()).sendTouch();
748+
749+
Mockito.verify(screens).add(Mockito.eq("ClosedErrorBatchInAppMessage"));
750+
Mockito.verify(screen, Mockito.never()).Campaign(Mockito.anyString());
751+
Mockito.verify(screen).sendView();
752+
}
753+
671754
@Test
672755
public void testInAppAutoClose() {
673756

@@ -678,6 +761,7 @@ public void testInAppAutoClose() {
678761
Mockito.when(screens.add("AutoClosedBatchInAppMessage")).thenReturn(screen);
679762

680763
TestEventPayload payload = new TestEventPayload(null,
764+
null,
681765
null,
682766
new Bundle());
683767

atinternet-dispatcher/src/test/java/com/batch/android/dispatcher/atinternet/TestEventPayload.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,33 @@ public class TestEventPayload implements Batch.EventDispatcher.Payload {
1313

1414
private String trackingId;
1515
private String deeplink;
16+
private String webViewAnalyticsID;
1617
private Bundle customPayload;
1718
private boolean isPositive;
1819

1920
TestEventPayload(String trackingId,
2021
String deeplink,
2122
Bundle customPayload)
2223
{
23-
this(trackingId, deeplink, customPayload, false);
24+
this(trackingId, null, deeplink, customPayload, false);
2425
}
2526

2627
TestEventPayload(String trackingId,
28+
String webViewAnalyticsID,
29+
String deeplink,
30+
Bundle customPayload)
31+
{
32+
this(trackingId, webViewAnalyticsID, deeplink, customPayload, false);
33+
}
34+
35+
TestEventPayload(String trackingId,
36+
String webViewAnalyticsID,
2737
String deeplink,
2838
Bundle customPayload,
2939
boolean isPositive)
3040
{
3141
this.trackingId = trackingId;
42+
this.webViewAnalyticsID = webViewAnalyticsID;
3243
this.deeplink = deeplink;
3344
this.customPayload = customPayload;
3445
this.isPositive = isPositive;
@@ -77,4 +88,9 @@ public BatchPushPayload getPushPayload()
7788
{
7889
return null;
7990
}
91+
92+
@Nullable
93+
public String getWebViewAnalyticsID() {
94+
return webViewAnalyticsID;
95+
}
8096
}

0 commit comments

Comments
 (0)