Generating Leads and Tracking ROAS with Custom Form

Hey everyone!

I’m having issues finishing up the marketing integrations for a completely custom price configurator for our company. Currently the pricing configurator is deployed and conversion event tracking is working for Google Tag Manager/Google Analytics/Google Ads/Facebook.

My questions are:
1) What API do I use to enter the form data into the HubSpot CRM?
2) What do I need to do for HubSpot to track ROAS from these leads generated from ads? (I’d like to clarify that I can NOT use HubSpot Forms and I do not want information about lead ads for Facebook and Google. This is for our custom configurator form).

For the first part about the API, I see this page here is for submitting data to a form https://legacydocs.hubspot.com/docs/methods/forms/forms_overview?_ga=2.223379995.1005207101.1644243643-1276624668.1642615444 which looks ideal, but then at the top of this page https://legacydocs.hubspot.com/docs/methods/forms/submit_form_v3_authentication it says, “This endpoint should not be used with non-HubSpot forms.” which conflicts with what the page before it says. (I cannot use native HubSpot forms and our site is a SPA so we can’t use the HTML form tracking options, it has to be an API call). Can I use this API endpoint to pass form lead data to HubSpot?

For the second part, will sending that form data as a lead in the HubSpot CRM + Google’s enhanced matching be enough for HubSpot to calculate ROAS from the Google Ads? If not, what information needs to be passed in the API call? Is there something specific Facebook needs as well?

Thanks in advance for any help or info!!!

Hey @TCarp21, thank you for posting in our Community!@

You might want to explore the Contacts API, specifically the endpoint for creating or updating contacts. This endpoint allows you to pass form data directly to HubSpot CRM. Here’s the link to the Contacts API documentation: HubSpot Contacts API.

You need to ensure that the leads generated from Google Ads are properly tagged or attributed within Google Ads itself. This usually involves utilizing Google’s tracking parameters (like gclid) to tie leads back to specific ad clicks.

To our top experts, @Jigar_Thakker, @RSchweighart, and @JyoteshG do you have any recommendations for @TCarp21?

Thank you,

Pam

Hey!

Thank you a ton for reccomending me to the Contacts API! That looks like it matches what I need. I found this page https://developers.hubspot.com/docs/api/crm/contacts?_gl=1*ww0ljp*_ga*MTM0NjQyNTgxNy4xNzEwNDI3MTY2*_ga_LXTM6CQ0XK*MTcxMDk2OTY5OS42LjEuMTcxMDk3MDQ2NS42MC4wLjA. which allows me to test API calls and I’ve setup a private app to get an oAuth key.
When I try to run some test API calls, I get back some errors about association TypeId and id params. Looks like TypeId needs 0 as the other option of 1 is reserved for companies and at the time of lead creation we do not know if it is a company or a person. Issue is, I don’t know what to put down for id as I’m trying to create a contact… but it wants to know the id of the contact I’m creating? I’ve tried random numbers and I keep getting the same error code:

HTTP 400

{
“status”: “error”,
“message”: “Invalid association spec: AssociationSpec{associationCategory=HUBSPOT_DEFINED, associationTypeId=0}”,
“correlationId”: “940d50f8-791c-416b-8490-cf2a0aa33067”,
“category”: “VALIDATION_ERROR”
}
What do I need to put in the id field for this to work?
Also to clarify futher, do I need to make a Deal API call? All I’m trying to do is log this lead in the CRM for our sales people to contact and ultimately measure ROAS for ads. I know there is endless complexity and configuration, but all I’m trying to do is those two things. (And yes we have it all setup to pass the info and gclid so that’s not an issue, just trying to understand your system).

Thank you again for taking the time to help me, it’s greatly apprecaited!

Hi @TCarp21,

Here’s some more information regarding the association type ids:

A contact to deal has a typeid of ‘4’.

That said, I don’t think you need this information if you don’t want to associate the contact with another object, so you could consider removing it and only passing any additional property parameters.

Best,

Ryan Schweighart

Whole Hart Impact, LLC

whimpact.co

I help businesses with HubSpot and Zapier.

Thank you for the additional insight!
To recap, I have successfully setup the API integration into the Contacts section of the HubSpot CRM and that is all tested and working. If anyone runs accross this post in the future and wants detailed steps on how to achieve this, skip to the bottom section after my quetsion about ROAS tracking.

So we paid $900/month for the professional ads tier and we still cannot track ROAS from Google Search Ads. Yes, I know lead ads will track ROAS, but we are not running those types of ads. So far I’ve tried:

  • Contacting your support multiple times and they give me the run around every single time (which is insane given the cost of this service).
  • Searching for any related documentation on how to send the Google Analytics ID (gclid) into your CRM to track ROAS… but I cannot for the life of me find any relevant info.

So my final question is: What do I need to do for HubSpot to track ROAS from these leads generated from Google Search ads or Facebook ads? (I’d like to clarify again that I can NOT use HubSpot Forms and I do not want information about lead ads for Facebook and Google. This is for our custom configurator form. I can also easily grab the glclid from our custom quote configurator, but there is no documentation on where to send it in your system or what field to attach it to for contacts).
Again, thank you for your time and insight!

==== How To Setup Contacts API ====

  1. Create a private app and get the OAuth key.

  2. Ignore all the documentation on the Hubspot website. As pointed out by RSchweighart, the API test widgets force you to use required fields that are not actually required.

  3. If you’re doing this from a custom HTML form on your website, you’ll need to setup some sort of back end Node.js solution to actually hit the contacts api. For example, we used a basic AWS lamda with this code on the front end site:
    const sendLeadDataToHubSpot: Promise<void>[] = [

         // Create contact in HubSpot
    
         axios.post('https://your-lamda-url-here.lambda-url.us-west-2.on.aws', {
    
           email: email.value,
    
           firstname: firstName.value,
    
           lastname: lastName.value,
    
         }),
    
       ];
    

And this code on the back end:

exports.handler = async (event, context, callback) => {

try {

  const reqBody = JSON.parse(event.body);

  const accessToken = "your-access-token-here";

  const contactData = {

    properties: {

      email: reqBody.email,

      firstname: reqBody.firstname,

      lastname: reqBody.lastname,
      // not required, but this marks it as a lead

      lifecyclestage: "marketingqualifiedlead",

    }

  };

  const axiosResponse = await axios.post(

    "https://api.hubspot.com/crm/v3/objects/contacts",

    contactData,

    {

      headers: {

        Authorization: \`Bearer ${accessToken}\`,

        "Content-Type": "application/json",

      },

    }

  );

  console.log("Contact Created: ", axiosResponse.data);

  const successResponse = {

    statusCode: 200,

    body: JSON.stringify({ message: "Success!" }),

  };

  callback(null, successResponse);

} catch (err) {

  console.log("ERROR: ", err);

  const errorResponse = {

    statusCode: 500,

    body: err,

  };

  callback(null, errorResponse);

}

};