var surveyActive = true; var surveyRatio = 0.1; // how many out of 1 should get surveyed // these two are used by JavaScript within the page: var doPrompt = false; var promptText = ''; if (surveyActive) { // cookieVal can have one of four values: // empty: never been cookied or refuses cookies // n: don't prompt this user // y: do prompt this user // x: this user has already taken the survey var cookieVal = ''; var cookieOffset = document.cookie.indexOf("CHsurvey="); if (cookieOffset != -1) { // "CHsurvey=" is 9 characters long cookieVal = document.cookie.substring(cookieOffset + 9, cookieOffset + 9 + 1); } if (cookieVal == '') { // not previously cookied if (Math.random() < surveyRatio) { cookieVal = 'y'; } else { cookieVal = 'n'; } document.cookie = 'CHsurvey=' + cookieVal + '; path=/wgbh/commandingheights/'; /* // document.cookie doesn't get updated this quickly... // commenting this out means // a) un-cookied users get prompted 1 in 10 no matter what // b) cookied users get prompted on their first page if (document.cookie.indexOf("CHsurvey=") != -1) { // they were unable to take the cookie; don't give them the survey cookieVal = 'n'; } */ } if (cookieVal == 'y') { var promptTextHi = '
'; var promptTextLo = ''; promptText = promptTextLo; if (window.location.pathname.indexOf('/hi/') != -1) { promptText = promptTextHi; } doPrompt = true; } } function surveyed() { document.cookie = 'CHsurvey=x; path=/wgbh/commandingheights/'; }