Rich-text Reply

Track results only when element exists

welshmike 06-16-14

Track results only when element exists

Our current product pages have a size dropdown, and when a product only has one size the dropdown will contain the value "One Size".

 

I want to experiment with hiding the dropdown in this case. This can be done with the jquery:

 

if($('#input1 option').size() === 1 && $('#input1 option').first().text() === 'One Size') {
    // code to remove
}

 

 

As this would be applied to all product pages (based on URL) and so that I can track acurate results, is there a way to either prevent optimisely from tracking results for pages that do not meet the above conditions, or alternatively only track those that do?

 

Mike

adzeds 06-16-14
 

Re: Track results only when element exists

Mike,

 

Your issue is actually the same as one that I am currently looking to solve.

 

I thought there would be some custom event that I could call to drop sessions that did not meet certain criteria but that does not appear to be an option.

 

I assume that we are missing something obvious as I am sure Optimizely have this functionality in their product in some capacity.

David Shaw
Level 11
adzeds 06-16-14
 

Re: Track results only when element exists

I think the answer is likely to be related to 'Custom Tags':
http://developers.optimizely.com/javascript/#custom-tag-9

But it is not the easiest thing to implement.
David Shaw
Level 11
Amanda 06-17-14
 

Re: Track results only when element exists

Hey @welshmike 

 

You will want to incorporate logic into your targeting conditions that ensures the experiment only runs on pages that have the 'One Size' value in the dropdown. Since goals and conversion events are only captured for visitors who get bucketed into the experiment, this will ensure that your actions are only tracked for the correct group of people. 

 

To adjust your targeting, you can use a custom JavaScript condition.  However, this can get tricky because your logic is referecing a specific element on the page that I assume exists below the Optimizely snippet. When the Optimizely snippet executes, the condition will always evaluate to false since the element $('#input1 option') doesn't exist on the page yet which will result in an experiment that never runs.  

 

Is there a way you can add a tag to your product pages above the snippet so that Optimizely can reference the value in the custom JS condition?  If not, then another option you have is to use manual activation to only activate the experiment when the condition you listed below is true. This will also ensure that goals are only tracked for the group of people with One Size. 

 

Let me know if you have any questions on this! 

 

 

 

 

 

Optimizely
adzeds 06-17-14
 

Re: Track results only when element exists

This all seems a little bit fiddly.

Surely we can come up with a better way of executing this?

Could we not integrate a call to Optimizely in our JS that can simply flag not to record the visit. Then we can program our logic in the normal way and just send a flag back if the conditions are not met.
David Shaw
Level 11
welshmike 06-17-14
 

Re: Track results only when element exists

I think the ideal solution would be a 'exclude from reporting' type call that we can add within the variation code 

adzeds 06-17-14
 

Re: Track results only when element exists

Yup. Think we are on the same wavelength @welshmike

Be interesting to see if Optimizely can integrate this.
David Shaw
Level 11
Amanda 06-17-14
 

Re: Track results only when element exists

There is a line of code that can be used to disable tracking - you can read about it here: http://developers.optimizely.com/javascript/#disable-12

 

However, the problem with adding it in the variation code is the visitor has already been included in the experiment and counted as a visitor by the time the variation code runs. This means your visitor count will reflect everyone (whether or not they actually saw the changes). This is why I recommended adding the logic to the targeting if possible so you can keep people who are ineligbile to see the change out of the experiment altogether. 

 

That all being said, the visitor count will be skewed upward for both variations equally, so as long as you take that into consideration, the effect should be the same. Once the "disable" line of code runs, there will be no further events tracked. You could add logic to your if condition to disable tracking in all scenarios that do not meet the 'One Size' rule. 

Optimizely
Junan 06-18-14
 

Re: Track results only when element exists

[ Edited ]

