Search in sources :

Example 1 with Visitor

use of com.optimizely.ab.event.internal.payload.Visitor in project java-sdk by optimizely.

the class EventBuilder method createImpressionEvent.

public LogEvent createImpressionEvent(@Nonnull ProjectConfig projectConfig, @Nonnull Experiment activatedExperiment, @Nonnull Variation variation, @Nonnull String userId, @Nonnull Map<String, String> attributes) {
    Decision decision = new Decision(activatedExperiment.getLayerId(), activatedExperiment.getId(), variation.getId(), false);
    Event impressionEvent = new Event(System.currentTimeMillis(), UUID.randomUUID().toString(), activatedExperiment.getLayerId(), ACTIVATE_EVENT_KEY, null, null, null, ACTIVATE_EVENT_KEY, null);
    Snapshot snapshot = new Snapshot(Arrays.asList(decision), Arrays.asList(impressionEvent));
    Visitor visitor = new Visitor(userId, null, buildAttributeList(projectConfig, attributes), Arrays.asList(snapshot));
    List<Visitor> visitors = Arrays.asList(visitor);
    EventBatch eventBatch = new EventBatch(clientEngine.getClientEngineValue(), clientVersion, projectConfig.getAccountId(), visitors, projectConfig.getAnonymizeIP(), projectConfig.getProjectId(), projectConfig.getRevision());
    String payload = this.serializer.serialize(eventBatch);
    return new LogEvent(LogEvent.RequestMethod.POST, EVENT_ENDPOINT, Collections.<String, String>emptyMap(), payload);
}
Also used : Snapshot(com.optimizely.ab.event.internal.payload.Snapshot) Visitor(com.optimizely.ab.event.internal.payload.Visitor) LogEvent(com.optimizely.ab.event.LogEvent) Event(com.optimizely.ab.event.internal.payload.Event) LogEvent(com.optimizely.ab.event.LogEvent) EventBatch(com.optimizely.ab.event.internal.payload.EventBatch) Decision(com.optimizely.ab.event.internal.payload.Decision)

Example 2 with Visitor

use of com.optimizely.ab.event.internal.payload.Visitor in project java-sdk by optimizely.

the class SerializerTestUtils method generateImpression.

static EventBatch generateImpression() {
    Snapshot snapshot = new Snapshot(Arrays.asList(decision), events);
    Visitor vistor = new Visitor(visitorId, null, userFeatures, Arrays.asList(snapshot));
    EventBatch impression = new EventBatch(accountId, Arrays.asList(vistor), false, projectId, revision);
    impression.setProjectId(projectId);
    impression.setAccountId(accountId);
    impression.setClientVersion("0.1.1");
    impression.setAnonymizeIp(true);
    impression.setRevision(revision);
    return impression;
}
Also used : Snapshot(com.optimizely.ab.event.internal.payload.Snapshot) Visitor(com.optimizely.ab.event.internal.payload.Visitor) EventBatch(com.optimizely.ab.event.internal.payload.EventBatch)

Example 3 with Visitor

use of com.optimizely.ab.event.internal.payload.Visitor in project java-sdk by optimizely.

the class EventBuilder method createConversionEvent.

public LogEvent createConversionEvent(@Nonnull ProjectConfig projectConfig, @Nonnull Map<Experiment, Variation> experimentVariationMap, @Nonnull String userId, @Nonnull String eventId, @Nonnull String eventName, @Nonnull Map<String, String> attributes, @Nonnull Map<String, ?> eventTags) {
    if (experimentVariationMap.isEmpty()) {
        return null;
    }
    ArrayList<Decision> decisions = new ArrayList<Decision>();
    for (Map.Entry<Experiment, Variation> entry : experimentVariationMap.entrySet()) {
        Decision decision = new Decision(entry.getKey().getLayerId(), entry.getKey().getId(), entry.getValue().getId(), false);
        decisions.add(decision);
    }
    EventType eventType = projectConfig.getEventNameMapping().get(eventName);
    Event conversionEvent = new Event(System.currentTimeMillis(), UUID.randomUUID().toString(), eventType.getId(), eventType.getKey(), null, EventTagUtils.getRevenueValue(eventTags), eventTags, eventType.getKey(), EventTagUtils.getNumericValue(eventTags));
    Snapshot snapshot = new Snapshot(decisions, Arrays.asList(conversionEvent));
    Visitor visitor = new Visitor(userId, null, buildAttributeList(projectConfig, attributes), Arrays.asList(snapshot));
    List<Visitor> visitors = Arrays.asList(visitor);
    EventBatch eventBatch = new EventBatch(clientEngine.getClientEngineValue(), clientVersion, projectConfig.getAccountId(), visitors, projectConfig.getAnonymizeIP(), projectConfig.getProjectId(), projectConfig.getRevision());
    String payload = this.serializer.serialize(eventBatch);
    return new LogEvent(LogEvent.RequestMethod.POST, EVENT_ENDPOINT, Collections.<String, String>emptyMap(), payload);
}
Also used : Visitor(com.optimizely.ab.event.internal.payload.Visitor) EventType(com.optimizely.ab.config.EventType) LogEvent(com.optimizely.ab.event.LogEvent) Experiment(com.optimizely.ab.config.Experiment) ArrayList(java.util.ArrayList) Decision(com.optimizely.ab.event.internal.payload.Decision) Snapshot(com.optimizely.ab.event.internal.payload.Snapshot) Event(com.optimizely.ab.event.internal.payload.Event) LogEvent(com.optimizely.ab.event.LogEvent) Variation(com.optimizely.ab.config.Variation) EventBatch(com.optimizely.ab.event.internal.payload.EventBatch) Map(java.util.Map)

Aggregations

EventBatch (com.optimizely.ab.event.internal.payload.EventBatch)3 Snapshot (com.optimizely.ab.event.internal.payload.Snapshot)3 Visitor (com.optimizely.ab.event.internal.payload.Visitor)3 LogEvent (com.optimizely.ab.event.LogEvent)2 Decision (com.optimizely.ab.event.internal.payload.Decision)2 Event (com.optimizely.ab.event.internal.payload.Event)2 EventType (com.optimizely.ab.config.EventType)1 Experiment (com.optimizely.ab.config.Experiment)1 Variation (com.optimizely.ab.config.Variation)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1