In my previous blog post I went in depth about anchor tag IDs and the fact that they’re a completely optional part of web development. However as you delve deeper on the best way to track everything on your website, you’re going to have to weigh the pros and cons of whether or not you need these identifiers.
Why aren’t anchor tag ids normally used?
Anchor tag ids aren’t always used because adding them means more code. Generally speaking, the more code you have, the longer it is to develop and the slower the page loads. This is not the case 100% of the time, but think of it like a book – it’s going to take a lot longer to read a 200 page book than a 20 page book, unless your 20 page book is written at a university level and your 200 page book is written at a 3rd grade level. Same concept. But more than load time, the development time is really what makes it stand out. You’re essentially paying a developer more money to add something that does nothing on the page. Well, mostly.
Why do you want to put anchor tag ids on a page?
Now that I’ve discounted anchor tag IDs, citing page speed and development time, let me tell you about their benefits. Unless you have a super fancy web analytics program, you’re probably getting all your web analytics tracking from Google Analytics.
Google Analytics is great in a lot of ways, but it has its limitations. With Google Analytics you can tell which pages people visited, but not which specific link they clicked on. All Google Analytics cares about is that you went to the next page, not that you interacted with one link more than another link.
One of the best ways to tell which specific link was clicked is by adding that anchor tag ID, because as I mentioned before – it’s the only one on the page. It’s important to note though that it’s totally possible to track an individual link without an anchor tag ID, however I don’t recommend it.
For example, many people track a specific link click based on the anchor text. This works great unless your anchor text is the same for all buttons (“Buy now!”) or decide that you need more keyword intensive anchor text for SEO and forget to tell your tracking team. Having the anchor tag ID is also especially helpful if you change your anchor text for an A/B test. Otherwise, you’re stuck trying to do some pretty complex regular expressions, which increases your opportunity for error.
Summary
Code smarter, not harder. If you’re looking to perform A/B testing in the future or if tracking the most successful CTA is important to you, it may be beneficial for you to put IDs on your anchor tags. However, if you’ve got links all over your website that you have no intent on tracking in the future, then my advice is to hold off on the anchor tags. Instead, avoid the anchor tag IDs, get your website to load quicker and have a website that’s developed faster.