App store doesn’t, the app itself does, that’s why this thing is included in it.
You click an ad on FB = you’re ID’d by a cookie or login or account on the device or fingerprint or whatever (probably all of the above)
You install the app from app store. Neither the bank or FB knows this.
You launch the app. The integrated FB library reads the cookie or FB account on the device or whatever it can, and pings FB. FB compares this ID to the entries and finds that it was you who clicked the ad.
FB bills bank for an ad click
Another option is there to be a specific FB variant of the app with its own app store entry, but they probably wouldn’t do that for something this trivial.