How to get utm parameters from the URL querystring

Hi everyone,
I have a webhook from which I receive contact form data.
From the form URL I would like to extract the utm parameters of the provenance campaigns.

This is the final part of the url:
/?utm_campaign=Friuli-Veneto&utm_medium=Search&utm_source=Google&gclid=Cj0KCQiAoeGuBhCBARIsAGfKY7yrzmid2VGBSjlnMMfMdY5AOWNAKAkU8UQrOLf0MfW1zidpoEZGAmEaAjXyEALw_wcB

I would like to extract the words contained between the = symbol and the & symbol

Url is variable, so the words inside the symbols can change, which is why the substring function is not good.

You can help me?

Thank you

Welcome to the Make community!

Option 1: If query string parameters are always in the same format

Screenshot_2024-02-20_151445

You can use a Text Parser “Match Pattern” module with this Pattern (regular expression):

utm_campaign=(?<utm_campaign>[\w_-]+)&utm_medium=(?<utm_medium>[\w_-]+)&utm_source=(?<utm_source>[\w_-]+)&gclid=(?<gclid>[\w_-]+)

Proof

https://regex101.com/r/8Iha1E

Important Info

  • :warning: Global match must be set to NO!

Screenshot and Output

As you can see, only one module is needed for this option

3 Likes

Option 2: Match all key-value pairs

Screenshot_2024-02-20_151445

You can use a Text Parser “Match Pattern” module with this Pattern (regular expression):

[?&](?<key>[^=]+)=(?<value>[^&]+)

Proof

https://regex101.com/r/246vPo

Important Info

  • :warning: Global match must be set to YES!

Screenshot

Using this method, you will need to aggregate to array and convert the array to a collection of parameters, using the toCollection built-in function.

Output

Screenshot_2024-02-23_230204


For more information, see Text Parser in the Make Help Center:

Match Pattern
The Match pattern module enables you to find and extract string elements matching a search pattern from a given text. The search pattern is a regular expression (aka regex or regexp), which is a sequence of characters in which each character is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.

Hope this helps!

3 Likes

Hi Samliew

The first solution seems to work perfectly.

Thank you very much

2 Likes

No problem, glad I could help!

1. If you have a new question in the future, please start a new thread. This makes it easier for others with the same problem to search for the answers to specific questions, and you are more likely to receive help since newer questions are monitored closely.

2. The Make Community guidelines encourages users to try to mark helpful replies as solutions to help keep the Community organized.

This marks the topic as solved, so that:

others can save time when catching up with the latest activity here, and

  • allows others to quickly jump to the solution if they come across the same problem

To do this, simply click the checkbox at the bottom of the post that answers your question:
Screenshot_2023-10-04_161049

3. Don’t forget to like and bookmark this topic so you can get back to it easily in future!

2 Likes

Hi Samliew

I have a problem.

The first solution you proposed works great.

The only problem is that if the url is changed my flow is blocked.

How can I avoid blocking the flow when the text parser fails to obtain the data?

Thank you

That looks like a new question, could you please create a separate topic for this?

While it’s tempting to continue an existing thread, a more effective approach would be to start a new topic just for your new question. It helps community experts find and respond to your query quicker, and keeps our space organised for everyone. If you start a new conversation you are also more likely to get help from other users. You can refer others back to a related topic by including that link in your question. Thank you for understanding and keeping our community neat and tidy.

The “New Topic” link can be found in the top-right of the header:

Screenshot_2023-12-19_091207

3 Likes