web development: how to measure clicks and impressions of banners?


I have a website where I publish banners, so what is the best way to measure impressions and real clicks?

I tried to implement a custom measurement system, but the numbers are not real, since it is difficult for me to filter bots and fake impressions and cliks.

Is there a way to filter fake impressions and clicks? Or is there a third-party tool that I can use to measure?