Skip to content

Commit 5473720

Browse files
authored
fix(pinpoint): add campaign attributes to push events (#2458)
1 parent 4d337c7 commit 5473720

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed

aws-android-sdk-pinpoint/src/main/java/com/amazonaws/mobileconnectors/pinpoint/targeting/notification/NotificationClientBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,10 @@ public NotificationClient.PushResult handleNotificationReceived(NotificationDeta
889889
}
890890

891891
final AnalyticsEvent pushEvent;
892+
this.pinpointContext.getAnalyticsClient().updateEventSourceGlobally(eventSourceAttributes);
892893
if (isAppInForeground) {
893894
pushEvent = this.pinpointContext.getAnalyticsClient().createEvent(eventSourceType.getEventTypeReceivedForeground());
894895
} else {
895-
this.pinpointContext.getAnalyticsClient().updateEventSourceGlobally(eventSourceAttributes);
896896
pushEvent = this.pinpointContext.getAnalyticsClient().createEvent(eventSourceType.getEventTypeReceivedBackground());
897897
}
898898
pushEvent.addAttribute("isAppInForeground", Boolean.toString(isAppInForeground));

aws-android-sdk-pinpoint/src/test/java/com/amazonaws/mobileconnectors/pinpoint/targeting/notification/ADMNotificationClientTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ public void testADMMessageReceivedInForegroundDefaultConfig() throws JSONExcepti
201201
for (Map.Entry<String, String> entry : receivedEvent.getAllAttributes().entrySet()) {
202202
System.out.println(entry.getKey() + ":" + entry.getValue());
203203
}
204-
assertThat(receivedEvent.getAllAttributes().size(), is(1));
204+
assertThat(receivedEvent.getAllAttributes().size(), is(4));
205205
assertThat(receivedEvent.getAttribute("isAppInForeground"), is("true"));
206-
assertNull(receivedEvent.getAttribute("campaign_id"));
207-
assertNull(receivedEvent.getAttribute("treatment_id"));
208-
assertNull(receivedEvent.getAttribute("campaign_activity_id"));
206+
assertThat(receivedEvent.getAttribute("campaign_id"), is("Customers rule"));
207+
assertThat(receivedEvent.getAttribute("treatment_id"), is("Treat Me well please"));
208+
assertThat(receivedEvent.getAttribute("campaign_activity_id"), is("the brink of dawn"));
209209
// optOut is true because this test can't get the app icon resource id.
210210
assertThat(receivedEvent.getAllMetrics().size(), is(0));
211211

@@ -241,9 +241,12 @@ public void testADMMessageReceivedInForegroundWithConfigShouldPostNotificationsI
241241
for (Map.Entry<String, String> entry : receivedEvent.getAllAttributes().entrySet()) {
242242
System.out.println(entry.getKey() + ":" + entry.getValue());
243243
}
244-
assertThat(receivedEvent.getAllAttributes().size(), is(2));
244+
assertThat(receivedEvent.getAllAttributes().size(), is(5));
245245
assertThat(receivedEvent.getAttribute("isOptedOut"), is("true"));
246246
assertThat(receivedEvent.getAttribute("isAppInForeground"), is("true"));
247+
assertThat(receivedEvent.getAttribute("campaign_id"), is("Customers rule"));
248+
assertThat(receivedEvent.getAttribute("treatment_id"), is("Treat Me well please"));
249+
assertThat(receivedEvent.getAttribute("campaign_activity_id"), is("the brink of dawn"));
247250
// optOut is true because this test can't get the app icon resource id.
248251
assertThat(receivedEvent.getAllMetrics().size(), is(0));
249252

aws-android-sdk-pinpoint/src/test/java/com/amazonaws/mobileconnectors/pinpoint/targeting/notification/BaiduNotificationClientTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ public void testBaiduMessageReceivedInForegroundDefaultConfig() throws JSONExcep
201201
for (Map.Entry<String, String> entry : receivedEvent.getAllAttributes().entrySet()) {
202202
System.out.println(entry.getKey() + ":" + entry.getValue());
203203
}
204-
assertThat(receivedEvent.getAllAttributes().size(), is(1));
204+
assertThat(receivedEvent.getAllAttributes().size(), is(4));
205205
assertThat(receivedEvent.getAttribute("isAppInForeground"), is("true"));
206-
assertNull(receivedEvent.getAttribute("campaign_id"));
207-
assertNull(receivedEvent.getAttribute("treatment_id"));
208-
assertNull(receivedEvent.getAttribute("campaign_activity_id"));
206+
assertThat(receivedEvent.getAttribute("campaign_id"), is("Customers rule"));
207+
assertThat(receivedEvent.getAttribute("treatment_id"), is("Treat Me well please"));
208+
assertThat(receivedEvent.getAttribute("campaign_activity_id"), is("the brink of dawn"));
209209
// optOut is true because this test can't get the app icon resource id.
210210
assertThat(receivedEvent.getAllMetrics().size(), is(0));
211211

@@ -241,9 +241,12 @@ public void testBaiduMessageReceivedInForegroundWithConfigShouldPostNotification
241241
for (Map.Entry<String, String> entry : receivedEvent.getAllAttributes().entrySet()) {
242242
System.out.println(entry.getKey() + ":" + entry.getValue());
243243
}
244-
assertThat(receivedEvent.getAllAttributes().size(), is(2));
244+
assertThat(receivedEvent.getAllAttributes().size(), is(5));
245245
assertThat(receivedEvent.getAttribute("isOptedOut"), is("true"));
246246
assertThat(receivedEvent.getAttribute("isAppInForeground"), is("true"));
247+
assertThat(receivedEvent.getAttribute("campaign_id"), is("Customers rule"));
248+
assertThat(receivedEvent.getAttribute("treatment_id"), is("Treat Me well please"));
249+
assertThat(receivedEvent.getAttribute("campaign_activity_id"), is("the brink of dawn"));
247250
// optOut is true because this test can't get the app icon resource id.
248251
assertThat(receivedEvent.getAllMetrics().size(), is(0));
249252

aws-android-sdk-pinpoint/src/test/java/com/amazonaws/mobileconnectors/pinpoint/targeting/notification/FCMNotificationClientTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ public void testFCMMessageReceivedInForegroundDefaultConfig() throws JSONExcepti
195195
for (Map.Entry<String, String> entry : receivedEvent.getAllAttributes().entrySet()) {
196196
System.out.println(entry.getKey() + ":" + entry.getValue());
197197
}
198-
assertThat(receivedEvent.getAllAttributes().size(), is(1));
198+
assertThat(receivedEvent.getAllAttributes().size(), is(4));
199199
assertThat(receivedEvent.getAttribute("isAppInForeground"), is("true"));
200-
assertNull(receivedEvent.getAttribute("campaign_id"));
201-
assertNull(receivedEvent.getAttribute("treatment_id"));
202-
assertNull(receivedEvent.getAttribute("campaign_activity_id"));
200+
assertThat(receivedEvent.getAttribute("campaign_id"), is("Customers rule"));
201+
assertThat(receivedEvent.getAttribute("treatment_id"), is("Treat Me well please"));
202+
assertThat(receivedEvent.getAttribute("campaign_activity_id"), is("the brink of dawn"));
203203
// optOut is true because this test can't get the app icon resource id.
204204
assertThat(receivedEvent.getAllMetrics().size(), is(0));
205205

@@ -235,9 +235,12 @@ public void testFCMMessageReceivedInForegroundWithConfigShouldPostNotificationsI
235235
for (Map.Entry<String, String> entry : receivedEvent.getAllAttributes().entrySet()) {
236236
System.out.println(entry.getKey() + ":" + entry.getValue());
237237
}
238-
assertThat(receivedEvent.getAllAttributes().size(), is(2));
238+
assertThat(receivedEvent.getAllAttributes().size(), is(5));
239239
assertThat(receivedEvent.getAttribute("isOptedOut"), is("true"));
240240
assertThat(receivedEvent.getAttribute("isAppInForeground"), is("true"));
241+
assertThat(receivedEvent.getAttribute("campaign_id"), is("Customers rule"));
242+
assertThat(receivedEvent.getAttribute("treatment_id"), is("Treat Me well please"));
243+
assertThat(receivedEvent.getAttribute("campaign_activity_id"), is("the brink of dawn"));
241244
// optOut is true because this test can't get the app icon resource id.
242245
assertThat(receivedEvent.getAllMetrics().size(), is(0));
243246

aws-android-sdk-pinpoint/src/test/java/com/amazonaws/mobileconnectors/pinpoint/targeting/notification/GCMNotificationClientTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ public void testGCMMessageReceivedInForegroundDefaultConfig() throws JSONExcepti
243243
for (Map.Entry<String, String> entry : receivedEvent.getAllAttributes().entrySet()) {
244244
System.out.println(entry.getKey() + ":" + entry.getValue());
245245
}
246-
assertThat(receivedEvent.getAllAttributes().size(), is(1));
246+
assertThat(receivedEvent.getAllAttributes().size(), is(4));
247247
assertThat(receivedEvent.getAttribute("isAppInForeground"), is("true"));
248-
assertNull(receivedEvent.getAttribute("campaign_id"));
249-
assertNull(receivedEvent.getAttribute("treatment_id"));
250-
assertNull(receivedEvent.getAttribute("campaign_activity_id"));
248+
assertThat(receivedEvent.getAttribute("campaign_id"), is("Customers rule"));
249+
assertThat(receivedEvent.getAttribute("treatment_id"), is("Treat Me well please"));
250+
assertThat(receivedEvent.getAttribute("campaign_activity_id"), is("the brink of dawn"));
251251
// optOut is true because this test can't get the app icon resource id.
252252
assertThat(receivedEvent.getAllMetrics().size(), is(0));
253253

@@ -283,9 +283,12 @@ public void testGCMMessageReceivedInForegroundWithConfigShouldPostNotificationsI
283283
for (Map.Entry<String, String> entry : receivedEvent.getAllAttributes().entrySet()) {
284284
System.out.println(entry.getKey() + ":" + entry.getValue());
285285
}
286-
assertThat(receivedEvent.getAllAttributes().size(), is(2));
286+
assertThat(receivedEvent.getAllAttributes().size(), is(5));
287287
assertThat(receivedEvent.getAttribute("isOptedOut"), is("true"));
288288
assertThat(receivedEvent.getAttribute("isAppInForeground"), is("true"));
289+
assertThat(receivedEvent.getAttribute("campaign_id"), is("Customers rule"));
290+
assertThat(receivedEvent.getAttribute("treatment_id"), is("Treat Me well please"));
291+
assertThat(receivedEvent.getAttribute("campaign_activity_id"), is("the brink of dawn"));
289292
// optOut is true because this test can't get the app icon resource id.
290293
assertThat(receivedEvent.getAllMetrics().size(), is(0));
291294

0 commit comments

Comments
 (0)