I built an internal custom URL shortner for my team in node js, however When generated short link is added to a message in Instagram, slack etc. the platform fetches meta tags to display title, image and description for preview to attach with the message.
Issue: This preview request currently is counted as a click within my logic since request to short link increments click count before 301 redirect to long URL
How can I robustly filter social meta preview requests? So that the engagement count is tracked correctly for this built tool.
Not 100% robust but currently this is how i decided to solve this issue:
step 1: created a list of known bot user-agents
steps 2: check if incoming request user-agent includes any of the bots user agents if it does then don't increment clicks if doesn't it means its not a bot and then increment clicks
Code below: