Set up Localytics
Read the Localytics Getting Started Guide if you're getting started.
Localytics offers more than one option for capturing Optimizely test information. The code examples demonstrate the Custom Events with Attributes option in this suggested integration. For more information and alternative solutions, see the sections below.
Android
The example code has two parts:
- Add a
TrackNotificationListener
listener foronEvent
to wrapLocalytics.tagEvent()
- Add
OptimizelyClient.track()
to track conversions
Instead of calling Localytics.tagEvent()
directly, wrap the calls with OptimizelyClient.track()
to include bucketing information as event attributes.
The example code demonstrates how to add a track event listener. Each OptimizelyClient.track()
event tracking retrieves a mapping of experiment key to variation key from UserProfile
, which records bucketing decisions. Next, the code calls Localytics.tagEvent()
and includes the bucketing map among the attributes.
The last step is to add OptimizelyClient.track()
to track event conversions.
Maintaining a consistent user identity across multiple sessions and devices can help ensure proper reporting. Localytics provides some guidelines for their platform.
Optimizely recommends using the same user ID with these methods:
optimizelyClient.activate()
Localytics.setCustomerId()
Another solution is to set Localytics' Custom Dimensions using an ActivateNotificationListener
. Custom dimensions can be used to segment users without needing to wrap Localytics.tagEvent()
, but they require configuration in the Localytics dashboard for each Optimizely test.
import com.localytics.android.Localytics;
import com.optimizely.ab.bucketing.UserProfile;
import com.optimizely.ab.notification.NotificationListener;
import com.optimizely.ab.notification.TrackNotificationListener;
import java.util.Map;
optimizelyManager.getOptimizely().getNotificationCenter().addNotificationListener(NotificationCenter.NotificationType.Track, new TrackNotificationListener() {
@Override
public void onTrack(@Nonnull String eventKey, @Nonnull String userId, @Nonnull Map<String, String> attributes, @Nonnull Map<String, ?> eventTags, @Nonnull LogEvent event) {
// Make a copy of attributes because it could be immutable
Map<String, String> attr = new HashMap<>(attributes);
// Retrieve mapping of tests to variations
UserProfile userProfile = optimizelyManager.getUserProfile();
Map<String, Map<String, String>> allRecords =
userProfile.getAllRecords();
// Set event attributes
if (allRecords.containsKey(userId)) {
Map<String, String> userRecords = allRecords.get(userId);
for (Map.Entry<String, String> entry : userRecords.entrySet()) {
// Mapping of experiment key to variation key
attr.put(entry.getKey(), entry.getValue());
}
}
// Tag custom event with attributes
Localytics.tagEvent("[Optimizely] " + eventKey, attr);
}
});
// Track a conversion event for the provided user
optimizelyClient.track(eventKey, userId);
Objective-C
The example code has two parts:
- Add a track event listener to wrap
[Localytics tagEvent]
- Add
[optimizely track]
to track conversions
Instead of calling [Localytics tagEvent]
directly, wrap the calls with [optimizely track]
to include bucketing information as event attributes.
The example code demonstrates how to add the track notification listener. Each [optimizely track]
event tracking adds a mapping of experiment key to variation key to the event attributes and passes the mapping to [Localytics tagEvent]
.
The last step is to add [optimizely track]
to track event conversions.
Maintaining a consistent user identity across multiple sessions and devices can help ensure proper reporting. Localytics provides some guidelines for their platform.
Optimizely recommends using the same user ID with these methods:
[optimizely activate]
[Localytics setCustomerId]
Another solution is to set Localytics' Custom Dimensions using an activate notification listener. Custom dimensions can be used to segment users without needing to wrap [Localytics tagEvent]
, but they require configuration in the Localytics dashboard for each Optimizely test.
@import Localytics;
// Add a Track notification listener
NSInteger trackNotificationId = [optimizely.notificationCenter addTrackNotificationListener:^(NSString * _Nonnull eventKey, NSString * _Nonnull userId, NSDictionary<NSString *,NSString *> * _Nonnull attributes, NSDictionary * _Nonnull eventTags, NSDictionary<NSString *,NSObject *> * _Nonnull event) {
// Tag custom event with attributes
NSString *eventIdentifier
= [NSString stringWithFormat:@"[Optimizely] %@",
eventKey]];
[Localytics tagEvent:eventIdentifier attributes:attributes];
}];
// Track a conversion event for the provided user
[optimizely track:eventKey userId:userId];
Swift
The example code has two parts:
- Add a track notification listener to wrap
Localytics.tagEvent()
- Add
optimizely.track()
to track conversions
Instead of calling Localytics.tagEvent()
directly, wrap the calls with optimizely.track()
to include bucketing information as event attributes.
The example code demonstrates how to add a track notification listener. Each time optimizely.track()
event tracking adds a mapping of experiment key to variation key to the event attributes and pass the mapping to Localytics.tagEvent()
.
The last step is to add optimizely.track()
to track event conversions.
Maintaining a consistent user identity across multiple sessions and devices can help ensure proper reporting. Localytics provides some guidelines for their platform.
Optimizely recommends using the same user ID with these methods:
optimizely.activate()
Localytics.setCustomerId()
Another solution is to set Localytics' Custom Dimensions using an activate notification listener. Custom dimensions can be used to segment users without needing to wrap Localytics.tagEvent()
but requires configuration in the Localytics dashboard for each Optimizely test.
import Localytics
// Add a track notification listener
optimizely?.notificationCenter?.addTrackNotificationListener({ (eventKey, userId, attributes, eventTags, event) in
// Tag custom event with attributes
let localyticsEventIdentifier : String = "[Optimizely] " + eventKey
Localytics.tagEvent(localyticsEventIdentifier, attributes)
})
optimizely?.track(eventKey, userId)
Compare results
When comparing Optimizely and Localytics results, remember to apply a date filter in Localytics that corresponds with the dates your Optimizely test was running.
Unsupported Platforms
Optimizely does not have a suggested solution for integrating Localytics with our SDKs for these platforms:
- C#
- Java
- JavaScript
- Node
- PHP
- Python
- Ruby
Updated over 3 years ago