Solved

Facebook Social Login: Fill form fields with details from Facebook


Hello,

I wanted to know if it’s possible for a form on an Unbounce page to be filled using the information of one’s Facebook profile?

Thanks!

icon

Best answer by Johnny_Opao 23 May 2014, 22:36

View original

36 replies

Userlevel 7
Badge +3

Hi @jhage,

First, welcome to the community.

What you are trying to achieve is pretty complicated and unfortunately would require extensive custom development to make it all work.

Hopefully, the following should point you in the right direction:

In the past I’ve used Auth0 to fill out an Unbounce form with data from LinkedIn. They support pretty much any login platform, including Facebook, so I think that should be your first step.

After that it’s a matter of figuring out your exact flow, which you’ve done for the most part and coding it.

One of the ways to do the Facebook to CRM push is through a Zapier webhook. Once Facebook returns the necessary data, you would have to fire the data to Zapier.

Best,
Hristian

I’m the ultimate newbie here. I’m not a programmer and I’m new to the Unbounce platform. I’m trying to replicate functionality from my current landing page provider that is somewhat complex and includes a custom Facebook Login button. Despite all the amazing code shown here, I can’t figure out how to put all the pieces together to achieve what I’m looking for.

Example Page

The gist:

  1. A lightbox button on landing page

  2. Lightbox opens to display 2 options: A custom Facebook login button and a text link to sign-up via email instead.

3a. Custom FB button (upon approval by user) submits leads 1st name & email from FB to Zapier

3b. Text link opens new lightbox to enter 1st name and email address and submits to Zapier on submit

  1. User is re-directed to a “full” squeeze page requesting more information. First name and email address are shown but locked - user cannot change (see step 5)

  2. Upon Squeeze page submit, all user data is sent to Zapier. The additional information is appended to the previous submission (keyed to the email address provided).

I’ve been able create the Facebook App and have successfully setup the default buttons to generate a re-direct to a new page; however, I can’t figure out how to A) use a custom button to do this and B) how to submit the user’s data to my CRM. I don’t want a visible form in the 1st lightbox so how do I collect the data from facebook and forward it to Zapier?

Can anyone offer some help? I know it’s asking a lot! 😃

Userlevel 3

Hey there!

Sorry about that. There’s a small bit of code that i’ve now added that should fix this issue.

Grab the updated script and give it another go!

<script>
  /**
    * Do not remove this section; it allows our team to troubleshoot and track feature adoption. 
    * TS:0002-13-010
  */

  function setFormValues(response) {
    
    // ***UPDATE FIELDS BELOW***
    //Adjust field IDs on the left with the field IDs on your form
    $('#email').val(response.email);
    $('#name').val(response.name);
      
    //Uncomment the lines below if you require the additional data
      
    //$('#firstNameField').val(response.first_name);
    //$('#lastNameField').val(response.last_name);
    //$('#linkField').val(response.link);
    //$('#genderField').val(response.gender);
    
    //The form willl submit by default. To disable this comment out the line below
    document.querySelector('.lp-pom-form button').click()
  }
  

  function statusChangeCallback(response) {
    if (response.status === 'connected') {
      fillForm();
    } else if (response.status === 'not_authorized') {
      triggerLogin();
    } else {
      triggerLogin();
    }
  }
  
  // Show Login Window
  function triggerLogin() {
    
   FB.login(function(response) {
     if (response.status === 'connected') {
         fillForm(); 
        }
   }, {scope: 'public_profile,email'}); 
  }
  
  // Called when your Facebook button is clicked
  function checkLoginState() {
    FB.getLoginStatus(function(response) {
      statusChangeCallback(response);
    });
  }

  // Update appId below to reflect your Facebook Apps ID
  window.fbAsyncInit = function() {
  FB.init({
    appId      : '552705011513631',
    cookie     : true, 
    xfbml      : true, 
    version    : 'v2.0',
    status     : true
  });
  };

  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
  
  function fillForm() {
  
  // Update the variable below with the fields you wish to obtain
  // See the full list of fields here:
  // https://developers.facebook.com/docs/graph-api/reference/user
    var requestedFields = {
      fields: 'name, first_name, last_name, email'
    };
    
    FB.api('/me', requestedFields, function(response) {
      setFormValues(response);
    });
  }
</script>

Thanks!

1 - Javascript is before body end tag ?
2- Button url Pass thought url parameter ?
here my page : http://unbouncepages.com/browzin/ not working

Userlevel 3

Hey Maxime

It looks like you got this working now. Did you run into any other issues? I just tested out your page and it worked just fine. If your still having issues please detail them further.

Everything in now find, the template that i bought on time forest is include a javascript that block the Facebook connect, now it’s just perfect

Hello Johnny. I have been wrestling with this for days now. Everyhting works, except the crucial fact that popup blockers still block the facebook login dialog.

Check it out at: www.getqounter.com

Userlevel 3

Hey Augusto

Are you still seeing this issue?

I visited the page and it seems to work just fine. If you are still running into issues shoot a email to support@unbounce.com and address it to me. Let me know what browsers/popup blocks are affecting it and i’ll see if I can give any helpful tips

Hello Johhny. Yes we were still seeing this issue so we went ahead and just programmed our own button with the custom HTML control. If we called the facebook login on the javascript click event of our button the problem went away.

