use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.
the class SessionManagerUnitTests method testDirectIAMInitInfluence.
@Test
public void testDirectIAMInitInfluence() 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);
iamTracker = trackerFactory.getIAMChannelTracker();
OSInfluence influence = iamTracker.getCurrentSessionInfluence();
assertEquals(OSInfluenceType.DIRECT, iamTracker.getInfluenceType());
assertEquals(IAM_ID, iamTracker.getLastReceivedIds().get(0));
assertEquals(OSInfluenceChannel.IAM, influence.getInfluenceChannel());
assertEquals(OSInfluenceType.DIRECT, influence.getInfluenceType());
assertEquals(1, influence.getIds().length());
assertEquals(IAM_ID, influence.getIds().get(0));
}
use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.
the class OSOutcomeEventsController method sendUniqueOutcomeEvent.
/**
* An unique outcome is considered unattributed when all channels are unattributed
* If one channel is attributed is enough reason to cache attribution
*/
private void sendUniqueOutcomeEvent(@NonNull final String name, @NonNull List<OSInfluence> sessionInfluences, @Nullable OneSignal.OutcomeCallback callback) {
List<OSInfluence> influences = removeDisabledInfluences(sessionInfluences);
if (influences.isEmpty()) {
OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "Unique Outcome disabled for current session");
return;
}
boolean attributed = false;
for (OSInfluence influence : influences) {
if (influence.getInfluenceType().isAttributed()) {
// At least one channel attributed this outcome
attributed = true;
break;
}
}
// Special handling for unique outcomes in the attributed and unattributed scenarios
if (attributed) {
// Make sure unique Ids exist before trying to make measure request
final List<OSInfluence> uniqueInfluences = getUniqueIds(name, influences);
if (uniqueInfluences == null) {
OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "Measure endpoint will not send because unique outcome already sent for: " + "\nSessionInfluences: " + influences.toString() + "\nOutcome name: " + name);
// Return null within the callback to determine not a failure, but not a success in terms of the request made
if (callback != null)
callback.onSuccess(null);
return;
}
sendAndCreateOutcomeEvent(name, 0, uniqueInfluences, callback);
} else {
// Make sure unique outcome has not been sent for current unattributed session
if (unattributedUniqueOutcomeEventsSentOnSession.contains(name)) {
OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "Measure endpoint will not send because unique outcome already sent for: " + "\nSession: " + OSInfluenceType.UNATTRIBUTED + "\nOutcome name: " + name);
// Return null within the callback to determine not a failure, but not a success in terms of the request made
if (callback != null)
callback.onSuccess(null);
return;
}
unattributedUniqueOutcomeEventsSentOnSession.add(name);
sendAndCreateOutcomeEvent(name, 0, influences, callback);
}
}
use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.
the class OSOutcomeEventsController method removeDisabledInfluences.
private List<OSInfluence> removeDisabledInfluences(List<OSInfluence> influences) {
List<OSInfluence> availableInfluences = new ArrayList<>(influences);
for (OSInfluence influence : influences) {
if (influence.getInfluenceType().isDisabled()) {
OneSignal.onesignalLog(OneSignal.LOG_LEVEL.DEBUG, "Outcomes disabled for channel: " + influence.getInfluenceChannel().toString());
availableInfluences.remove(influence);
}
}
return availableInfluences;
}
use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.
the class OSOutcomeEventsController method sendAndCreateOutcomeEvent.
private void sendAndCreateOutcomeEvent(@NonNull final String name, @NonNull final float weight, @NonNull List<OSInfluence> influences, @Nullable final OneSignal.OutcomeCallback callback) {
final long timestampSeconds = OneSignal.getTime().getCurrentTimeMillis() / 1000;
final int deviceType = new OSUtils().getDeviceType();
final String appId = OneSignal.appId;
OSOutcomeSourceBody directSourceBody = null;
OSOutcomeSourceBody indirectSourceBody = null;
boolean unattributed = false;
for (OSInfluence influence : influences) {
switch(influence.getInfluenceType()) {
case DIRECT:
directSourceBody = setSourceChannelIds(influence, directSourceBody == null ? new OSOutcomeSourceBody() : directSourceBody);
break;
case INDIRECT:
indirectSourceBody = setSourceChannelIds(influence, indirectSourceBody == null ? new OSOutcomeSourceBody() : indirectSourceBody);
break;
case UNATTRIBUTED:
unattributed = true;
break;
case DISABLED:
OneSignal.Log(OneSignal.LOG_LEVEL.VERBOSE, "Outcomes disabled for channel: " + influence.getInfluenceChannel());
if (callback != null)
callback.onSuccess(null);
// finish method
return;
}
}
if (directSourceBody == null && indirectSourceBody == null && !unattributed) {
// Disabled for all channels
OneSignal.Log(OneSignal.LOG_LEVEL.VERBOSE, "Outcomes disabled for all channels");
if (callback != null)
callback.onSuccess(null);
return;
}
OSOutcomeSource source = new OSOutcomeSource(directSourceBody, indirectSourceBody);
final OSOutcomeEventParams eventParams = new OSOutcomeEventParams(name, source, weight, 0);
OneSignalApiResponseHandler responseHandler = new OneSignalApiResponseHandler() {
@Override
public void onSuccess(String response) {
saveUniqueOutcome(eventParams);
// The only case where an actual success has occurred and the OutcomeEvent should be sent back
if (callback != null)
callback.onSuccess(OSOutcomeEvent.fromOutcomeEventParamsV2toOutcomeEventV1(eventParams));
}
@Override
public void onFailure(int statusCode, String response, Throwable throwable) {
new Thread(new Runnable() {
@Override
public void run() {
Thread.currentThread().setPriority(Process.THREAD_PRIORITY_BACKGROUND);
// Only if we need to save and retry the outcome, then we will save the timestamp for future sending
eventParams.setTimestamp(timestampSeconds);
outcomeEventsFactory.getRepository().saveOutcomeEvent(eventParams);
}
}, OS_SAVE_OUTCOMES).start();
OneSignal.onesignalLog(OneSignal.LOG_LEVEL.WARN, "Sending outcome with name: " + name + " failed with status code: " + statusCode + " and response: " + response + "\nOutcome event was cached and will be reattempted on app cold start");
// Return null within the callback to determine not a failure, but not a success in terms of the request made
if (callback != null)
callback.onSuccess(null);
}
};
outcomeEventsFactory.getRepository().requestMeasureOutcomeEvent(appId, deviceType, eventParams, responseHandler);
}
use of com.onesignal.influence.domain.OSInfluence in project OneSignal-Android-SDK by OneSignal.
the class OutcomeEventIntegrationTests method assertNotificationChannelIndirectInfluence.
private void assertNotificationChannelIndirectInfluence(int indirectIdsLength) {
OSInfluence influence = trackerFactory.getNotificationChannelTracker().getCurrentSessionInfluence();
assertTrue(influence.getInfluenceType().isIndirect());
assertEquals(indirectIdsLength, influence.getIds().length());
}
Aggregations