Rich-text Reply

Can't get the Conditional Activation to work

timmcqu2 09-13-16

Can't get the Conditional Activation to work

I have set up a Variation in Optimizely which should cause the page to Active when the user's Internet Provider (the "org" sourced from ipinfo) contains "Internode".

 

This is the code I have in the Conditional Activation box:

/*
 * Conditional Activation Function
 *
 * @param {Function} activate - Activate this experiment
 * @param {Object=} options {
 *                    isActive : {Boolean} - Current activation status
 *                    experimentId : {Integer} - This experiment's Id
 *                  }
 */

function(activate, options) {
 $.getJSON("http://ipinfo.io", function(response){
     if (response.org.indexOf('Internode') > -1 ) {
      activate();
    }
  });
}

However, it is not activating; despite my IP org containing "Internode".
I can use jQuery to make changes to my page based on my IP org, both from within the page code in the CMS, or through an Optimizely variation. The $.get.response.org.indexOf('Internode') > -1; command works in the jQuery codes, to evaluate at true for me as a user.

I have tried it with both $.getJSON and $.get in the code.
The ipinfo should be working, as it is working when used in the jQuery code.


Also, when I preview the Variation, it confirms that the experiment is running, but not activated due to not meeting the condition. However, when I click "ignore targeting conditions" it does nothing - it does not activate.

 

What is wrong with my code? Why doesn't it work?

 

Thanks!

Level 2

CouchPsycho 09-14-16
 

Re: Can't get the Conditional Activation to work

Hi,

not a solution but maybe a hint to find one: Check, if your function is running by changing a , e.g. header on the page to the response.org value. By this u can see if it's firing and which value is returned. Or add an alert as first statement to the function.

Kind regards

Michael



"the essence of the creative act is to see the familiar as strange." (anonymous)
inigam 09-14-16
 

Re: Can't get the Conditional Activation to work

HI Tim

 

Try to run this and check where the code is getting stucked

 

function(activate, options) {
 console.log('response 1');
$.getJSON("http://ipinfo.io", function(response){
console.log('response 2'); if (response.org.indexOf('Internode') > -1 ) { console.log('response 3');
activate(); } }); }

Open developer tools in chrome and check for these console.log values.

Then you would know where to look.

 

 

Regards,
IN


Level 6
timmcqu2 09-19-16
 

Re: Can't get the Conditional Activation to work

Thank you both for your replies.

 

I implimented IN's idea of using the console.log() to identify where it is failing.

It gets to "response 1" fine, but fails before "response 2".

When I look at the Optimizely log, it says "Error running conditional callback function" (for the experiment ID).

 

Any ideas why (or how to work out why) it is failing at this point?

-- keep in mind that pasting the jQuery into the actual page (and using jQuery to make page changes based on the result) works, as well as pasting that same jQuery code into the 'edit code' section of Optimizely. It is only when it is in the Conditional Activation that it fails to be processed.

 

Thank you in advance.

Level 2
JasonDahlin 09-20-16
 

Re: Can't get the Conditional Activation to work

If it works when you run it in your console, but not when run via Optimizely, it could be a scope issue where you are using a method that exists in your page's jQuery but not Optimizely's jQuery.  Try prefacing your $s with window.

 

e.g.

$.getJSON

becomes

window.$getJSON

 

 

--Jason Dahlin
Analytics and Testing Guru Smiley Happy
Experimentation Hero
timmcqu2 09-20-16
 

Re: Can't get the Conditional Activation to work

Hi Jason,

The code does work when placed in Optimizely's 'edit code' for a variation. However, it does not work when (a modified version) is in the Conditional Activation setting. It doesn't activate.
Level 2
JasonDahlin 09-20-16
 

Re: Can't get the Conditional Activation to work

That may be because the code in the editor is running after the page loads. Try the window scoping to see if that helps. (I usually window scope all of them then remove them one at a time until it works so that I will remember which one was the culprit). Thankfully, saving to the cdn only takes a minute, so this process doesn't take too long.
--Jason Dahlin
Analytics and Testing Guru Smiley Happy
Experimentation Hero
JasonDahlin 09-20-16
 

Re: Can't get the Conditional Activation to work

 
--Jason Dahlin
Analytics and Testing Guru Smiley Happy
Experimentation Hero
timmcqu2 09-21-16
 

Re: Can't get the Conditional Activation to work

[ Edited ]

That makes sense (re: page load & running order).

I have put the window.$getJSON, but alas no luck. Smiley Sad It still doesn't activate because "I have not met the conditions" -- yet I know my ISP is Internode (and the code works when not in CA).

Still only returning 'response 1'.
Console doesn't show any errors.
Optimizely log still outputs:

Optimizely / Distributor / Configuring conditionally-activated experiment
Optimizely / Distributor / Error running conditional callback function


This is my code in the CA sections (I have updated it a bit from the original one, streamlined it to only fetch the org field):

/*
* Conditional Activation Function
*
* @param {Function} activate - Activate this experiment
* @param {Object=} options {
* isActive : {Boolean} - Current activation status
* experimentId : {Integer} - This experiment's Id
* }
*/

function(activate, options) {
console.log('response 1');
window.$getJSON("http://ipinfo.io/org", function(response){
console.log('response 2');
if (response.indexOf('Internode') > -1 ) {
console.log('response 3');
activate();
}
});
}
Level 2