Skip to content

Commit 40f5042

Browse files
committed
Fix DIRECT IAM influence being cache
* IAM Direct influence shoudn't be cache because DIRECT Influence will be only while the IAM is being display * Instead of caching DIRECT cache INDIRECT
1 parent 057cdd9 commit 40f5042

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/influence/OSInAppMessageTracker.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ void addSessionData(@NonNull JSONObject jsonObject, OSInfluence influence) {
9595

9696
@Override
9797
public void cacheState() {
98-
dataRepository.cacheIAMInfluenceType(influenceType == null ? OSInfluenceType.UNATTRIBUTED : influenceType);
98+
// We only need to cache INDIRECT and UNATTRIBUTED influence types
99+
// DIRECT is downgrade to INDIRECT to avoid inconsistency state
100+
// where the app might be close before dismissing current displayed IAM
101+
OSInfluenceType influenceTypeToCache = influenceType == null ? OSInfluenceType.UNATTRIBUTED : influenceType;
102+
dataRepository.cacheIAMInfluenceType(influenceTypeToCache == OSInfluenceType.DIRECT ? OSInfluenceType.INDIRECT : influenceTypeToCache);
99103
}
100104
}

OneSignalSDK/unittest/src/test/java/com/test/onesignal/OutcomeEventV2UnitTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.onesignal.StaticResetHelper;
4444
import com.onesignal.influence.OSTrackerFactory;
4545
import com.onesignal.influence.model.OSInfluence;
46+
import com.onesignal.influence.model.OSInfluenceType;
4647
import com.onesignal.outcomes.OSOutcomeEventsFactory;
4748
import com.onesignal.outcomes.domain.OSOutcomeEventsRepository;
4849
import com.onesignal.outcomes.model.OSOutcomeEventParams;
@@ -342,6 +343,31 @@ public void testDirectOutcomeWithValueSuccess() throws Exception {
342343
assertEquals("{\"id\":\"testing\",\"sources\":{\"direct\":{\"notification_ids\":[\"notification_id\"],\"in_app_message_ids\":[\"iam_id\"]}},\"weight\":1.1,\"device_type\":1}", service.getLastJsonObjectSent());
343344
}
344345

346+
@Test
347+
public void testDirectOutcomeSaveIndirectSuccess() throws Exception {
348+
service.setSuccess(true);
349+
sessionManager.initSessionFromCache();
350+
sessionManager.onNotificationReceived(NOTIFICATION_ID);
351+
sessionManager.onInAppMessageReceived(IAM_ID);
352+
// Set DIRECT notification id influence
353+
sessionManager.onDirectInfluenceFromNotificationOpen(NOTIFICATION_ID);
354+
sessionManager.onDirectInfluenceFromIAMClick(IAM_ID);
355+
356+
controller.sendOutcomeEventWithValue(OUTCOME_NAME, 1.1f);
357+
threadAndTaskWait();
358+
359+
handler.setOutcomes(repository.getSavedOutcomeEvents());
360+
361+
threadAndTaskWait();
362+
assertEquals(0, outcomeEvents.size());
363+
assertEquals("{\"id\":\"testing\",\"sources\":{\"direct\":{\"notification_ids\":[\"notification_id\"],\"in_app_message_ids\":[\"iam_id\"]}},\"weight\":1.1,\"device_type\":1}", service.getLastJsonObjectSent());
364+
365+
sessionManager.initSessionFromCache();
366+
assertEquals(OSInfluenceType.INDIRECT, trackerFactory.getIAMChannelTracker().getInfluenceType());
367+
assertEquals(1, trackerFactory.getIAMChannelTracker().getIndirectIds().length());
368+
assertEquals(IAM_ID, trackerFactory.getIAMChannelTracker().getIndirectIds().get(0));
369+
}
370+
345371
@Test
346372
public void testIndirectOutcomeWithValueSuccess() throws Exception {
347373
service.setSuccess(true);

0 commit comments

Comments
 (0)