// This work by Sébastien Brodeur is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. // By : Sebastien Brodeur ([email protected]) // Fire when the user submit the survey. _kiq.push(['eventHandler', 'submit', function(){ // Make sure Google Analytics is available. var _gaq = _gaq || []; // Retrieve KISSIsights survey ID. surveyId = $("[src*='kissinsights.com']").attr("src").match(new RegExp("(id=)(.*)&"))[2]; // For each survey questions... for (i = 0; i < $("[class*='ki_question']").length; i++) { // ... get the question text... question = $("[class*='ki_h1']:eq("+i+")").text(); // ... and the selected anwser text // Check first for radio button answer. anwser = $("[class*='ki_question']:eq("+i+") input:checked[type='radio']").closest("label").text(); if (anwser == "" || anwser == null || anwser == undefined) { // Then for checkbox answer anwser = $("[class*='ki_question']:eq("+i+") input:checked[type='checkbox']").closest("label").text(); } if (anwser == "" || anwser == null || anwser == undefined) { // Then for textbox answer anwser = $("[class*='ki_question']:eq("+i+") textarea").val(); } if (anwser == "" || anwser == null || anwser == undefined) { // And finaly, score anwser = $("[class*='ki_question']:eq("+i+") [class*='active'] a").text(); } // If both data are available, queue a Google Analytics _trackEvent tag. if (question && anwser) _gaq.push(['_trackEvent', 'VOC', surveyId, question +' | ' + anwser]); } }]);