Search in sources :

Example 1 with OSChannelTracker

use of com.onesignal.influence.data.OSChannelTracker in project OneSignal-Android-SDK by OneSignal.

the class OSSessionManager method restartSessionIfNeeded.

void restartSessionIfNeeded(OneSignal.AppEntryAction entryAction) {
    List<OSChannelTracker> channelTrackers = trackerFactory.getChannelsToResetByEntryAction(entryAction);
    List<OSInfluence> updatedInfluences = new ArrayList<>();
    logger.debug("OneSignal SessionManager restartSessionIfNeeded with entryAction: " + entryAction + "\n channelTrackers: " + channelTrackers.toString());
    for (OSChannelTracker channelTracker : channelTrackers) {
        JSONArray lastIds = channelTracker.getLastReceivedIds();
        logger.debug("OneSignal SessionManager restartSessionIfNeeded lastIds: " + lastIds);
        OSInfluence influence = channelTracker.getCurrentSessionInfluence();
        boolean updated;
        if (lastIds.length() > 0)
            updated = setSession(channelTracker, OSInfluenceType.INDIRECT, null, lastIds);
        else
            updated = setSession(channelTracker, OSInfluenceType.UNATTRIBUTED, null, null);
        if (updated)
            updatedInfluences.add(influence);
    }
    sendSessionEndingWithInfluences(updatedInfluences);
}
Also used : OSChannelTracker(com.onesignal.influence.data.OSChannelTracker) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) OSInfluence(com.onesignal.influence.domain.OSInfluence)

Example 2 with OSChannelTracker

use of com.onesignal.influence.data.OSChannelTracker in project OneSignal-Android-SDK by OneSignal.

the class OSSessionManager method onDirectInfluenceFromIAMClickFinished.

void onDirectInfluenceFromIAMClickFinished() {
    logger.debug("OneSignal SessionManager onDirectInfluenceFromIAMClickFinished");
    OSChannelTracker inAppMessageTracker = trackerFactory.getIAMChannelTracker();
    inAppMessageTracker.resetAndInitInfluence();
}
Also used : OSChannelTracker(com.onesignal.influence.data.OSChannelTracker)

Example 3 with OSChannelTracker

use of com.onesignal.influence.data.OSChannelTracker in project OneSignal-Android-SDK by OneSignal.

the class OSSessionManager method onNotificationReceived.

void onNotificationReceived(@Nullable String notificationId) {
    logger.debug("OneSignal SessionManager onNotificationReceived notificationId: " + notificationId);
    if (notificationId == null || notificationId.isEmpty())
        return;
    OSChannelTracker notificationTracker = trackerFactory.getNotificationChannelTracker();
    notificationTracker.saveLastId(notificationId);
}
Also used : OSChannelTracker(com.onesignal.influence.data.OSChannelTracker)

Example 4 with OSChannelTracker

use of com.onesignal.influence.data.OSChannelTracker in project OneSignal-Android-SDK by OneSignal.

the class OSSessionManager method attemptSessionUpgrade.

