Rich-text Reply

Custom Javascript audience targeting

Nicolas_Hemidy 04-27-16

Custom Javascript audience targeting

Hey everyone!

Glad to be part of this community Smiley Happy. I'm quite new on Optimizely and I have an issue understanding how to set up my experiment.

I would like to target visitors who have seen X time(s) a specific page. I just don't understand how to do this, I feel I have to use custom event or custom javascript when defining an audience but I'm not sure.

Thanks a lot in advance for your help,


robertchan 04-27-16

Re: Custom Javascript audience targeting

Paste the following code into your experiment JavaScript:


window.setCookie = function(c_name,value,exdays,c_domain) {
   c_domain = (typeof c_domain === "undefined") ? "" : "domain=" + c_domain + ";";
   var exdate=new Date();
   exdate.setDate(exdate.getDate() + exdays);
   var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
   document.cookie=c_name + "=" + c_value + ";" + c_domain + "path=/";

In the Audience section of your experiment, drag a cookie in and set the parameter to "has any value."

Robert Chan

Re: Custom Javascript audience targeting

Hi Robert,

Thanks a lot! I think it will work if the behaviour of the page depends on the number of visits on this page.

But, maybe my question was not enough precise, I would like to trigger this experiment depending on the number of visits on another page (not the one concerned by my experiment).

Let me know if what I say has no sense.. Thanks a lot!

robertchan 04-28-16

Re: Custom Javascript audience targeting

Hi Nicolas,

In this case, you'll need to set a cookie for users from the other page, and on the page you're building the experiment, you would need to specify that users who have that cookie will not see this experiment ("has not") within the audience conditions.
Robert Chan