Leads showing up as Direct Traffic when they aren't, via Forms API


#1

We have potential clients land on our Wordpress site, where the the utm_campaign/utm_source params are on the url. Then we sent them to our webapp once they enter their name/email. The webapp then uses the Form API to submit their name/email to Hubspot, but everyone is showing up as Direct Traffic, as opposed to part of our campaigns.

We’re passing the hutk cookie as described on https://developers.hubspot.com/docs/methods/forms/submit_form but it has not added any information.

Here’s what the POST body looks like when submitting the form through the Form API:
{
“email”: "test@test.com",
“firstname”: “Tester”,
“hs_context”:
{
“hutk”: “0f9abb06328e07b16e16f3571b30c31e”,
“pageUrl”: “http://test.com/signup”,
“pageName”: “My Page”,
“redirectUrl”: “https://test.com/done”,
“ipAddress”: “127.0.0.1”
}
}


#2

Hi @robin_izea

Are you sending the data as JSON or as form-encoded data? You would need to use form-encoded data for this.

If you are sending the data as form-encoded, do you have an example of the form-encoded data you’re sending? There might be an issue converting that JSON into the form data.


#3

Yes, it is being form-encoded. Here is what the data looks like once form-encoded:

email=test%40test.com&firstname=Tester&hs_context=%7B%22hutk%22%3D%3E%220f9abb06328e07b16e16f3571b30c31e%22%2C+%22pageUrl%22%3D%3E%22http%3A%2F%2Ftest.com%2Fsignup%22%2C+%22pageName%22%3D%3E%22My+Page%22%2C+%22redirectUrl%22%3D%3E%22https%3A%2F%2Ftest.com%2Fdone%22%2C+%22ipAddress%22%3D%3E%22127.0.0.1%22%7D


#4

Is there anything else we can try on our end to get the Original Source to show up as something other than Direct Traffic?

I see here that it should even pick up things like search terms that landed the user on our site, but it isn’t.

Here’s another example of a flow that isn’t getting the Original Source set properly:

  • Brand new browser session, with all cookies cleared
  • Search in Google for our sign up page, click link to get to our Wordpress site
  • Our Wordpress site has your tracking JS snippet, which I assume is what then sets the ‘hubspotutk’ cookie (I’ve confirmed the cookie is now set)
  • Filling out our html form on Wordpress lands the user on our webapp to complete the sign up process
  • On the webapp, we submit what is in the above post via your Form API, including the ‘hubspotutk’ cookie
  • On the Hubspot Form dashboard, there is now a new entry for that name/email, but their Original Source is incorrectly listed as Direct Traffic

#5

@robin_izea the hs_context value looks incorrect. If I decode the value you have I get:

{“hutk”=>“0f9abb06328e07b16e16f3571b30c31e”,+“pageUrl”=>“http://test.com/signup",+“pageName”=>“My+Page”,+“redirectUrl”=>“https://test.com/done”,+“ipAddress”=>"127.0.0.1”}

which isn’t valid JSON. For those same values, you’d need to have something like this:

%7B%22hutk%22%3A%220f9abb06328e07b16e16f3571b30c31e%22%2C%22pageUrl%22%3A%22http%3A%2F%2Ftest.com%2Fsignup%22%2C%22pageName%22%3A%22My%20Page%22%2C%22redirectUrl%22%3A%22https%3A%2F%2Ftest.com%2Fdone%22%2C%22ipAddress%22%3A%22127.0.0.1%22%7D

which would decode to

{“hutk”:“0f9abb06328e07b16e16f3571b30c31e”,“pageUrl”:“http://test.com/signup",“pageName”:"My Page”,“redirectUrl”:“https://test.com/done",“ipAddress”:"127.0.0.1”}


#6

Thank you for your reply. In early testing, this change has already resulted in the “pageName” (adjacent to the cookie) showing up on your dashboard from this call, so I am hopeful the other issue will be also be fixed once we deploy this.

Please be aware that the way we had implemented it previously (with the “+” as spaces in the JSON) is exactly as the example in the official documentation’s example has it at https://developers.hubspot.com/docs/methods/forms/submit_form .

So, the official example of a full body should instead be:
firstname%3DTestContact%26lastname%3DFormSub%26email%3Dformsub%40hubspot.com%26newcustomproperty%3Dtesting%26hs_context%3D%7B%22hutk%22%3A%2260c2ccdfe4892f0fa0593940b12c11aa%22%2C%22ipAddress%22%3A%22192.168.1.12%22%2C%22pageUrl%22%3A%22http%3A%2F%2Fdemo.hubapi.com%2Fcontact%2F%22%2C%22pageName%22%3A%22Contact%2BUs%22%2C%22redirectUrl%22%3A%22http%3A%2F%2Fdemo.hubapi.com%2Fthank-you%2F%22%7D

If you’ve arrived here and are also writing in Ruby, consider running the following on your form data before submitting it (and consider using Faraday):

form_data["hs_context"] = form_data["hs_context"].to_json

#7

Thanks @robin_izea, I’ll make sure the documentation gets updated.


#8

Hi @dadams, thank you for all your helpful responses regarding tracking traffic source through the Form API. Our campaign landing page to web app flow is very similar to robin’s , but we have a slightly different issue.

Here’s an example of a lead’s journey:

  1. lead sees our link on a referral site: https://www.producthunt.com/alternatives/marvel-2-0-2
  2. lead clicks on the “GET IT” link under “Brandcast”
  3. the link takes lead to our landing page: https://brandcast.com/?ref=producthunt
  4. lead clicks on one of the “try for free” links on the landing page
  5. the link takes the lead to our signup page which is on our web app under a different domain: https://app.brandcast.io/signup
  6. after the lead signs up, a contact like this one is created: https://app.hubspot.com/contacts/2712945/contact/63251/

As you can see the contact traffic source is recorded as “Direct Traffic” while we are certain that the lead went through the flow above.

We have the hubspot tracking code deployed via google tag manager on both the landing page and the signup page (although under different domains). We are fairly confident that we are sending the hutk data correctly because a couple of contacts are showing the correct traffic source, for example:
https://app.hubspot.com/contacts/2712945/contact/58701
https://app.hubspot.com/contacts/2712945/contact/73101

We think these leads might have clicked on ads that show links directly to our web app signup page which might explain the correct traffic source.

Here’s an example of the form API request body:

company=referral2&company_size=&custom_query_parameters=%26_ga%3D2.190843178.1242099095.1499890904-677363387.1441927871&email=referral2%40test.com&firstname=referral2&gclid=&hs_context=%7B%22hutk%22%3A%22e33b721cfa83144eefef3775a12000a7%22%2C%22pageUrl%22%3A%22https%3A%2F%2Fapp.brandcast.io%2F%23%2Ffte%22%2C%22pageName%22%3A%22Create%20Account%22%7D&jobtitle=&lastname=referral2&persona=organization&phone=&referrer_url=https%3A%2F%2Fwww.cmscritic.com%2Fbrandcast-a-web-design-platform-worth-investing-in%2F&utm_campaign=&utm_content=&utm_medium=&utm_source=&utm_term=

Could you provide some insight into why the traffic source is not correct when the leads go through our landing pages then to our web app signup page?

Thank you


#9

NVM @dadams, we figured it out. We had to enable the “Automatic cross-domain linking” option in the hubspot tracking code according to this article: https://knowledge.hubspot.com/articles/kcs_article/settings/can-i-track-multiple-domains-with-hubspot