Rich-text Reply

Can setValue:forCustomTag method (IOS SDK) be called after +startOptimizelyWithAPIToken?

dratewka 01-07-15
Accepted Solution

Can setValue:forCustomTag method (IOS SDK) be called after +startOptimizelyWithAPIToken?

[ Edited ]

Hi,

 

in our app we wanted to use custom tags for user targeting. We know that you can use  

setValue:forCustomTag

but the docs state: Warning: This method should be called before +startOptimizelyWithAPIToken

and we wanted to base our tags on information available after Optimizely has been started. Can we still do that?
What does violating this warning implicate?


Anny suggestions appreciated!

 

Thanks in advance,
Paweł

Level 2

Re: Can setValue:forCustomTag method (IOS SDK) be called after +startOptimizelyWithAPIToken?

Hi @dratewka!

 

Thanks for asking about and using our iOS SDK; however, that unfortunately will not work. As a brief overview, Optimizely works in the way that someone will not be in the experiment unless a variable is set.  What they can do is to set a variable around the code block or live variable they're making changes to.  

 

e.g.: 

 

 

   if (self.logInState == LOGGEDIN) {
        
        [Optimizely codeBlocksWithKey:loggedInExperimentExample
                             blockOne:^{
                                 LoggedInExpViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"optlyExpRunning"];
 
                                 [self.navigationController pushViewController:newView animated:YES];
                             }
                         defaultBlock:^{
                             LoggedInExpViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"loggedInNoExp"];
 
                             [self.navigationController pushViewController:newView animated:YES];
                         }];
        
    }
    else {
        LoggedOutExpViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"logOutExp"];
        [self.navigationController pushViewController:newView animated:YES];
    }

 

I hope that helps!

 

Derek

dratewka 01-08-15
 

Re: Can setValue:forCustomTag method (IOS SDK) be called after +startOptimizelyWithAPIToken?

Hi Derek!

Thank you for your quick response and suggestions.   However I think, that I should describe our use case more deeply.

What we want to do is to integrate our mobile Optimizely tests with a service responsible for dividing our users into test groups. So the idea was, once the mobile app gets started it fetches information about the whether the current user is in such a group or not - this information chages when the user logs in. 

We thought about using the tags feature for this as it seemed the most appropriate (targeting would for specific tests be defined by setting the required tag values using  Optimizely UI  and the mobile app would get its tags from our service). 
Static checks are not really feasible for us, so my next question is - can you use live variables for targeting while setting up Optimizely tests? Or maybe there exists some other means to do this?

Best,
Pawel

Level 2
Suneet 01-09-15
 

Re: Can setValue:forCustomTag method (IOS SDK) be called after +startOptimizelyWithAPIToken?

Hi Pawel,

 

Thanks for that extra context about your scenario.

 

My name is Suneet and I'm a Product Manager on the mobile team at Optimizely.

 

With the way our product works right and your scenario, what you can do is set the custom tag once you have the data available from your service (after startOptimizely), and the next time a user opens the app (a foregrounding event or a cold start), that experiment will be activated.

 

Currently experiments are only activated on application launch (when calling startOptimizely), and on a foregrounding event (the app re-opening from the background)

 

By default, Optimizely reloads experiments on foregrounding-- but if you have changed that setting, you will want to set it to yes as follows:

 

    [[Optimizely sharedInstance] setShouldReloadExperimentsOnForegrounding:YES];

 

Does that make sense?

 

Thanks,

Suneet

 

Optimizely
dratewka 01-12-15
 

Re: Can setValue:forCustomTag method (IOS SDK) be called after +startOptimizelyWithAPIToken?

Hi Suneet,

thanks for your answer!

Yes, this does make sense, but just to be sure: you wrote that:

 

and the next time a user opens the app (a foregrounding event or a cold start), that experiment will be activated.

 

 

so does this mean that Optimizely SDK stores tha tag values (by itself) on the mobile device and reloads them on startup?
Or just that the tags (which have to be manually set) become "effective" after reloading the experiments?

Cheers,
Pawel

Level 2
Suneet 01-13-15
 

Re: Can setValue:forCustomTag method (IOS SDK) be called after +startOptimizelyWithAPIToken?

Hi Pawel,

 

The tags are cached locally, but experiments are only reloaded on application start & and on application foregrounding event.

 

So once you set the custom tags, the next time experiments are reloaded (on app launch or foregrounding), assuming the targeting conditions are met, that experiment will run. 

 

Thanks,

Suneet

Optimizely