Long story short: Facebook Ads optimizes ad delivery based on ROAS (return on ad spent) but return is sales and not profits.
I open sourced the data pipeline to do just that and explained it all here:
https://medium.com/@theo_dot/how-we-increased-shopify-busine...