Conversion tracking with the Forms API



I’ve been working with the Forms API for a while and for the most part everything works just fine as the submissions appear correctly in HubSpot with the correct field values.

However, all of the stuff related to “web analytics” doesn’t work. For example, the original source is shown as “Offline sources” with the drill down saying “FORM”, even though I came to the site via a link and can verify that the cookie value of the user is correctly being passed in the hutk section as part of the request body.

I assume the issue might have something to do with my escaping/formatting of “hs_context” part being somehow incorrect. Any ideas on what could be wrong? You’ll find an example request body below.



Hi @jesseniem

The hs_context data is getting double encoded. When you decode the value in that example, the result is still URL encoded:


That value is what you’d actually want in the POST data, since decoding that gets you the valid JSON.



Thanks for the quick reply @dadams! :slight_smile: That would indeed seem to have been the issue.

The requests library in Python can’t handle dictionaries inside a dictionary so doing the URL escaping manually resulted in this behaviour.

If someone else is trying to do this with python, you can use json.dumps() to convert the hs_context dictionary to a JSON string for the request library to process automatically.


I am having a similar issue where I am not seeing any Hubspot Analytics data. I am submitting the hs_context data via Forms API on my external site (using PHP to cURL the data to the endpoint). I created a form in hubspot so that I would have a form guid needed to post the form data. I am not embedding the hubspot form but using my own form.

I have taken the following steps -

  1. Installed Hubspot tracking cookie script on all pages of our website. Double-checked to make sure cookie is present
  2. Correctly encoded my hs_context values - {“hutk”:“xxxcxxxxxx39e1c987107008xxx”,“ipAddress”:“”,“pageUrl”:“",“pageName”:"Sign up for a plan”} (masked hutk and ip values for this thread)
  3. Removed my IP address from the IP Filtering list

When I submit the form it correctly populates name, email, company etc. But I am not seeing any analytics data being populated. For example, under Forms, the submissions are incrementing with each submit but the views are still at 0. In the individual contact settings properties, the IP Address is being correctly set, but nothing for IP City, State etc. Also page views is still at 0. I should note that my page is not public facing (my ip is private). Could this be affecting the analytics data not populating? I looked for this extensively but did not find any information in the Hubspot documents that says this would be an issue.



@tchin If you’re using the Forms API to send HubSpot form data, we’ll record submissions but we don’t have a way to record form views. At the moment we’ll only record views to the form if you’re using the form embed code.

For the contact record, the analytics data won’t populate immediately, so if you’re looking for views and page views for the record immediately after its creation, you’ll need to wait a minute or so to see the analytics data populated.

If you’ve waited a while and you’re still not seeing that, then there might be a problem with the submission. Do you have an example of the full encoded POST data you’re using? Even if the JSON in hs_context is correctly encoded there might be another issue with that data.

Submit data to a form via API and track form views

Here is the fully encoded POST data I am sending -


And the array before I run http_build_query() -

[firstname] => sprintsignup
[lastname] => test11
[dev_testing] => YES
[email] =>
[hs_context] => {“hutk”:“c34d8ca17a28539e1c987107008876df”,“ipAddress”:“”,“pageUrl”:“",“pageName”:"Sign up for a plan”}

I gave it 48 hours but still no analytics data.



The data looks ok, can you send me a link to the contact record that that submission created?


How do I share that contact record? I can only see it if I am logged in. Also, the response from the Forms API endpoint is empty. It doesn’t fail, just empty. But the record did get created.


Form submissions return a 204 no content response, so you will get a response with that status code, but there won’t be anything in the body of the response.

For sending me the contact, you can either just send me a link to the record you’re viewing, or just send me your Hub ID and the contact vid or email.


Here is the link to the record in Hubspot


Thanks @tchin, looking at that record, I can see that the form submission looks ok, and the utk is getting attached to the contact, but the utk does not show any analytics data, so it doesn’t look like there are any page views to show. So the form submission is working correctly, but the page views are not being tracked.

Is this set up on a local testing system, or would there be a way for me to take a look at the pages you’re testing this with?


I think this is working OK. Because I am testing multiple users on one PC/Browser, it looks like the Analytics is tracking based on one unique cookie. So most of the analytics data is being tracked as expected, just to one particular user. If I clear my cookies Hubspot tracking should recognize me as a ‘new’ user.

Thanks for your help.



When I turn off IP Filtering (remove my IP from the excluded list) - is it immediate or is there a wait until I start to see Analytics data come in?


The IP filter is applied when the analytics is processed, so removing an IP will not reprocess the existing data, it would just start showing data from that IP going forward. The same applies in reverse as well, adding a new IP will not filter out past traffic, jut new traffic going forward. The IP filter gets applied within a minute, but analytics also has a processing delay of a few minutes so you may not see the effects for several minutes.


Awsome! Thanks again!