Sending UTM's programmatically

Hello,

We have conducted some research to explore if there are any API endpoints available for programmatically sending UTM parameters to HubSpot. Alternatively, we are considering the option of creating a hidden form and submitting it with the UTM parameters if the user satisfies certain conditions on our page. But still not sure if will work.
Does anyone encountered this before and has any thoughts on how can be done?

Hey, @ARatiu :waving_hand: Thanks for reaching out! This is a great question.

Looking at the documentation and conducting a quick search of community posts and solutions, I didn’t find an example of accomplishing this programmatically.

One question to better understand your use case:

Are you tracking custom UTM parameters that HubSpot doesn’t automatically capture, or are you managing UTM parameters differently?

Regarding your second idea, using hidden fields in forms to capture UTMs is a strategy some HubSpot users employ.

Typically, people use JavaScript to capture these UTM parameters from the URL when a visitor lands on your site, and automatically populate these hidden fields with the UTM values.

If you have more questions or if there’s more context you can provide, that would be really helpful for the community to give you a more targeted solution.

Have fun building! — Jaycee

Thank you for your answer.
Are you tracking custom UTM parameters that HubSpot doesn’t automatically capture, or are you managing UTM parameters differently?
We’re managing UTM parameters differently, we have some strategies and in certain conditions, we want to send the UTM’s to HubSpot.
I’ve found a way, like submitting from the client-side a form that does not exist on the page but we still want to track the UTM’s as I mentioned above in certain conditions.

https://api.hsforms.com/submissions/v3/integration/submit/{portal-id}/{form-id}
Hiting this endpoint and passing the payload:

const formData = {

context: {

    pageUri: '[https://examplepage.com?utm\_campaign=my\_campaign&utm\_source=facebook&utm\_medium=test](https://examplepage.com?utm_campaign=my_campaign&utm_source=facebook&utm_medium=test)',

},

};
It seems to appear in Reports → Traffic analytics → UTM, not sure if this is the right way but it seems to work and it’s showing after 40 minutes the UTM parameters.