Rich-text Reply

Notification Listeners in Optimizely X iOS SDK

craigrouse 02-06-17
Accepted Solution

Notification Listeners in Optimizely X iOS SDK

In the OptimizelyX Android SDK, it's possible to implement event listeners to listen for experiment activation and events being tracked.

 

It seems that the equivalent has not yet been implemented in the iOS SDK. I expected that the feature might have been released but not yet documented, but I think in fact the feature just hasn't been released at all yet. Is this correct, or have I missed something? 

 

Also, just as an FYI, the code blocks in the OptimizelyX iOS Quick Start guide are out of date and don't work at all; I guess the API calls changed slightly between releases. The documentation in the "reference" section is up to date, but I only found this after I'd muddled through and managed to find the correct API calls using automatic code completion in XCode.

 

The Android SDK by contrast is well-documented, and I didn't have any issues.

 

Thanks,

 

Craig.

wangjoshuah 02-06-17
 

Re: Notification Listeners in Optimizely X iOS SDK

Hi Craig,

 

Thanks so much for the feedback! Can you point us to the outdated code blocks in the Optimizely X iOS guide so we can fix that? We have implemented and released event listeners for the Optimizely X iOS SDK, but we have not gotten around to documenting it yet. You can subscribe to them by subscribing to OptimizelyDidActivateExperimentNotification or OptimizelyDidTrackEventNotification. You can see how the experiment activation notification is created here, and the track event notification is created here. We will try and update our documentation to explain this in more detail soon.

 

Thanks for helping us out,

Josh

Optimizely
craigrouse 02-07-17
 

Re: Notification Listeners in Optimizely X iOS SDK

Hi @wangjoshuah,

Not sure if my last reply went through? It looks like I wasn't logged in when I posted.

The outdated code blocks are on this page:

https://developers.optimizely.com/x/solutions/sdks/getting-started/index.html?language=objectivec&pl...

e.g. initializeWithCallback is now initializeClientWithCallback

Thanks,

Craig.
craigrouse 02-07-17
 

Re: Notification Listeners in Optimizely X iOS SDK

Hi again @wangjoshuah,

I just checked the version of the code that comes with the module that's up on Cocoapods, and it seems the Cocoapods version is out of date, and the notifications feature is missing.

Thanks,

Craig.
craigrouse 02-08-17
 

Re: Notification Listeners in Optimizely X iOS SDK

Just posting back here for the benefit of anyone else reading this thread: I've now switched from Cocoapods to Carthage - Carthage pulls the up-to-date files from GitHub, while the Cocoapods pod is out of date.

After switching, I found that in fact the Quickstart guide (https://developers.optimizely.com/x/solutions/sdks/getting-started/index.html?language=objectivec&pl...) is correct, and the "Reference" documentation is incorrect (https://developers.optimizely.com/x/solutions/sdks/reference/index.html?language=objectivec&platform...).

The reference docs, for example, use the "initWithBuilderBlock" method, whilst the quickstart docs reference the (correct) "initializeWithCallback" method.

So, anyone using Cocoapods and then referencing the Quickstart guide will have problems, and likewise, anyone using Carthage and reading the "Reference" documentation will also have issues, as the API methods don't match the documentation.
craigrouse 02-08-17
 

Re: Notification Listeners in Optimizely X iOS SDK

Just one more thing...

The notification names to subscribe to are actually OptimizelyExperimentActivated and OptimizelyEventTracked

Here's a code snippet that logs Optimizely events to the console, as long as you are using the latest SDK from GitHub via Carthage.

[notifyCenter addObserverForNameSmiley SadNSNotificationName) @"OptimizelyEventTracked" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) {
// Explore notification
NSLog(@"Notification found with:"
"\r\n name: %@"
"\r\n object: %@"
"\r\n userInfo: %@",
[notification name],
[notification object],
[notification userInfo]);
}];

[notifyCenter addObserverForNameSmiley SadNSNotificationName) @"OptimizelyExperimentActivated" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull notification) {
// Explore notification
NSLog(@"Notification found with:"
"\r\n name: %@"
"\r\n object: %@"
"\r\n userInfo: %@",
[notification name],
[notification object],
[notification userInfo]);
}];
wangjoshuah 02-08-17
 

Re: Notification Listeners in Optimizely X iOS SDK

Thanks for your detailed answers Craig! I will definitely incorporate these into our docs and try to update them soon!

For the CocoaPods issue, what version of the pod were you on?
Optimizely