API registration with Affiliate ID

Created: 12/27/2016 | Updated: 8/24/2018 | Status: Published

Registration form - Getting the affiliate id from a landing page URL and sending it to the API

 
When sending affiliate id to the api you need to use the next parameter structure:

landing={"a_aid":"35135", "serial":"camp1"}
 
This parameter must be a string so you can send it via POST method to the Tradesmarter API when sending all From fields.
You have 2 options \ ways to work with the affiliate ID:
 
1.     You can hardcore it in the html of the affiliate landing page.
 
2.     You can add a short script that will work dynamically, the script will :
 
A.    get the affiliate parameter used in the affiliate landing page
B.     plant it in the landing page registration form
C.     when the user will press on the form submit button the parameter will be pass as well.

Here is an example code that shows how to retract the affiliate ID from the affiliate landing page url:

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];
                                    }
                        }
            } 

            //And this is how you can use this function assuming the URL is,
            //http://wonderful-binary.com/?affiliate=123456&oterparam=5

 
            var a_aid = getUrlParameter('affiliate');
            var other_parameter = getUrlParameter('oterparam');

 
Next thing you want to do is to save the parameter value into the registration form you built:

var api_aff = "landing={'a_aid':'"+ a_aid +"', 'serial':'camp1'}" //note that you do not need the "serial" parameter so just place any text there
            $('#landing').val(api_aff); //assuming the input id is "landing"
 
Once the user will submit the form the a_aid parameter value will be sent to the API as well.
 
 
Lets see an example of the from:
 
<form class="form small-form cf" id="quick-registration-form" method="post" action="https://trading.tradesmarter.com/index/sign-up"  onsubmit="return submit_form(this);" target="_top">
                        <input type="hidden" name="landing" id="landing" value="">

 
As you can see we set the "landing" input to be hidden from the user and using Jquery selector we planting the parameter value that we have extracted from the page url.