How to make anchor links work with UTM parameters in the URL

How to make anchor links work with UTM parameters in the URL

While working with UTM parameters recently, I found out that anchor links don’t work with URL parameters the way I thought they would.

UTM parameters are parameters added to URLs to track and monitor marketing campaigns. The most common parameters that are tracked are source, campaign, medium, content and term.

When attaching UTM parameters or any other parameter to the URL, it will normally look something like this:

https://www.example.com?utm_campaign=summer&utm_source=instagram

Now let’s say the URL you want to attach the parameters to is an anchor link that leads to a section of the page like this for example: https://www.example.com#section2

If you add the UTM parameters at the end of the URL like this: https://www.example.com#section2?utm_campaign=summer&utm_source=instagram

you will notice that the anchor link stops working and doesn’t go to the intended section.

To make UTM parameters (or parameters in general) work with anchor links you should add the section id to the end of the URL string after the parameters, like this: https://www.example.com?utm_campaign=summer&utm_source=instagram#section2

That’s all, your anchor links now play nice with the UTM parameters :)