Search in sources :

Example 1 with OSInfluence

use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.

the class OSFocusTimeProcessorFactory method getTimeProcessorSaved.

FocusTimeController.FocusTimeProcessorBase getTimeProcessorSaved() {
    FocusTimeController.FocusTimeProcessorBase attributedProcessor = getAttributedProcessor();
    List<OSInfluence> influences = attributedProcessor.getInfluences();
    for (OSInfluence influence : influences) {
        // Is true is at least one channel attributed the session
        if (influence.getInfluenceType().isAttributed())
            return attributedProcessor;
    }
    return getUnattributedProcessor();
}
Also used : OSInfluence(com.onesignal.influence.domain.OSInfluence)

Example 2 with OSInfluence

use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.

the class OSFocusTimeProcessorFactory method getTimeProcessorWithInfluences.

FocusTimeController.FocusTimeProcessorBase getTimeProcessorWithInfluences(List<OSInfluence> influences) {
    boolean isAttributed = false;
    for (OSInfluence influence : influences) {
        // Is true is at least one channel attributed the session
        if (influence.getInfluenceType().isAttributed()) {
            isAttributed = true;
            break;
        }
    }
    FocusTimeController.FocusTimeProcessorBase focusTimeProcessorBase;
    if (isAttributed)
        focusTimeProcessorBase = getAttributedProcessor();
    else
        focusTimeProcessorBase = getUnattributedProcessor();
    return focusTimeProcessorBase;
}
Also used : OSInfluence(com.onesignal.influence.domain.OSInfluence)

Example 3 with OSInfluence

use of com.onesignal.influence.domain.OSInfluence 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 4 with OSInfluence

use of com.onesignal.influence.domain.OSInfluence 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 OSInfluence

use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.

the class OutcomeEventIntegrationTests method assertIAMChannelUnattributedInfluence.

private void assertIAMChannelUnattributedInfluence() {
    OSInfluence influence = trackerFactory.getIAMChannelTracker().getCurrentSessionInfluence();
    assertTrue(influence.getInfluenceType().isUnattributed());
    assertNull(influence.getIds());
}
Also used : OSInfluence(com.onesignal.influence.domain.OSInfluence)

Aggregations

OSInfluence (com.onesignal.influence.domain.OSInfluence)40 Test (org.junit.Test)25 OneSignalPackagePrivateHelper (com.onesignal.OneSignalPackagePrivateHelper)23 OSChannelTracker (com.onesignal.influence.data.OSChannelTracker)7 JSONArray (org.json.JSONArray)5 ArrayList (java.util.ArrayList)3 Config (org.robolectric.annotation.Config)2 Bundle (android.os.Bundle)1 FCMBroadcastReceiver_onReceived_withBundle (com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withBundle)1 OSOutcomeEventParams (com.onesignal.outcomes.domain.OSOutcomeEventParams)1 OSOutcomeSource (com.onesignal.outcomes.domain.OSOutcomeSource)1 OSOutcomeSourceBody (com.onesignal.outcomes.domain.OSOutcomeSourceBody)1 GenerateNotificationRunner.getBaseNotifBundle (com.test.onesignal.GenerateNotificationRunner.getBaseNotifBundle)1