Connect your Customer login form to Referral Dashboard

Connect your Customer login form to Referral Dashboard

Here is how to connect your customer login (or signup) form to their referral dashboard. This will pass the customer details into your referral campaign as a new customer invite if customer is not already invited to your campaign.

You need to make few updates to our script code before making it live on your website. You need to change the Email field name, Name field name, your lead form name, your license key and your campaign id. Instructions are as follows for making these changes.

1. FORM NAME
Right click on your lead form and choose "Inspect element" to find your Form HTML. Then look for "name=" in the form tag. If "name=" is not available, then look for "id=". If that's not available either then look for "class=" as shown below.

Depending on what you have, you can use one of the three options. Copy, make the required replacement and then replace 'form-identifier' on the main script code with the selection.

//Use the following as your 'FORM-IDENTIFIER' if your form has name. Replace the "form-name" below with your actual form name. Keep the quotes ("").
'form[name="form-name"]'

//Use the following as your 'FORM-IDENTIFIER' if your form has no name but has an ID. Replace the form-id below with your actual form id. Keep the #.
'#form-id'

//Use the following as your 'FORM-IDENTIFIER' if your form has no name and no ID but has a css class name. Replace the form-class-name below with your actual form class name. Keep the dot (.).
'.form-class-name'

In our example we are using form name as the tag: name="gform_1"

Copy and paste the form name (or id or class) between the quotes, so in this example you would need to copy gform_1 and replace it into correct script line as identified above. Then copy it and replace it in the script code below to replace our default 'form-identifier'

Use the "Inspect element" feature in Firefox or Chrome to find your form field names.

2. NAME FIELD
Place your cursor into the name field of your lead form, right click and choose "Inspect element".
Look for "name=" as shown in the above screenshot. Copy and paste the field name between the quotes, so in this example you would need to copy et_pb_contact_your_name_0 and paste it into the script below to replace our default "name". Do not delete the quotes in our script.

3. EMAIL FIELD
Place your cursor into the email field of your lead form, right click and choose "Inspect element".

Look for "name=" as shown in the above screenshot. Copy and paste the field name between the quotes, so in this example you would need to copy et_pb_contact_your_email_0 and paste it into the script below to replace our default "useremail_field_name". Do not delete the quotes in our script.

4. CHANGE LICENSE KEY AND CAMPAIGN ID

Finally, you need to change the license key and the campaign ID in our script as shown in the below screenshot.

You can find you License Key and Campaign ID by logging into your iRefer account and going to your campaign settings.

Then click on API guide > Overview as shown below.

 

Copy and paste this script along with the above changes into the same page as your form or login button.

<script>    

if("undefined"==typeof jQuery){var script=document.createElement("SCRIPT");script.src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js",script.type="text/javascript",document.getElementsByTagName("head")[0].appendChild(script)}


jQuery( document ).ready(function( $ ) {


   //Change form name here by replacing 'FORM-IDENTIFIER' keyword below with your form identifier value as mentioned above.
   $('FORM-IDENTIFIER').on("submit",function(e) {      

   //Get UserEmail - change email field name here
   var user_email = document.getElementsByName("useremail_field_name")[0].value;

   //Get UserName - change name field name here
   var user_name = document.getElementsByName("username_field_name")[0].value;

   //Replace with your license key
   var license_key = 'W4qLb411508c792cf7e89dfed936a2d2';

   //Replace with your campaign id
   var campaign_id = '2650';


   var domain_name = window.location.hostname;
   if (domain_name.startsWith("www.")){
      domain_name = domain_name.substring(4);
   }
   var days = 365;
   var date = new Date();
   date.setTime(date.getTime() + (days*24*60*60*1000));
   var expires = "; expires=" + date.toUTCString();
   
   //Register Referral
   document.cookie = "vsu_ref_email=" + user_email + expires + "; domain=." + domain_name + "; path=/";
   //Comment line below if name is not being used
   document.cookie = "vsu_ref_name=" + user_name + expires + "; domain=." + domain_name + "; path=/";

   if(user_email != '' && user_email != null){
    var api_url = "https://api.irefer.io/v2.0/" + license_key + "/customer?campaign_id=" + campaign_id + "&email=" + user_email + "&name=" + user_name + "";


    console.log(api_url);
    var xhr = new XMLHttpRequest();
    xhr.open("GET", api_url, false);
    xhr.send();
    json_result = xhr.responseText;

    if(xhr.status == 200){
        console.log('api call success');
        console.log(json_result);    
    } 
    else {
        console.log('api call failed');
        console.log(xhr.status);   
        console.log(xhr.statusText);   
        console.log(xhr.responseText);   
    }
   }


   });

});


</script>

You can remove or comment out the name section of Get User-name and name cookies, if you are not using user name (prefix each line with //).


Did this help answer your question?

thumbs up
thumbs down

Thanks for the feedback! 🙏🏽