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.
Solved! Go to Solution.
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 "&".
The formula is:
split(triggerBody()['text'],'&')
STEP 2: For each of the values split by "=".
The formula is:
split(items('Apply_to_each'),'=')
STEP 3: Assign to the variables
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
Hi @Mick282
You're right. I forgot to validate the URL.
It's quite simple, add a simple IF with the following structure:
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
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 "&".
The formula is:
split(triggerBody()['text'],'&')
STEP 2: For each of the values split by "=".
The formula is:
split(items('Apply_to_each'),'=')
STEP 3: Assign to the variables
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
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?
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
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.
Hi @Mick282
You're right. I forgot to validate the URL.
It's quite simple, add a simple IF with the following structure:
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
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.
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!
User | Count |
---|---|
39 | |
37 | |
37 | |
32 | |
28 |
User | Count |
---|---|
39 | |
37 | |
31 | |
28 | |
23 |