Pull Query String from First Page Seen

I’m looking for a way to pull the query strings from the First Page Seen url. I want to pass this information into their respected fields within the contact property, i.e., utm_source, utm_medium, etc.

Was wondering if someone has already done this so I don’t have to create the code myself.

Hello @ryanbreneman, thank you for posting in our Community!

To our top experts @Mike_Eastwood @StefaniUAT - @tjoyce any recommendations to @ryanbreneman?

Thank you,

Pam

Thank you @PamCotton, appreciate the hello and the help.

Just to include a little more information. I’m trying to use the Custom Code within a workflow. And this is what I’ve been trying but haven’t gotten it to work. Not sure if this is the best way.

exports.main = async (event, callback) => {
 /*****
 Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.
 *****/
 const firstpageseen = event.inputFields['hs_analytics_first_url'];
 const queryString = firstpageseen.parse(window.location.href).query;
 const ParameterName = 'utm_source'
 const parameterValue = queryString[ParameterName]
 /*****
 Use the callback function to output data that can be used in later actions in your workflow.
 *****/
 callback({
 outputFields: {
 utmsource: parameterValue
 }
 });
}