// gather URL params function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1); var sURLVariables = sPageURL.split('&'); for (var i = 0; i < sURLVariables.length; i++) { var sParameterName = sURLVariables[i].split('='); if (sParameterName[0] == sParam) { return sParameterName[1]; } } } function paramPresent(paramName) { return getUrlParameter(paramName) !== void 0 && getUrlParameter(paramName) != ""; } // build featured results in a carousel function carouselBuild() { $('#resultsCarousel .carousel-item').each(function () { var next = $(this).next(); if (!next.length) { next = $(this).siblings(':first'); } next.children(':first-child').clone().appendTo($(this)); //this will only work for carousel with 3 items since it only adds next() and next.next(); if (next.next().length > 0) { next.next().children(':first-child').clone().appendTo($(this)); } else { $(this).siblings(':first').children(':first-child').clone().appendTo($(this)); } }); } // grab user data via maxmind window.mmResults = function (ip, zip, city, state) { // vars from params var ip = ip; var zip = zip; var city = city; var state = state; // AB test value: var sub_3 = typeof window.widgetAbTestSubValue !== "undefined" ? window.widgetAbTestSubValue : ''; // Search assumptions. These should change depending on site var education_level = paramPresent('education_level') ? getUrlParameter('education_level') : 'High School'; var degree_level = paramPresent('degree_level') ? getUrlParameter('degree_level') : 'Bachelor'; var hs_grad_year = paramPresent('hs_grad_year') ? getUrlParameter('hs_grad_year') : '2013'; var age = paramPresent('age') ? getUrlParameter('age') : '25'; var study_area = paramPresent('area_of_study') ? getUrlParameter('area_of_study') : 'Business'; var zip = paramPresent('zip') ? getUrlParameter('zip') : zip; // set utm params to session if (paramPresent('utm_source')) { var utm_source = getUrlParameter('utm_source'); localStorage.setItem('utm_source', utm_source); } else { var utm_source = localStorage.getItem('utm_source') || 'source'; } if (paramPresent('utm_campaign')) { var utm_campaign = getUrlParameter('utm_campaign'); localStorage.setItem('utm_campaign', utm_campaign); } else { var utm_campaign = localStorage.getItem('utm_campaign') || 'campaign'; } if (paramPresent('utm_clickid')) { var utm_clickid = getUrlParameter('utm_clickid'); localStorage.setItem('utm_clickid', utm_clickid); } else { var utm_campaign = localStorage.getItem('utm_campaign') || 'campaign'; } // prefill sidebar form $("input[name='zip']").val(zip); $("input[name='hs_grad_year']").val(hs_grad_year); $("select[name='degree_level']").val(degree_level); $("select[name='area_of_study']").val(study_area); $("select[name='education_level']").val(education_level); function consoleDump() { console.log("Degree Level: " + degree_level + "\nStudy Area: " + study_area + "\nZip: " + zip + "\nHS Grad Year: " + hs_grad_year + "\nEducation Level: " + education_level + "\nAge: " + age + "\nSub 1: " + utm_source + "\nSub2: " + utm_campaign); } consoleDump(); // populate header text var study_area_text = window.subjectName; $('#degree_level_text').html(degree_level); $('#study_area_text').html(study_area_text); $('#city_text').html(city); $('#state_text').html(state); // make the api request var xml_request = { "api_token": "JQo1SNLbqg3JWeUNrHDbZaalN7XDaZPO", "data": { "zip": zip, "area_of_study": study_area, "high_school_graduation_year": hs_grad_year, "education_level": education_level, }, "ip": ip, "local_hour": 12, "placement_id": "Aw6LI4zv-pqqmKbBxPAPQ4yW04iIlw", "sub_1": utm_source, "sub_2": utm_clickid, "sub_3": sub_3, "ua": navigator.userAgent, "url": "https://offers.degreesearch.org/forms/click-cc-ma/index.html", "version": 17 }; var results_i = 1; var json_request = JSON.stringify(xml_request); var apiUrl = "https://education.mediaalpha.com/ads.json"; var ma_xmlhttp = new XMLHttpRequest(); window.ma_complete = false; // render the results ma_xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { window.ma_complete = true; var myObj = JSON.parse(this.responseText); // console.log(myObj); if (myObj.num_ads==0) { $('.noresults').show(); } else { $('.noresults').hide(); } $('.loading').hide(); for (x in myObj.ads) { var result = myObj.ads[x]; var description = result.description; var trimmedDescription = description.substring(0, 120); var clickUrl = "https:" + result.click_url; if (result.large_image_url) { var imgUrl = "https:" + result.large_image_url; } else if (result.medium_image_url) { var imgUrl = "https:" + result.medium_image_url; } else { var imgUrl = "https:" + result.original_image_url; } document.getElementById("combined-results").innerHTML += ""; results_i++; } if (window.qs_complete === true && window.ma_complete === true && window.ds_complete === true) { carouselBuild(); console.log("I built on MA"); } } }; ma_xmlhttp.open("POST", "https://cors-anywhere.herokuapp.com/" + apiUrl, true); ma_xmlhttp.send(json_request); // QS RESULTS var degreeLevelMapping = { "Associate" : "ASSOCIATE", "Bachelor" : "BACHELOR", "Master" : "MASTER", "Doctorate" : "DOCTORAL", "Certificate / Diploma" : "CERTIFICATE" }; var educationLevelMapping = { "Haven't completed High School" : "None", "High School" : "High School Diploma", "Associate" : "Associate's Degree", "Bachelor" : "Bachelor's Degree", "Master" : "Master's Degree", "Doctorate" : "Doctoral Degree" }; window.qs_complete = false; var rootStudyAreaId = "{{ .Page.Params.dms_category_id }}"; //var rootStudyAreaId = 3; var qs_study_area = areaOfInterestMapping[rootStudyAreaId]; var qs_degree_level = degreeLevelMapping[degree_level]; var qs_education_level = educationLevelMapping[education_level]; var webSiteName = "degreesearch.org"; // DS_ListingAPI keys: // var affiliateKey = 112620444; var widgetInstanceKey = 28181110; var authKey = "5cedfc9f579105b511dfeacefa9"; var tag = 204666871; var cfurl = encodeURIComponent(location.protocol + '//' + location.host + location.pathname); // creative url var initiatingurl = encodeURIComponent(location.protocol + '//' + location.host + location.pathname); // landing url var websource = utm_source; var apiUrl = "http://api.searchschoolsnetwork.com/listings?authkey=" + authKey + "&webSiteName=" + webSiteName + "&webPageUri=/&widgetInstanceKey=" + widgetInstanceKey + "&affiliateKey=" + affiliateKey + "&tag=" + tag + "&areaofinterest=" + qs_study_area + "°reeofinterest=" + qs_degree_level + "&educationlevel=" + encodeURIComponent(qs_education_level) + "&highschoolgradyear=" + hs_grad_year + "&zip=" + zip + "&subid=" + sub_3 + "&cfurl=" + cfurl + "&initiatingurl=" + initiatingurl + "&websource=" + websource; var qs_xmlhttp = new XMLHttpRequest(); qs_xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { window.qs_complete = true; var i = 0; var myObj = JSON.parse(this.responseText); // console.log(myObj); if (myObj.vendors) { $('.noresults').hide(); } $('.loading').hide(); for (x in myObj.vendors) { if (i == 4) { break; } var result = myObj.vendors[x]; var clickUrl = ''; // console.log("MaxZip: " + zip); // console.log("Root Study Area: " + rootStudyAreaId + studyArea); if (result.clickThroughUrl != '') { clickUrl = result.clickThroughUrl } else { clickUrl = result.leadSiteUrl }; document.getElementById("combined-results").innerHTML += ""; i++; results_i++; } document.getElementById("qs-pixel").innerHTML = myObj.impressionPixel; if (window.qs_complete === true && window.ma_complete === true && window.ds_complete === true) { carouselBuild(); console.log("I built on QS"); } } }; qs_xmlhttp.open("GET", "https://cors-anywhere.herokuapp.com/" + apiUrl, true); qs_xmlhttp.send(); window.ds_complete = false; // Ping DS JSON and Display Results var ds_xmlhttp = new XMLHttpRequest(); var featuredSchoolsSourceUrl = 'https://degreesearch.org/widgets/school_listings_json?provider_id=' + window.providerId + '&study_area_ids[]=' + window.rootStudyAreaId; if (window.qs_complete === true && window.ma_complete === true) {} ds_xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { window.ds_complete = true; var i = 0; var myObj = JSON.parse(this.responseText); for (x in myObj) { if (i == 4) { break; } var result = myObj[x]; // Trimmed Description var description = result.description; var trimmedDescription = description.substring(0, 150); var clickUrl = 'https://colleges.' + window.siteDomain + '/one/result/' + result.slug + '?provider_id=' + window.providerId + '&sub_id=' + sub_3 + '&creative=' + window.creativeId + '&campaign=' + result.slug; if (description.length > 1) { document.getElementById("combined-results").innerHTML += ""; i++; } } if (window.qs_complete === true && window.ma_complete === true && window.ds_complete === true) { carouselBuild(); console.log("I built on DS"); } } }; ds_xmlhttp.open("GET", featuredSchoolsSourceUrl, true); ds_xmlhttp.send(); }; // Map DMS values to QS values var areaOfInterestMapping = { "1" : "CRIMINAL-JUSTICE-LEGAL-SAFETY", // criminal justice "3" : "BUSINESS", // business "14" : "COMPUTERS-TECHNOLOGY", // information technology "18" : "ART-DESIGN", // art and design "23" : "HEALTH-HEALTHCARE-NURSING", // healthcare "27" : "PSYCHOLOGY-COUNSELING-MENTAL-HEALTH", // psychology "33" : "EDUCATION-TEACHING", // education "40" : "LIBERAL-ARTS", // general "175" : "VOCATIONAL-TRADE", // trade skills "229" : "ENGINEERING-ARCHITECTURE", // science and engineering }; // If these URL params are present, add them to q AND customParams var qs_study_area = 'BUSINESS'; if (paramPresent('study_area_id')) { qs_study_area = areaOfInterestMapping[getUrlParameter('study_area_id')] } else if (paramPresent('area_of_study')) { qs_study_area = areaOfInterestMapping[getUrlParameter('area_of_study')] }