Stipulating that advertising revenue on his website depends on the number of visitors
The contract described in the question is a contract that is based on reward and there is nothing wrong with it from a shar’i point of view, so long as the ads are free of haraam content and do not help with haraam things.
Among the permissible forms of reward-based contracts that the fuqaha’ have mentioned is when someone says: “Whoever brings back my stray camel will have such and such”. The evidence that reward-based contracts are permissible is the verse in which Allaah says (interpretation of the meaning):
“They said: ‘We have lost the (golden) bowl of the king and for him who produces it is (the reward of) a camel load; and I will be bound by it’”
[Yoosuf 12:72]
There is scholarly consensus that it is permissible. This was narrated by more than one of the scholars, including Ibn Qudaamah in al-Mughni (6/20), where he said: We do not know of any difference of opinion concerning that.
A reward-based contract is similar to a hiring contract, but the rules are more relaxed, therefore a reward-based contract is valid even though the type of work in question is not known, as in the case of returning a lost camel: it may be returned after a lot of work or a little.
Another example is the case asked about here: You do not know how many users will click on those ads.
So long as the financial reward is stipulated in return for each user clicking on the ads, there is nothing wrong with it from a shar’i point of view.
But the content of these ads should be known, so that they will not be ads for haraam things; in that case it is haraam to advertise them or to take any payment for that, because Allaah says (interpretation of the meaning):
“… do not help one another in sin and transgression”
[al-Maa’idah 5:2]
For more information please see the answer to question no. 101806.
And Allaah knows best.