# Extracting Param Value From URL Path Using Custom Code

**URL:** <https://community.hubspot.com/t/extracting-param-value-from-url-path-using-custom-code/104647>\
**Category:** Data Hub\
**Created:** [April 11, 2024, 8:40pm UTC](https://community.hubspot.com/t/extracting-param-value-from-url-path-using-custom-code/104647 "2024-04-11T20:40:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoshuaW](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/joshuaw/32/79535_2.png) [@JoshuaW](https://community.hubspot.com/u/JoshuaW)\
**Post date:** [April 11, 2024, 8:40pm UTC](https://community.hubspot.com/t/extracting-param-value-from-url-path-using-custom-code/104647/1 "2024-04-11T20:40:46Z")

</div>

Does anyone know workflow custom code that would extract a specific parameter from the “Last Page Seen” contact property URL to then apply that value to another property for the contact? For example: If the “Last Page Seen” value is the following URL and I’m looking for the param value of “npsevent”, I would want the action to copy “CaptureThisValue” to another property.

[examplewebsite.com/event?npsevent=CaptureThisValue](http://examplewebsite.com/event?npsevent=CaptureThisValue)

I can predict the parameter of “npsevent” will always be present, but the value could be different for different contacts and is unpredicable.

The workflow the action is in would trigger off of update to “Last Page Seen” property with filter for it to include the specific parameter I need to capture the value of.

---

<div class="post-metadata">

**Author:** ![karstenkoehler](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/karstenkoehler/32/68554_2.png) [@karstenkoehler](https://community.hubspot.com/u/karstenkoehler)\
**Post date:** [April 12, 2024, 4:42am UTC](https://community.hubspot.com/t/extracting-param-value-from-url-path-using-custom-code/104647/2 "2024-04-12T04:42:42Z")

</div>

Hi @JoshuaW,

This should be possible with a regex replace:

 ![karstenkoehler_0-1712896740714.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/1/c/1c5c40ea37280da6952f4669df158740438d0f9f.png)

I’m not a regex expert but this code snippet should correspond to anything before the parameter:

`^.*\?npsevent=`

Explanation:

- `^`: Matches the beginning of the string.
- `.*`: Matches any character (including spaces) zero or more times. This captures everything before “?npsevent=”.
- `\?npsevent=`: Matches the exact string “?npsevent=”.

Replacement Text: Leave the replacement text empty (`""`). This effectively removes the matched portion of the string.

You should then be able to save the remaining parameter into a new property. I haven’t tested this but it feels doable 🙂

Best regards!

---

<div class="post-metadata">

**Author:** ![JoshuaW](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/joshuaw/32/79535_2.png) [@JoshuaW](https://community.hubspot.com/u/JoshuaW)\
**Post date:** [June 18, 2024, 2:30pm UTC](https://community.hubspot.com/t/extracting-param-value-from-url-path-using-custom-code/104647/3 "2024-06-18T14:30:34Z")

</div>

Hi Karsten,

Thanks for the response. It helped me get part way to my goal, but not fully isolate value needed.

Using the following does copy over the value of the parameter, but it is also copying over everything else after it.

 ![2024-06-18_10-20-32.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/3X/0/d/0d9d2b45c85ba6f596e90b34544970e128ebff74.jpeg)

Below is example of the value it currently creates, but I want to capture what is green and what I need still removed in red.

Meet%20the%20Business%20Network%20Newsroom

&utm\_campaign=2024\_MTN&utm\_medium=email&\_hsenc=00000JQJR\_KdgJ0E4&\_hsmi=000008085&utm\_content=000008085&utm\_source=hs\_email

I want only what is after “&npseventname=” and before “&utm\_campaign”. I’d then want to unencode it to finally paste the result in another custom property.

---

<div class="post-metadata">

**Author:** ![KKolodinsky](https://avatars.discourse-cdn.com/v4/letter/k/d6d6ee/32.png) [@KKolodinsky](https://community.hubspot.com/u/KKolodinsky)\
**Post date:** [March 7, 2025, 3:31pm UTC](https://community.hubspot.com/t/extracting-param-value-from-url-path-using-custom-code/104647/4 "2025-03-07T15:31:01Z")

</div>

Hey Joshua,

Thanks for posting this and Karsten for the first step. I’ve come across this post as I was looking to do something similar and adapted code from another community post to push across the finish line: [https://community.hubspot.com/t5/9881-Operations-Hub/Custom-code-Format-Data-split-full-name-property/m-p/740086](https://community.hubspot.com/t5/9881-Operations-Hub/Custom-code-Format-Data-split-full-name-property/m-p/740086)

Sharing here in case it’s helpful for you or anyone else that stumbles across this post. Big disclaimer, I’m not an expert in any of this so it’s possible that there’s a better way to do it.. this is just what worked for me.

---

**My use case: Extract utm\_content from Last Page Seen**

Example Last Page Seen value: [https://yourdomain.com/?\*utm\_source=example\_source&utm\_medium=example\_medium&utm\_content=content\_type&utm\_campaign=example\_campaign](https://yourdomain.com/?*utm%5C_source=example%5C_source&utm%5C_medium=example%5C_medium&utm%5C_content=content%5C_type&utm%5C_campaign=example%5C_campaign)\*

Enrollment Filter: Last Page Seen contains utm\_content

1. Format data with regex\_replace: ^.\*utm\_content=

 ![KKolodinsky_0-1741360572382.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/b/4/b4c4593b4b21f41eff89463e7445abb66e926400.png)

_Example output: content\_type&utm\_campaign=example\_campaign_

2. Custom code (Python 3.9)

Property to include in code: input\_string = Action outputs - [String] value from step 1

 ![KKolodinsky_1-1741360846674.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/a/f/af0b88376be6cee53569af7bf31ffffcd3dcfcc7.png)

Use this code, customizing for your output field names

`def main(event):content_string = event.get("inputFields").get("input_string")string_list = content_string.split("&")utm_content = string_list[0]return {"outputFields": {"utm_content": utm_content,}}`

 ![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/5/f5f61de9c66df0a683a1b063d6a9287a8372224c.png)

_Example output: content\_type_

3. Edit record, setting the property value to the string identified in 2. Custom code

 ![KKolodinsky_3-1741361049460.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/3/1/31e2f16cf0db6aeef2504849d3b4155ef7f8e6e1.png)
