Set up Localytics
This topic describes how you can integrate Localytics with Optimizely.
Note
See Optimizely's Third-Party Add-Ons & Platform Integration Terms.
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.
Important
This integration leverages API behavior that has changed for 3.0. If you encounter any issues, please contact support.
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.
Consistent user identity
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()
Alternative solution
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);
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:
- Agent
- Go
- C#
- Java
- JavaScript
- Node
- PHP
- Python
- Ruby
Updated 4 months ago