Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
96 changes: 28 additions & 68 deletions core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,9 @@
import com.optimizely.ab.event.internal.EventBuilderV1;
import com.optimizely.ab.event.internal.EventBuilderV2;
import com.optimizely.ab.event.internal.payload.Event.ClientEngine;
import com.optimizely.ab.internal.EventTagUtils;
import com.optimizely.ab.internal.ProjectValidationUtils;
import com.optimizely.ab.internal.ReservedEventKey;
import com.optimizely.ab.notification.NotificationListener;
import com.optimizely.ab.notification.NotificationBroadcaster;

Expand Down Expand Up @@ -117,22 +119,9 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
return activate(experimentKey, userId, Collections.<String, String>emptyMap());
}

public @Nullable Variation activate(@Nonnull String experimentKey,
@Nonnull String userId,
@CheckForNull String sessionId) throws UnknownExperimentException {
return activate(experimentKey, userId, Collections.<String, String>emptyMap(), sessionId);
}

public @Nullable Variation activate(@Nonnull String experimentKey,
@Nonnull String userId,
@Nonnull Map<String, String> attributes) throws UnknownExperimentException {
return activate(experimentKey, userId, attributes, null);
}

public @Nullable Variation activate(@Nonnull String experimentKey,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
@CheckForNull String sessionId) throws UnknownExperimentException {

if (!validateUserId(userId)) {
logger.info("Not activating user for experiment \"{}\".", experimentKey);
Expand All @@ -148,42 +137,27 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,
return null;
}

return activate(currentConfig, experiment, userId, attributes, sessionId);
return activate(currentConfig, experiment, userId, attributes);
}

public @Nullable Variation activate(@Nonnull Experiment experiment,
@Nonnull String userId) {
return activate(experiment, userId, Collections.<String, String>emptyMap());
}

public @Nullable Variation activate(@Nonnull Experiment experiment,
@Nonnull String userId,
@CheckForNull String sessionId) {
return activate(experiment, userId, Collections.<String, String>emptyMap(), sessionId);
}

public @Nullable Variation activate(@Nonnull Experiment experiment,
@Nonnull String userId,
@Nonnull Map<String, String> attributes) {

return activate(experiment, userId, attributes, null);
}

public @Nullable Variation activate(@Nonnull Experiment experiment,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
@CheckForNull String sessionId) {

ProjectConfig currentConfig = getProjectConfig();

return activate(currentConfig, experiment, userId, attributes, sessionId);
return activate(currentConfig, experiment, userId, attributes);
}

private @Nullable Variation activate(@Nonnull ProjectConfig projectConfig,
@Nonnull Experiment experiment,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
@CheckForNull String sessionId) {
@Nonnull Map<String, String> attributes) {
// determine whether all the given attributes are present in the project config. If not, filter out the unknown
// attributes.
attributes = filterAttributes(projectConfig, attributes);
Expand All @@ -202,7 +176,7 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,

if (experiment.isRunning()) {
LogEvent impressionEvent = eventBuilder.createImpressionEvent(projectConfig, experiment, variation, userId,
attributes, sessionId);
attributes);
logger.info("Activating user \"{}\" in experiment \"{}\".", userId, experiment.getKey());
logger.debug(
"Dispatching impression event to URL {} with params {} and payload \"{}\".",
Expand All @@ -225,61 +199,39 @@ private Optimizely(@Nonnull ProjectConfig projectConfig,

public void track(@Nonnull String eventName,
@Nonnull String userId) throws UnknownEventTypeException {
track(eventName, userId, Collections.<String, String>emptyMap(), null, null);
}

public void track(@Nonnull String eventName,
@Nonnull String userId,
@CheckForNull String sessionId) throws UnknownEventTypeException {
track(eventName, userId, Collections.<String, String>emptyMap(), null, sessionId);
track(eventName, userId, Collections.<String, String>emptyMap(), Collections.<String, Object>emptyMap());
}

public void track(@Nonnull String eventName,
@Nonnull String userId,
@Nonnull Map<String, String> attributes) throws UnknownEventTypeException {
track(eventName, userId, attributes, null, null);
}

public void track(@Nonnull String eventName,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
@CheckForNull String sessionId) throws UnknownEventTypeException {
track(eventName, userId, attributes, null, sessionId);
track(eventName, userId, attributes, Collections.<String, String>emptyMap());
}

/**
* @deprecated see {@link #track(String, String, Map)} and pass in the revenue value as an event tag instead.
*/
public void track(@Nonnull String eventName,
@Nonnull String userId,
long eventValue) throws UnknownEventTypeException {
track(eventName, userId, Collections.<String, String>emptyMap(), eventValue);
}

public void track(@Nonnull String eventName,
@Nonnull String userId,
long eventValue,
@CheckForNull String sessionId) throws UnknownEventTypeException {
track(eventName, userId, Collections.<String, String>emptyMap(), eventValue, sessionId);
track(eventName, userId, Collections.<String, String>emptyMap(), Collections.singletonMap(
ReservedEventKey.REVENUE.toString(), eventValue));
}

/**
* @deprecated see {@link #track(String, String, Map, long)} and pass in the revenue value as an event tag instead.
*/
public void track(@Nonnull String eventName,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
long eventValue) throws UnknownEventTypeException {
track(eventName, userId, attributes, (Long)eventValue, null);
track(eventName, userId, attributes, Collections.singletonMap(ReservedEventKey.REVENUE.toString(), eventValue));
}

public void track(@Nonnull String eventName,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
long eventValue,
@CheckForNull String sessionId) throws UnknownEventTypeException {
track(eventName, userId, attributes, (Long)eventValue, sessionId);
}

private void track(@Nonnull String eventName,
@Nonnull String userId,
@Nonnull Map<String, String> attributes,
@CheckForNull Long eventValue,
@CheckForNull String sessionId) throws UnknownEventTypeException {
@Nonnull Map<String, ?> eventTags) throws UnknownEventTypeException {

ProjectConfig currentConfig = getProjectConfig();

Expand All @@ -294,10 +246,18 @@ private void track(@Nonnull String eventName,
// attributes.
attributes = filterAttributes(currentConfig, attributes);

Long eventValue = null;
if (eventTags == null) {
logger.warn("Event tags is null when non-null was expected. Defaulting to an empty event tags map.");
eventTags = Collections.<String, String>emptyMap();
} else {
eventValue = EventTagUtils.getRevenueValue(eventTags);
}

// create the conversion event request parameters, then dispatch
LogEvent conversionEvent = eventBuilder.createConversionEvent(currentConfig, bucketer, userId,
eventType.getId(), eventType.getKey(), attributes,
eventValue, sessionId);
eventTags);

if (conversionEvent == null) {
logger.info("There are no valid experiments for event \"{}\" to track.", eventName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion core-api/src/main/java/com/optimizely/ab/config/Group.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2016, Optimizely and contributors
* Copyright 2016-2017, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading