User Tools

Site Tools


adminrecordemailconversion

How can I record email conversion to split test ?

Get Email from QueryString

Suppose you have url like this : http://www.example.com/?email=abc@example.com

function getQueryStrings() { 
  var assoc  = {};
  var decode = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); };
  var queryString = location.search.substring(1); 
  var keyValues = queryString.split('&'); 
 
  for(var i in keyValues) { 
    var key = keyValues[i].split('=');
    if (key.length > 1) {
      assoc[decode(key[0])] = decode(key[1]);
    }
  } 
 
  return assoc; 
} 
 
var param= getQueryStrings();
var _email = param["email"]; 

Now, You can grab email from either queryString and send data to cbsplit CallBack recordEmailConversion() JavaScript Function Call is promised based:

recordEmailConversion(_email).then(function() {
      // continue to your next task
});

Incase you are using HTML <form> , you could do the follow,

[1] Add onSubmit Event to the Form

<form onsubmit="return recordEmailConversion()" >
</form>

[2] Code for the CallBack “recordEmailConversion”

<script>
    function emailConversion(){
      var _email = document.querySelector('#inf_field_Email').value;
      recordEmailConversion(_email).then(function() {
        // redirect to next page
        return true;
      });
      return true;
    }
</script>
adminrecordemailconversion.txt · Last modified: 2022/10/07 05:24 by stephan