They can do it because the user is logged in in all those apps. It's the same apple ecosystem. The problem is really that Facebook tracks you outside their ecosystem. App developers and website marketers have been willing to sell out their users to Facebook and Google in return for some analytics.