Mon Aug 06 2018
Copied to clipboard! Copy reply
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
get_ip(function(ip_data){
			var ip = ip_data.ipaddress.split(',')[0];

			get_geo_data(ip, function(geo_response){
				var geo_data_array = geo_response.split('|');
				var geo_data = {
					country: geo_data_array[0],
					state: geo_data_array[1],
					city: geo_data_array[2],
					zip: geo_data_array[3]
				}

				ee_form_data['Country'] = geo_data.country;
				ee_form_data['State'] = geo_data.state;
			});
		});


		function get_ip(callback){
			var callback_name = 'ip_data_jsonp_callback' + Date.now();
			window[callback_name] = callback;
			var script_tag = document.createElement('script');
			script_tag.src = 'https://www.rosettastone.com/product-activation/?p_p_id=responsysservicesportlet_WAR_responsysservicesportlet&p_p_lifecycle=2&callback='+callback_name;
			document.body.appendChild(script_tag);
		}


		function get_geo_data(ip, callback){
			var request = new XMLHttpRequest();
			var stg_or_not = (/\.stg\./i).test(window.location.href) ? 'stg.':''
			var url = 'https://www.'+stg_or_not+'rosettastone.com/institutional/web/us-institution/?p_p_id=rosettaservices_WAR_institutionalrosettaservicesportlet&p_p_lifecycle=2&p_p_resource_id=GeoIP_request&redirect2mobile=disabled&ipaddr='+ip;
			request.open('GET', url, true);

			request.onload = function() {
				if(request.status>=200 && request.status<400){
					// Success!
					var resp = request.responseText;
					callback(resp);
				}
				else{
					// We reached our target server, but it returned an error
					window.console && console.log('E&E IP Geo Data lookup failed. We reached our target server, but it returned an error.');
				}
			};
			request.onerror = function() {
				// There was a connection error of some sort
				window.console && console.log('E&E IP Geo Data lookup failed. There was a connection error.');
			};
			request.send();
		}