Updated 2020-01-09: Improved the Flows to get only the UTM parameters to parse. Templates updated also.
For those unaware, what are UTM parameters, they are additions to the URL that help marketing people segment a link in a specific campaign, medium, and content. You can see this usually when you open a link, in an email or click specific links in websites, but they always keep a format like this:
Google Analytics, or whatever system you’re using, pick them to keep tabs on what’s working and what’s not. Google Analytics introduced UTM parameters for that specific purpose, and used widely in the industry, even in competing services.
Why extract them
Sometimes it’s handy to have that information elsewhere so, given a specific URL, we can quickly parse these values and get them individually and store them. For example, if you want to keep a list of all parameters used in campaigns and provide that list to the marketeers, then you need to get them individually. You can give them a Flow that they can feed a URL, and that information is automatically stored for them to reference in the future.
Flow to get the parameters
I’ve built two templates that you can find in my template section, one if you want to have the full flow and another if you’re going to have a Flow that performs these actions and then returns the values. The later can be quite useful if you want to re-use this logic elsewhere but requires you to have a premium account because we’re using the “Request” trigger.
There are three main steps for parsing the URL.
Get the individual elements
Let’s use the example above and split it using the & as our separator.
The formula is quite simple:
We’ll get something like this:
[ "https://www.test.com?utm_medium=newsletter", "utm_campaign=test-campaign", "utm_content=promotion" ]
Get the values of the elements
Now that we have the items, we need to get each of them and split them again, this time by “=.”
The formula is the same:
And we’ll get something like this:
First run: [ "https://www.test.com?utm_medium", "newsletter" ] Second run: [ "utm_campaign", "test-campaign" ] Third run: [ "utm_content", "promotion" ]
Setting the values to variables
The rest is trivial. Add a Switch and set them to the correct variable.
Notice that the default is “utm_medium.” It’s usually the first one, and we’ll get the URL also, so if we can get the other two, then we’re sure that the last one is this one.
If you’re using the Request trigger
The “Request” trigger allows you to centralize a lot of business logic into one Flow. There are only two extra things that you need to take into consideration that I’ll highlight now.
I’ll include, in the template, archive an example of a Flow that calls a service that is a “Get” instead of a “Post” so that you can see the differences.
Request Type – GET
The request type needs to be “Get,” since we’re trying to get something back from the service, in this case, the values parsed. To do this, just set, in the advanced settings, the “method.” Notice that we’re not expecting anything in the body of the request since the URL is in the “Header” portion of the request
Now let’s prepare the information to send back to the caller of the service. To do this, do the following:
The calling Flow will get a helpful JSON formatted reply with the UTM parameters passed.
One more thing
I got an email from Sam (my thanks to Sam!) that had a perfect point. The templates work if you have URLs that contain UTM parameters only. If not we need to add an extra filter to filter them out.
Here’s the change:
The formula to filter is the following:
We’ll filter out all items that don’t contain the string “utm_.” The templates were updated to consider this.
It’s quite simple, and it can give you a lot of flexibility to parse information internally.
There’s no need for you to build this yourself. I have a template that you can download and it in your instance. Just use the template archive, and you’ll find these and more.