Hi there, I’m unable to get this going. My page is http://unbouncepages.com/facebook-connect-test2/

any tips?

Thanks!

Hey Pedro, 
If you’re still running into issues with this, I would reach out to our support team directly to see if we can lend some insights. Feel free to reach out via email (support@unbounce.com) or by giving us a call at 1.888.515.9161.

Ive got a ticket into support, but just curious if anyone has successfully got this to work on mobile? Works fine on desktop, but when I add the button to mobile nothing happens when you click the button. Ive got the Facebook App setup since I am not hosting on Unbouncepages as well. http://guide.viviscal.com/healthy-hair-guide/

Hello Guys,

I have an other question about this function. It worked out pretty well but we didn’t managed to get it filled in dutch language. 

This is the script we used: /topics/filling_in_form_fields_with_info_from_facebook?topic-reply-list%5Bsettings%5D%5Bfilter_by%5D=all

I have customised a couple of things but it isn’t working:

(function(d, s, id) {

    var js, fjs = d.getElementsByTagName(s)[0];

    if (d.getElementById(id)) return;

    js = d.createElement(s); js.id = id;

    js.src = “//connect.facebook.net/nl_NL/sdk.js”;

    fjs.parentNode.insertBefore(js, fjs);

  }(document, ‘script’, ‘facebook-jssdk’));

  

  At first it was:

  (function(d, s, id) {

    var js, fjs = d.getElementsByTagName(s)[0];

    if (d.getElementById(id)) return;

    js = d.createElement(s); js.id = id;

    js.src = “//connect.facebook.net/us_US/sdk.js”;

    fjs.parentNode.insertBefore(js, fjs);

  }(document, ‘script’, ‘facebook-jssdk’));

  

I customised it this way because Facebook told us so:

  https://developers.facebook.com/docs/internationalization

  

It should work but it doesn’t, we still get our responds in English. We want to autofill the data in dutch language. Do you know were it went wrong? The url of the Facebookpage were the autofill in button is running is: https://www.facebook.com/uwvakmannen.nl/app/1083190695053293/

 

I hope you people can help us out.

With kind regards,

Nick Nikkels

Hey Kurtis, how do I open up the scope to include  user_location and user_hometown? I need to get auto populating address on my form. I’m a designer, not a dev! Thanks, J

Hey all, this is great. However, I’m trying to pull a phone number via Facebook. Looking at https://developers.facebook.com/docs/graph-api/reference/user I can’t see a phone number field, am I right to think I can’t because FB keep phone numbers private?

Also, is there a way/code to pull things like ‘list’ categories from FB?

Hey James!

It’s been a while since I looked at this, but hopefully the Unbounce people will pop in here to help.

I didn’t end up using the social login for forms.

Best of luck!

Kurtis

I couldn’t get anymore info to pull but am seeing positive results from my FB auto login variant tests.

Userlevel 3

Hey Michael - We don’t have a built in solution at the moment. However I put together a solution that should work in filling your forms with basic Facebook information. I’d be happy if you could give it a try and let me know if it works for your use case.

Add the script below to your ‘javascript’ box in the page builder

https://gist.github.com/johnnyopao/0f…

Be sure to update the section in the code labelled “UPDATE FIELDS BELOW” with your own fields IDs

To find the ID of your Unbounce fields open up the form builder, select a field, and look at the grey text below your field label. The grey value is the ID for that field.

Once your form fields are configured drop a button on your page and set its URL to:

javascript:checkLoginState();

This will get the button working under the domain ‘unbouncepages.com’. However if you wish to use this under your own domain you’ll need to configure some settings within Facebook itself.

Keep in mind you’ll only need to follow the instructions below for the first time you setup your Facebook ‘app’.

One time setup: setting up your own Facebook form app

Head over to https://developers.facebook.com/ and enable access to your developer account.

At the top menu select ‘Apps > Create a new app’

Set your apps display name and choose a category. Once that’s done select ‘Settings’ from the left menu.

Set the ‘Contact Email’ and select “Add Platform”. Choose ‘Website’ and define your domain URL.

From the left menu select ‘Status & Review’. Toggle the switch to turn your app ‘Live’

Your app is now configured! The last step is to obtain your App ID. Select ‘Dashboard’ from the menu and copy your ‘App ID’

Head back over to the Facebook form fill script and replace the App ID with your own:

That’s it! Remember this configuration only needs to be done once, afterwards you simply need to paste the updated script on your page and set your button to javascript:checkLoginState();

Excellent! Thanks for the step-by-step, got it working on my first lander.

@Johnny_Opao Thanks so much for the step-by-step instructions! Got the button working on our unbouncepages.com/samwise, but as you mentioned, it no longer works at go.samwiseapp.com.

Could you elaborate a bit more on the Facebook settings we need to change to get it up and running again?

Thanks in advance!

Userlevel 7
Badge +4

Hey Johnny! Just me, or is this not working for mobile? 😭

Hi Stefano. It worked fine for me. We did tests on several different mobile devices.

Hi Lisa, I’m not an specialist, but what I did - and it did work for me - was:

Enter the link https://developers.facebook.com/, on the upper right side, click on My Apps, and find the one you just created.

Then, click settings >> basic >> and in the field “App Domain” use yours (samwiseapp.com).
Below, at the “Website” block, include your page root URL (http://go.samwiseapp.com).

Hope it works for you too.

Reply