A couple other options that could be used to accomplish this:
1) If you're using Optimizely at the Platinum level, you can add visitors to a segment called "saw_one_size" within your if statement to check if the element exists. You'll want to send off a custom event right after adding the visitors to the segment to simulate a "pageview" so that the visitor is counted as part of the segment even if they don't convert on any goals. Additionally, you'll want to remove the visitor from the segment if they land on a page where the element doesn't exist. Then when you view your results, just view it while filtering your results by the "Saw One Size" segment.

if($('#input1 option').size() === 1 && $('#input1 option').first().text() === 'One Size') {
    // code to remove
    window.optimizely.push(['addToSegment', 'saw_one_size']);
    window.optimizely.push(["trackEvent", window.location.href]);
}
else
{
    window.optimizely.push(['removeFromSegment', 'saw_one_size']);
}


2) The second option is to define your goals as custom events and setup the tracking yourself within the Global JavaScript. You'll want to do the same check for whether the element exists and use jQuery to bind to the events that the visitor triggers in order to send the custom event conversion to Optimizely. In this scenario, your visitor counts will be still include visitors to the non-one-size pages, so you'll want to send a custom event off automatically if the page does have the one-size element.

if($('#input1 option').size() === 1 && $('#input1 option').first().text() === 'One Size') {
    window.optimizely.push(["trackEvent", "on_one_size_page"]);
    $('#someElement').mousedown(function () {
        window.optimizely.push(["trackEvent", "clicked_on_some_element"]);
    });
}

Hope this helps!

Junan Pang
Optimizely
welshmike 06-18-14
 

Re: Track results only when element exists

[ Edited ]

 Hi Junan,

 

One of the key challenges that Optimizely lets us overcome is the ability to make quick onsite changes without the need of developer resources.

 

I'm in a situation where the development is outsourced ,and all changes are chargable and would need to be scheduled, therefore having to change the onsite code is not a viable option, given as the results of the test may be negligable. 

 

Can we add a wishlist feature to either be able to target based on the DOM, or to be able to enable / disable the tracking events based on it?

 

Mike

 

 

adzeds 06-18-14
 

Re: Track results only when element exists

I am with @welshmike on this one!
David Shaw
Level 11
Junan 06-18-14
 

Re: Track results only when element exists

@welshmike @adzeds Great suggestions, I'll be sure to pass this along to the product team.

So the two proposals that I suggested are actually to be used within an Optimizely experiment so they don't require changes to the page directly. With that said, I think I have a better solution than what I suggested yesterday:

1) Create experiment #1 with your jQuery check to see if the element is on the page.
2) Setup the targeting on the page itself with the assumption that it will include pages that have the element as well as pages that don't.

3) Within experiment #1, if the element exists, manually activate a second experiment. No additional variation code. (https://help.optimizely.com/hc/en-us/articles/200040225). You'll only want a single variation so turn off Variation #1 and put the manual activation call in the Original.
4) Create experiment #2 with the same targeting as Experiment #1, but set this to Manual Activation. This experiment will only be activated by Experiment #1 if the element exists so there's no need to check this in Experiment #2. In this experiment, just add in your code to make the changes in your variation. 

With this setup, the visitors and conversions captured in Experiment #2 will reflect only those that landed on a page with the specific element. You can ignore the Experiment #1 results, its not really a test but a way to activate Experiment #2 only when the element exists. One point to be aware of is that since you're running Experiment #1 more broadly, you'll use visitors that aren't truly being "tested". However, when they make it to Experiment #2, they won't count again towards your "unique visitor allocation" as they've already been counted (only from a usage perspective). 

Again, appreciate the product feature suggestion, hope this helps get your experiment off the ground in the meantime.

 

Thanks!

Junan Pang
Optimizely
Amanda 06-18-14
 

Re: Track results only when element exists

Thanks @Junan !

 

Also, @welshmike , you can add your product ideas within Optiverse here. This list is reviewed and updated by our product team. Also, posting the idea Optiverse allows others to upvote your idea Smiley Happy

Optimizely
welshmike 06-19-14
 

Re: Track results only when element exists

@Junan @Amanda thanks both!