How to collect lead data from HTML forms

In the next guide, we will learn how to pull to AnyTrack the details of the leads like Name, Email, or phone number.

This is a really good hack, as the more values you send from AnyTrack to Facebook, the higher the match rate that your event will get. Also, sending facebook the events with the details like Email will help for the advanced matching. 

Please note: Trigger custom events require HTML and JavaScript skills. Please contact a web developer if you don’t feel comfortable doing that yourself.

Requirements:

  • You should be familiar with HTML and have some basic knowledge of JavaScript
  • The AnyTrack Base Code must be on the head section of your website

How to start collecting leads value in the javascript event code?

  1. Open your form HTML
  2. Search for the form element (search for "<form")
  3. Paste this part after the action tag:
    onsubmit="AnyTrack('trigger','Lead',{firstName:this.X.value,lastName:this.X.value,phone:this.X.value,email:this.X.value })"
  4. Here is how it should look
    <form action="/action_page.php" onsubmit="AnyTrack('trigger','Lead',
    {firstName:this.X.value,lastName:this.X.value,
    phone:this.X.value,email:this.X.value })">
  5. The last part is to substitute the X's with the names that appear in the HTML input
<!DOCTYPE html>
<html>
   <body>
      <form action="/action_page.php" onsubmit="AnyTrack('trigger','Lead',
{firstName:this.X.value,lastName:this.X.value,
phone:this.X.value,email:this.X.value })">
         <label for="fname">First name:</label>
         <br>
         <input type="text" name="fname">
         <br>
         <label for="lname">Last name:</label>
         <br>
         <input type="text" name="lname">
         <br>
         <label for="phone">phone number:</label>
         <br>
         <input type="text" name="phoneNumber">
         <br>
         <label for="email">Email:</label>
         <br>
         <input type="text" name="email">
         <br>
         <br>
         <input type="submit" value="Submit">
      </form>
   </body>
</html>

The Result

Forms can have different tagging and naming syntaxes. Please check with your form provider in case of friction.

<!DOCTYPE html>
<html>
   <body>
      <form action="/action_page.php" onsubmit="AnyTrack('trigger','Lead',
{firstName:this.fname.value,lastName:this.lname.value,
phone:this.phoneNumber.value,email:this.email.value })">
         <label for="fname">First name:</label>
         <br>
         <input type="text" name="fname">
         <br>
         <label for="lname">Last name:</label>
         <br>
         <input type="text" name="lname">
         <br>
         <label for="phone">phone number:</label>
         <br>
         <input type="text" name="phoneNumber">
         <br>
         <label for="email">Email:</label>
         <br>
         <input type="text" name="email">
         <br>
         <br>
         <input type="submit" value="Submit">
      </form>
   </body>
</html>

 

In case you collect the lead's full name, use the following snippet

onsubmit="AnyTrack('trigger','Lead',{name:this.X.value,
phone:this.X.value,email:this.X.value })"

 

That's it! 🎉


Need support?

Questions? Problems? Need more info? Contact Anytrack Support for assistance!

Click here