So after that, every time they open the app, it'll match their user ID in the database and I'll be able to see how many times they've accessed it?
Well that's a different thing. You could add that on if you wanted to.
Two things from the advertizing.
1) The refferal ID (who reffered them, google, fb, a forum, that is based on what you put in the second /*/)
2) generate a unique id (usually an md5 hash of the machine id + time in miliseconds).
It takes those and creates a cookie on the user side, you can also add to the database that the person has accessed the landing page and their id/cookie-id.
The landing page links to your FB app download page.
Once they've installed the FB app and ran it, the app will check to see if the user has a cookie containing a ref id and a unique id. If it does it will then add to the database that such and such id+cookie has actually commited to isntalling the fb app. But you want to remove the cookie at that point so that it doesn't add to the database again the next time they run the app.
From there you now have in the database who reffered them, and if they actually installed the app or not.
From there you could additionally add to a database their actual FB username and keep a tally of how many times they use the app if that is important to you. But thats a seperate issue all together from the 'tracking' of reffers and installation.
You have any experience with PHP/MySQL? Or Cookies/Sessions in PHP for that matter?