Prefilling User Details

Documentation for Prefilling User Details on Gleam

Sometimes you may want to prefill user details within the Gleam widget to prevent users from having to enter details twice. This may be if a user is already logged into your website, or if you're redirecting users to a Gleam widget after completing another form first.

Applications that support Prefilling:

Javascript API

The first way you can prefill data is by including some extra Javascript on your page. This should be included after your embed code.

<script>
  window.Gleam = window.Gleam || [];
  Gleam.push(['name', 'John Doe']);
  Gleam.push(['email', 'john@doe.com']);
</script>

The main things you can pass are:

  • Name
  • Email
  • DOB

It will also match up with any additional Custom Fields that you have setup.

URL Parameters

The second way you can prefill is to pass parameters to the URL. This will only work if you send users to the Gleam Hosted Landing Page or use the iFrame embed option.

You must also encode the parameters & parameter names.

?name=John%20Doe&email=john%40doe.com

You can see how this would work sending users to our demo competition with Prefilling active:

https://gleam.io/iR0GQ/gleam-demo-competition?name=John%20Doe&email=john%40doe.com

Again this method supports:

  • Name
  • Email
  • DOB
  • Custom Fields (note - Custom Fields need to match their respective names under the 'User Details' tab and are case sensitive. E.g. Gleam.push(['Phone', decodeURIComponent(paramPhone[1])]);)

URL Parameters on Embedded Campaigns

This additional script will allow you to grab parameters from your URL and pass it to prefill the Gleam embedded widget.

<!-- Start Gleam prefill code - https://gleam.io/docs/advanced/prefill -->
<script>
  (function () {
    let fieldsToPass = ['name', 'email', 'utm_source', 'utm_medium', 'utm_campaign'];

    window.Gleam = window.Gleam || [];
    let toSend = []
    fieldsToPass.forEach(function(field) {
      let match = location.search.match(new RegExp("[?&]" + field + "=([^?&#]+)"));
      if(match) {
        toSend.push([field, decodeURIComponent(match[1])])
      }
    })
    if(toSend.length > 0) {
      Gleam.push(toSend);
    }
  })();
</script>
<!-- End Gleam prefill code -->