privacy – How does Facebook know which websites I’ve visited and what technology does it use to do so?

I’ve been using Facebook for quite a while and have noticed that it keeps an eye on my browsing habits. Facebook also recommends me videos and other content based on my locality. I use Facebook only on my phone and have its GPS location disabled for all apps and websites. Even though I have all permissions disabled for the Facebook app, I start seeing ads related to a product I’d searched for in my feed. Even as a programmer, I am unaware of any way to track the end user’s browsing habits (except for getting their IP address). I want to know about the technology Facebook implements to track its users across the web.