(function () { var getParams = function (url) { var params = {}; var parser = document.createElement('a'); parser.href = url; var query = parser.search.substring(1); var vars = query.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); params[pair[0]] = decodeURIComponent(pair[1]); } return params; }; var integrate = function (){ console.log('integrate'); // url of the sript var scriptUrl = document.getElementById('uwm_kia_integration'); // get lineup key var dealerCode = getParameterByName('d', scriptUrl.src); // get model var model = getParameterByName( 'm' ); // get model var salesdemo = getParameterByName( 'salesdemo' ); var params = getParams(window.location.href); var sd_campaign = (Object.keys(params).length && params.sd_campaign != undefined) ? params.sd_campaign : ""; if ( 'on' == salesdemo ) { var sString = '&salesdemo=on'; } else { var sString = ''; } // get intro status var introInfo = getParameterByName('intro', scriptUrl.src); // create iframe url var iframeUrl = '//uwmedia.us/cm_kia/front/?d=' + dealerCode + '&integration=&m=' + model +'&intro='+introInfo + "&sd_campaign=" + sd_campaign ; // main container element var uwmIframeContainer = document.getElementById('uwm_kia'); // create pym script and add it to the dom var pymScript = document.createElement('script'); pymScript.async = true; pymScript.src = '//uwmedia.us/cm_kia/js/global/front/pym.js'; // setup iframe uwmIframeContainer.innerHTML = "
"; // append pym script to main container uwmIframeContainer.appendChild( pymScript ); console.log('scriptUrl : ',scriptUrl,'dealerCode : ',dealerCode,'model : ',model,'salesdemo : ',salesdemo,'sString : ',sString,'sString : ',sString,'introInfo : ',introInfo,'iframeUrl : ',iframeUrl,'uwmIframeContainer : ',uwmIframeContainer); /** * Get param from URL by name * * @param name of the param you are looking for * @param url to look for the param in by name * * @return String value of the param found */ function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); } console.log('integrated'); } integrate(); })();