Not a wordpress questions really. You will get much better responses at stackoverflow.com. However you instigated my curiosity… you can get the referral url by using the following javascript:
document.referrer
You could add that to your current AD script to check if the document.referrer == “some url” before displaying the ad.
See more examples here