private void attemptSessionUpgrade(OneSignal.AppEntryAction entryAction, @Nullable String directId) {
    logger.debug("OneSignal SessionManager attemptSessionUpgrade with entryAction: " + entryAction);
    OSChannelTracker channelTrackerByAction = trackerFactory.getChannelByEntryAction(entryAction);
    List<OSChannelTracker> channelTrackersToReset = trackerFactory.getChannelsToResetByEntryAction(entryAction);
    List<OSInfluence> influencesToEnd = new ArrayList<>();
    OSInfluence lastInfluence = null;
    // We will try to override any session with DIRECT
    boolean updated = false;
    if (channelTrackerByAction != null) {
        lastInfluence = channelTrackerByAction.getCurrentSessionInfluence();
        updated = setSession(channelTrackerByAction, OSInfluenceType.DIRECT, directId == null ? channelTrackerByAction.getDirectId() : directId, null);
    }
    if (updated) {
        logger.debug("OneSignal SessionManager attemptSessionUpgrade channel updated, search for ending direct influences on channels: " + channelTrackersToReset);
        influencesToEnd.add(lastInfluence);
        // In that way we finish the session duration time for the last influenced session
        for (OSChannelTracker tracker : channelTrackersToReset) {
            if (tracker.getInfluenceType().isDirect()) {
                influencesToEnd.add(tracker.getCurrentSessionInfluence());
                tracker.resetAndInitInfluence();
            }
        }
    }
    logger.debug("OneSignal SessionManager attemptSessionUpgrade try UNATTRIBUTED to INDIRECT upgrade");
    // We will try to override the UNATTRIBUTED session with INDIRECT
    for (OSChannelTracker channelTracker : channelTrackersToReset) {
        if (channelTracker.getInfluenceType().isUnattributed()) {
            JSONArray lastIds = channelTracker.getLastReceivedIds();
            // There are new ids for attribution and the application was open again without resetting session
            if (lastIds.length() > 0 && !entryAction.isAppClose()) {
                // Save influence to ended it later if needed
                // This influence will be unattributed
                OSInfluence influence = channelTracker.getCurrentSessionInfluence();
                updated = setSession(channelTracker, OSInfluenceType.INDIRECT, null, lastIds);
                // Changed from UNATTRIBUTED to INDIRECT
                if (updated)
                    influencesToEnd.add(influence);
            }
        }
    }
    OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "Trackers after update attempt: " + trackerFactory.getChannels().toString());
    sendSessionEndingWithInfluences(influencesToEnd);
}
Also used : OSChannelTracker(com.onesignal.influence.data.OSChannelTracker) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) OSInfluence(com.onesignal.influence.domain.OSInfluence)

Example 5 with OSChannelTracker

use of com.onesignal.influence.data.OSChannelTracker in project OneSignal-Android-SDK by OneSignal.

the class SessionManagerUnitTests method testDirectIAMResetInfluence.

@Test
public void testDirectIAMResetInfluence() throws JSONException {
    trackerFactory.saveInfluenceParams(new OneSignalPackagePrivateHelper.RemoteOutcomeParams());
    sessionManager.initSessionFromCache();
    OSChannelTracker iamTracker = trackerFactory.getIAMChannelTracker();
    assertEquals(0, iamTracker.getLastReceivedIds().length());
    sessionManager.onInAppMessageReceived(IAM_ID);
    sessionManager.onDirectInfluenceFromIAMClick(IAM_ID);
    sessionManager.onDirectInfluenceFromIAMClickFinished();
    iamTracker = trackerFactory.getIAMChannelTracker();
    OSInfluence influence = iamTracker.getCurrentSessionInfluence();
    assertEquals(OSInfluenceType.INDIRECT, iamTracker.getInfluenceType());
    assertEquals(IAM_ID, iamTracker.getLastReceivedIds().get(0));
    assertEquals(OSInfluenceChannel.IAM, influence.getInfluenceChannel());
    assertEquals(OSInfluenceType.INDIRECT, influence.getInfluenceType());
    assertEquals(1, influence.getIds().length());
    assertEquals(IAM_ID, influence.getIds().get(0));
}
Also used : OSChannelTracker(com.onesignal.influence.data.OSChannelTracker) OSInfluence(com.onesignal.influence.domain.OSInfluence) OneSignalPackagePrivateHelper(com.onesignal.OneSignalPackagePrivateHelper) Test(org.junit.Test)

Aggregations

OSChannelTracker (com.onesignal.influence.data.OSChannelTracker)11 OSInfluence (com.onesignal.influence.domain.OSInfluence)7 OneSignalPackagePrivateHelper (com.onesignal.OneSignalPackagePrivateHelper)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 JSONArray (org.json.JSONArray)2