Rich-text Reply

How can I stop tracking if a page has a specific css-id ?

takuma 02-26-16

How can I stop tracking if a page has a specific css-id ?

Hi, I'm Takuma.

Now, I have a trouble on my test...

I want to stop optimizely-tracking if a page, which is one of  dynamic pages, has specific css-id and I want to do this on JS editor of Optimizely.

For example, when a page doesn't have #hoge, I allow optimizely to track the page, but when a page has #hoge, I'll let optimilzey stop tracking.


Is it capable on optimizely??

Level 2

DavidS 02-29-16

Re: How can I stop tracking if a page has a specific css-id ?

Hi there,


Thanks for reaching out!


 I understand that you are looking to activate an experiment based on the existence of a CSS id on the page. 

You could do that by setting the activation mode of your experiment to manual and then use a Javascript API call to activate your experiment everytime #hoge is not present on the page. 


First, to change the Activation Mode to manual, you will need to head to your experiment page, click on Options, then Activation Mode. Select Manual in the new popup that appears. Click Apply to save changes. 


Now in your website you will need to put the following activation code : 


 if($("#hoge").length == 0) {
  window.optimizely = window.optimizely || [];

If the #hoge id class does not exist, then Optimizely will activate any experiment that matches the URL targeting and Audience condition settings. Please note that this code needs to run on every page that you wish the experiment to run on. For that reason it is not possible to put this code in the Code Editor in Optimizely. 


Does that answer your question?