Skip to content

Commit 7fe96ad

Browse files
authored
Add event tags to track API (#97)
1 parent 6c18a00 commit 7fe96ad

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Optimizely Android X SDK Changelog
2+
### 1.2.0
3+
March 20, 2017
4+
5+
- Add event tags to the `track` API
6+
- Deprecated `eventValue` parameter from the `track` API. Use event tags to pass in event value instead
7+
- Update to java-core 1.6.0 (https://github.com/optimizely/java-sdk/blob/master/CHANGELOG.md#160)
8+
29
### 1.1.0
310
February 17, 2017
411

android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyClient.java

+22
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,27 @@ public void track(@NonNull String eventName,
134134
* Track an event for a user
135135
* @param eventName the name of the event
136136
* @param userId the user id
137+
* @param attributes a map of attributes about the user
138+
* @param eventTags a map of metadata associated with the event
139+
*/
140+
public void track(@NonNull String eventName,
141+
@NonNull String userId,
142+
@NonNull Map<String, String> attributes,
143+
@NonNull Map<String, ?> eventTags) throws UnknownEventTypeException {
144+
if (optimizely != null) {
145+
optimizely.track(eventName, userId, attributes, eventTags);
146+
147+
} else {
148+
logger.warn("Optimizely is not initialized, could not track event {} for user {}" +
149+
" with attributes and event tags", eventName, userId);
150+
}
151+
}
152+
153+
/**
154+
* Track an event for a user
155+
* @deprecated see {@link Optimizely#track(String, String, Map, Map)} and pass in revenue values as event tags instead.
156+
* @param eventName the name of the event
157+
* @param userId the user id
137158
* @param eventValue a value to tie to the event
138159
*/
139160
public void track(@NonNull String eventName,
@@ -150,6 +171,7 @@ public void track(@NonNull String eventName,
150171
/**
151172
* Track an event for a user with attributes and a value
152173
* @see Optimizely#track(String, String, Map, Long)
174+
* @deprecated see {@link Optimizely#track(String, String, Map, Map)} and pass in revenue values as event tags instead.
153175
* @param eventName the String name of the event
154176
* @param userId the String user id
155177
* @param attributes the attributes of the event

android-sdk/src/test/java/com/optimizely/ab/android/sdk/OptimizelyClientTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ public void testBadTrack4() {
139139
"with value {} and attributes", "event1", "1", 1L);
140140
}
141141

142+
@Test
143+
public void testTrackWithEventTags() {
144+
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);
145+
final HashMap<String, String> attributes = new HashMap<>();
146+
attributes.put("foo", "bar");
147+
final HashMap<String, Object> eventTags = new HashMap<>();
148+
eventTags.put("foo", 843);
149+
optimizelyClient.track("event1", "1", attributes, eventTags);
150+
verify(optimizely).track("event1", "1", attributes, eventTags);
151+
}
152+
142153
@Test
143154
public void testGoodGetVariation1() {
144155
OptimizelyClient optimizelyClient = new OptimizelyClient(optimizely, logger);

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ext {
5252
min_sdk_version = 10
5353
target_sdk_version = 24
5454

55-
java_core_ver = "1.5.0"
55+
java_core_ver = "1.6.0"
5656
android_logger_ver = "1.3.1"
5757
support_annotations_ver = "24.2.1"
5858
junit_ver = "4.12"

0 commit comments

Comments
 (0)