Traffic Source At Time of Form Submission

I want to know what traffic source (organic, paid, email marketing, etc.) is responsible for generating a form submission. This data needs to be tied to the Contact record, updated at or around the time of a form submission.

hs_original_traffic_source isn’t dependable due to our oldest Contact records being imports, or from too long ago.

hs_latest_traffic_source gets overwritten with each new session.

I’ve created traffic_source_at_time_of_submission, and set up a workflow triggered by ANY FORM SUBMISSION that looks like the screenshot below. *
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Important note: This branch checks if hs_latest_traffic_source HAS BEEN UPDATED in the last 1 day. Otherwise, hs_latest_traffic_source was coming up empty at times, therefore copying null over to traffic_source_at_time_of_submission.
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~*

Great. Now we’re able to capture the hs_latest_traffic_source for the session at the time when a web visitor actually submitted one of our lead forms.

So… How can we retroactively fill this value for hundreds of thousands of contacts?

Workflows cannot dig through property history for hs_latest_traffic_source and grab its latest value prior to recent_conversion_date.
I’ve considered writing a NodeJS application to do just that… but I’ve since realized that this logic has the same issue as the one described in my important note above. hs_latest_traffic_source isn’t always set at the time when the form is submitted, and often takes time to be calculated–hence the two minute delay in my workflow.

Workflows can’t read property history but the api can, that’s the whole unlock here. Pull each
contact with propertiesWithHistory=hs_latest_traffic_source and you get every timestamped
version of that property. Grab the version whose timestamp lands at or just before the
conversion date and write that into your custom field. Bonus, that also kills your
2 minute delay problem, since you’re reading the value that was actually live at that moment
instead of racing it in real time. Before you run it on hundreds of thousands though, check one thing that hubspot doesn’t keep unlimited version history per property, so on your oldest imported contacts the early values might already be gone. pull - properties With History on a handful of your oldest records first and see how far back it actually reaches. If the history’s there, the backfill is just a paginated read plus update, no node app guessing required there.

Hi @davidjwu92,

There is an easier way to do this - assuming that you’re doing this for reporting purposes.

When you use the Form submission data source in the custom report builder, you can access data points like “utm_source” and “Visit source”. This will give you retroactive data, no workflow needed, no custom property required.

Best regards