Created
November 21, 2019 19:25
-
-
Save westonwatson/8e64f61ec88a76a7a1dbaf418f393d38 to your computer and use it in GitHub Desktop.
Parse and Extract several Studio Session Storage values and use them for an iframe/pixel URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Parse and Extract values from text like "key=HELLO&value=WORLD&test=OK" | |
function getUriParameter(UriString, targetKey) { | |
var sPageURL = UriString; | |
var sURLVariables = sPageURL.split('&'); | |
for (var i = 0; i < sURLVariables.length; i++) | |
{ | |
var sParameterName = sURLVariables[i].split('='); | |
if (sParameterName[0] == targetKey) | |
{ | |
return sParameterName[1]; | |
} | |
} | |
} | |
//Create and attach an iFrame tag to the body | |
function addIframe(src) { | |
var s = document.createElement( 'iframe' ); | |
s.setAttribute( 'src', src ); | |
s.style.width=1; | |
s.style.height=1; | |
document.body.appendChild(s); | |
} | |
//grab studio LEAD_ID from JSON encoded session storage variable | |
var lead_id = JSON.parse(window.sessionStorage.getItem('crm.session_completed_fields'))['lead_id'] | |
//grab the C1 URI value (it's passed in via the URL and stored in session storage) | |
var c1 = getUriParameter(window.sessionStorage.getItem('crm.session_params'), "c1") | |
//create the iframe src/link using the variables above | |
var iframeSrc = 'https://c.verifyconv.com/pixel?cid=25857&refid=' + lead_id + '&clickid=' + c1; | |
//create the iframe (using the link/src we just created) | |
addIframe(iframeSrc); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment