cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Mick282
Level: Powered On

How to extract the a Google Analytics UTM value from a URL

Hi I want to extract the Google Analytics UTM parameter values from a URL. As an example, if I have a URL of:

 

https://www.test.com?utm_medium=newsletter&utm_campaign=test-campaign&utm_content=cool

 

What I'd want to extract is the "newsletter" from medium, "test-campaign" from campaign and "cool" from content.

 

I'm looking at the substring expression but how do I dynamically get the string if potentially the character amounts are different.

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: How to extract the a Google Analytics UTM value from a URL

Hi @Mick282 

 

A substring for that would be quite complicated, but you can have a Flow that extracts that information. 

 

You need two splits and then cycle through the values to get what you want. If you have a Premium subscription, you can create this Flow with a "Request" trigger so that you can re-use this logic everywhere. Then you need to do an HTTP Post with your URL and get the values.

 

Here's the Flow:

 

STEP 1: Get the values, so we need to split by "&".

 

small-Screenshot_2019-10-22_at_11_29_13.jpg

 

The formula is:

split(triggerBody()['text'],'&')

 

STEP 2: For each of the values split by "=".

small-Screenshot_2019-10-22_at_11_29_38.jpg

The formula is:

split(items('Apply_to_each'),'=')

 

STEP 3: Assign to the variables

small-Screenshot_2019-10-22_at_11_30_35.jpgsmall-Screenshot_2019-10-22_at_11_30_49.jpg

 

The Switch formula is:

outputs('Compose_2')[0]

And then set to the variables with the formula:

outputs('Compose_2')[1]

 

 

That's it.

Is this what you need?

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

View solution in original post

Re: How to extract the a Google Analytics UTM value from a URL

Hi @Mick282 

 

You're right. I forgot to validate the URL.

 

It's quite simple, add a simple IF with the following structure:

 

Screenshot 2019-10-24 at 10.36.50.png

 

You can use the same strategy in the standalone Flow.

 

I hope this helps!

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

View solution in original post

6 REPLIES 6

Re: How to extract the a Google Analytics UTM value from a URL

Hi @Mick282 

 

A substring for that would be quite complicated, but you can have a Flow that extracts that information. 

 

You need two splits and then cycle through the values to get what you want. If you have a Premium subscription, you can create this Flow with a "Request" trigger so that you can re-use this logic everywhere. Then you need to do an HTTP Post with your URL and get the values.

 

Here's the Flow:

 

STEP 1: Get the values, so we need to split by "&".

 

small-Screenshot_2019-10-22_at_11_29_13.jpg

 

The formula is:

split(triggerBody()['text'],'&')

 

STEP 2: For each of the values split by "=".

small-Screenshot_2019-10-22_at_11_29_38.jpg

The formula is:

split(items('Apply_to_each'),'=')

 

STEP 3: Assign to the variables

small-Screenshot_2019-10-22_at_11_30_35.jpgsmall-Screenshot_2019-10-22_at_11_30_49.jpg

 

The Switch formula is:

outputs('Compose_2')[0]

And then set to the variables with the formula:

outputs('Compose_2')[1]

 

 

That's it.

Is this what you need?

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

View solution in original post

Mick282
Level: Powered On

Re: How to extract the a Google Analytics UTM value from a URL

Thanks @manuelstgomes .

 

That seems to work. Thank you so much for this.

 

Just want to check. Is there anyway to make the flow steps smaller? 

Re: How to extract the a Google Analytics UTM value from a URL

HI @Mick282 ,

 

I guess, but I would need to think about it a little. I would advise, however, to have a little bit more steps, and the Flow is readable and easily understandable by someone else than compressing it and becoming complex to understand. Even you in a few months won't know why you did it that way 🙂

 

Think about it and also think about the Request strategy. Then you would have the Flow as a "Function".

 

Inspired by your question, I wrote a blog post on how to achieve this. I hope you don't mind using your question as inspiration.

https://manueltgomes.com/microsoft/flow/flow-parse-utm-parameters-from-url/

 

I have also templated that you import and see how it works:

https://manueltgomes.com/microsoft/flow/template-archive/#jump_request_trigger

 

Anyway, glad all is working!

 

Anything else, please let me know.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

Mick282
Level: Powered On

Re: How to extract the a Google Analytics UTM value from a URL

Hi @manuelstgomes 

 

So I ran into another issue. What happens if someone clicks to the landing page organically without a UTM. The flow seems to fail during the switch and anything afterwards will fail.

 

I saw in your blog you mentioned having this flow separate as a function which you can call.

 

EDIT: So I set the UTM extraction as a standalone flow based off your template. That way I can call that flow whenever I need the UTM records. It also means that if the split fails, it doesn't stop the entire flow steps afterwards.

 

The only thing is again if I call the function and try to return the UTM values from the standalone Flow and the url passed doesn't have any UTMs. The calling flow will attempt to call the UTM extraction flow 4 times before failing. That's fine with my calling flow has I had all the records created before hand but I'm hoping there's a more elegant way of doing this.

 

If expressions don't work because we're extracting an Array index number in the switch so if position 1 doesn't exist, the switch will fail regardless.

Re: How to extract the a Google Analytics UTM value from a URL

Hi @Mick282 

 

You're right. I forgot to validate the URL.

 

It's quite simple, add a simple IF with the following structure:

 

Screenshot 2019-10-24 at 10.36.50.png

 

You can use the same strategy in the standalone Flow.

 

I hope this helps!

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

View solution in original post

Mick282
Level: Powered On

Re: How to extract the a Google Analytics UTM value from a URL

Thanks @manuelstgomes .

 

Doh, that's actually really simple lol. I think my mind has recently been in the mindset of trying to solve everything with expressions as opposed to Flow steps hahaha.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 160 members 5,203 guests
Please welcome our newest community members: