Rich-text Reply

Custom Event based on cookie value

davepowell 01-19-17
Accepted Solution

Custom Event based on cookie value

Hello!

I trying to set up a custom event that counts a success based on a cookie value.

i.e if my_cookie contains 10.10.10

Basically, the test is to determine an increase in sales of a particular product.
Having this I would also duplicate it and track the affect on other products.

Hope someone can help!

 

Cheers,

 

-Dave

RyanC 01-19-17
 

Re: Custom Event based on cookie value

This should work:

 

function getCookie(b) {
var a, c, d, e = document.cookie.split(";");
for (a = 0; a < e.length; a++) {
c = e[a].substr(0, e[a].indexOf("="));
d = e[a].substr(e[a].indexOf("=") + 1);
c = c.replace(/^\s+|\s+$/g, "");
if (c == b) return unescape(d);
}
}

 

var cookieValue = getCookie('my_cookie');

 

if(cookieValue.indexOf("10.10.10") >= 0)

{

window['optimizely'] = window['optimizely'] || [];
window.optimizely.push(["trackEvent", "eventName"]);

}

Ryan
------------------------------------------------
The best solution is the simplest.

https://www.linkedin.com/in/ryan-camilleri
http://midnightknights.com
Experimentation Hero
davepowell 01-19-17
 

Re: Custom Event based on cookie value

A M A Z I N G !

Thanks a lot!
RyanC 01-19-17
 

Re: Custom Event based on cookie value

You are welcome, please "Accept as Solution" on my reply if it has answered your question.
Ryan
------------------------------------------------
The best solution is the simplest.

https://www.linkedin.com/in/ryan-camilleri
http://midnightknights.com
Experimentation Hero
davepowell 01-19-17
 

Re: Custom Event based on cookie value

I will - I'm just finding out how to test if it works or not. Will get back to you - Cheers!