Traffic Source is Incorrect for API Form post

forms
contacts

#1

I’m currently only getting Direct Traffic for the Traffic Source on api form posts. I know you probably get this a lot, but I’ve gone through a lot of the documentation, as well as other posts on this subject, and I still feel like I don’t know what the problem is. I’m using c# with mvc asp.net.

The API post is fine (as in I get all the correct values for everything else), and I include Request.Cookies[“hubspotutk”].Value (which I checked to make sure it is giving a value) in hsContext Dictionary when posting the data. I’ve made sure that cookies are not disabled on the form as well as in the report settings. I’ve also viewed the source of the page, and made sure that the javascript is included just before the closing body tag on every page, including the one where I post the data. However, despite that, traffic source is still always Direct Traffic.

Please let me know if anymore information is needed


#2

Hi @Garrett

Are you passing the context data in a hsContext field or hs_context? Your post mentions hsContext but you would need to use hs_context.

If you are using hs_context, do you have an example of the actual POST data you’re using?


#3

Hi @dadams,

Thank you for answering. My Dictionary variable is called hsContext as shown on https://developers.hubspot.com/docs/methods/forms/submit_form

Dictionary<string, string> hsContext = new Dictionary<string, string>();
hsContext.Add(“hutk”, strHubSpotUTK);
hsContext.Add(“ipAddress”, strIpAddress);

but I post it as “hs_context”

// Append HS Context JSON
strPostData += "hs_context=" + Server.UrlEncode(strHubSpotContextJSON);

Edit:
Here’s the hs_context post data (was on localhost):

“{“hutk”:“561f2e1ae22989c634d6815f88298463”,“ipAddress”:”::1"}"

and the StrPostData value looks like this:

“firstname=Garrett&lastname=K&email=test%40pacbell.net&phone=(555)+555-5555&eye_exam=Yes&contact_lenses_exam=&store_try_on=&insurance=Yes&appointment_location=TestStore1&appointment_date=5%2f31%2f2017+9%3a00%3a00+AM&hs_context=%7b%22hutk%22%3a%22561f2e1ae22989c634d6815f88298463%22%2c%22ipAddress%22%3a%22%3a%3a1%22%7d”


#4

Thanks @Garrett. Do you have an example contact I could take a look at? The POST data looks correct, but something else may be going on with the contacts.


#5

Not sure if it’s just a coincidence that it didn’t look like it was working before. But I checked the contacts list, and the last hour has actually given accurate values (or rather, values other than Direct Traffic). In the last hour, I see Organic Search and Paid Search results now, though the last 100+ contacts (before the most recent change) are all Direct Traffic.

So I think it’s working… Thank you for the help