use of com.onesignal.outcomes.domain.OSOutcomeSource in project OneSignal-Android-SDK by OneSignal.
the class OSOutcomeEvent method fromOutcomeEventParamsV2toOutcomeEventV1.
/**
* Creates an OutcomeEvent from an OSOutcomeEventParams in order to work on V1 from V2
*/
public static OSOutcomeEvent fromOutcomeEventParamsV2toOutcomeEventV1(OSOutcomeEventParams outcomeEventParams) {
OSInfluenceType influenceType = OSInfluenceType.UNATTRIBUTED;
JSONArray notificationId = null;
if (outcomeEventParams.getOutcomeSource() != null) {
OSOutcomeSource source = outcomeEventParams.getOutcomeSource();
if (source.getDirectBody() != null && source.getDirectBody().getNotificationIds() != null && source.getDirectBody().getNotificationIds().length() > 0) {
influenceType = OSInfluenceType.DIRECT;
notificationId = source.getDirectBody().getNotificationIds();
} else if (source.getIndirectBody() != null && source.getIndirectBody().getNotificationIds() != null && source.getIndirectBody().getNotificationIds().length() > 0) {
influenceType = OSInfluenceType.INDIRECT;
notificationId = source.getIndirectBody().getNotificationIds();
}
}
return new OSOutcomeEvent(influenceType, notificationId, outcomeEventParams.getOutcomeId(), outcomeEventParams.getTimestamp(), outcomeEventParams.getWeight());
}
use of com.onesignal.outcomes.domain.OSOutcomeSource 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);
}
Aggregations