Rich-text Reply

Audience with custom Javascript conditions

dviss 04-27-19

Audience with custom Javascript conditions

I have an audience created which has two conditions: one of two elements need to be present AND one of two elements needs to be not present. In the developers console I get both conditions to return 'true', yet the debug log is saying 'Not activating Campaign: XXX ; not in the cohort because: Audience conditions failed for experiment: YYY.' Please advise how to activate an experiment based on these requirements.

Optimizely Conditions.png
Level 2

Re: Audience with custom Javascript conditions

Hi,

Please try combining the two javascript conditions into one audience condition.

Regards
Optimizely
CouchPsycho 04-29-19
 

Re: Audience with custom Javascript conditions

Try to put it into an anonymous function, in order to generate some output to the console:

 

(function()
{
	var condition1 = .... ;
	var condition2 = .... ;

	if ( condition1 && condition2 )
	{
		return true;
	}
	else
	{
		console.log("Condition1:"+condition1);
		console.log("Condition2:"+condition2);
		return false;
	}
})();

And keep in mind, that you might have a timing issue, if you have lazy loading content, JS modifying your code etc.

Kind regards

Michael


   
dviss 04-29-19
 

Re: Audience with custom Javascript conditions

@mansoor-omarThank you for your suggestion. I combined the two conditions into one and am still not in the audience.

Level 2
dviss 04-29-19
 

Re: Audience with custom Javascript conditions

@CouchPsychothank you for your suggestion. The content is not lazy loaded.

 

I've tried an anonymous function which is still not placing me into the audience and the console.log from the audience seems to be suppressed. I may try splitting the audience into two.

Level 2
dviss 04-29-19
 

Re: Audience with custom Javascript conditions

clarification; when viewing the page with ?optimizely_log=DEBUG, the log from the audience code is not present. I see the Condition1 & 2 values in the log when the Optimizely log is off.
Level 2
JasonDahlin 04-29-19
 

Re: Audience with custom Javascript conditions

Side note: "console.log" will not be defined, use "window.console.log"

--Jason Dahlin
Analytics and Testing Guru Smiley Happy


Experimentation Hero