Rich-text Reply

Check how many users clicked a button on a modal popup?

xaisoft 05-23-16

Check how many users clicked a button on a modal popup?

Hi,

 

I have a modal that pops up after the the 3 pages have been visited.  There are a couple of expirements I would like to try, but I am not sure how to do it.

 

1.   I want to have one variation where the modal is shown to 50% of the users and one where it is not shown.

 

2. I want to see how many users click the subscribe button on my modal, so I want to show it to all users and track the clicks of the subscribe button.

 

What do I need to do to get this started and what parts of the optimizely editor do I need to change.  The modal is hidden, so I can't see it in the optimizely editor.

 

Thanks

Level 2

Re: Check how many users clicked a button on a modal popup?

[ Edited ]

Hello,

I would create an audience and bucket users into the experiment using the cookie condition. When a user visits three pages on your site attach a cookie to that user. From there create two variations, one without the modal and one variation with the modal.

For the second question I would create a click goal on the subscribe button within the modal.

To edit the modal in Optimizely check out this great example that walks you through step by step how to do it.

https://blog.optimizely.com/2013/09/12/how-to-add-a-lightbox-to-an-experiment/

-Joey

-Joey Herzberg
xaisoft 05-23-16
 

Re: Check how many users clicked a button on a modal popup?

Hi,

I added the javascript to the variation code, but it is only running the first time. After that, it does not run anymore, it should run on every page load.

Thanks
Level 2

Re: Check how many users clicked a button on a modal popup?

It depends on how you are implementing your experiment js code. Sounds like you are using a cookie to not display the modal on subsequent visits. Can you share the snippet with me?
-Joey Herzberg
xaisoft 05-23-16
 

Re: Check how many users clicked a button on a modal popup?

This is the code that I run on every page load


$(document).ready(function () {

// check for cookie
var visited = Cookies.get('visited');

alert(visited);
// if no cookie present create cookie
if (visited === undefined || visited === null){
Cookies.set('visited', 1, {expires:30});
}
else
{
alert(visited);
if (visited == 3) {
// open fancybox after 3 secs on 4th visit or further on the same day
setTimeout(function () {
$.magnificPopup.open({
items: {
src: 'div.newsletter-signup'
}
}, 0);
$('#newsletter_signup_modal').show();
}, 3000);

visited++; // increase counter of visits
Cookies.set('visited', visited, {
expires: 45 // expires after one day
});
} else {
visited++; // increase counter of visits
// set new cookie value to match visits
Cookies.set('visited', visited, {
expires: 45 // expires after one day
});
return false;
}
}
});

I put this in the variation code editor, not the one that runs across all variations because I only want it to run in one.
Level 2

Re: Check how many users clicked a button on a modal popup?

I could not get your code to work. Did you try debugging it prior to putting it inside the editor?
-Joey Herzberg
xaisoft 06-03-16
 

Re: Check how many users clicked a button on a modal popup?

Hi Joey,

The code works because I ran it in an editor. It does use an a jquery plugin called js.cookie. When I put it in the editor, it runs once, but stops after that. It runs each time I open up a new tab or window.
Level 2