I am not sure I can agree to this as an answer.
It feels to reductionistic, humans are complex system and often none rational.
Certainly religions provide utility to the followers, but I wouldn't equate wealth of a country as direct correlation to religiosity.
There are wealthy countries (US, gulf counties) that are largely religious, and smaller poorer (czech rep) countries predominately atheistic.
I think religion is more of an entertainment then meaning of life. in poorer counties there is less things to be occupied with. Thats where you have the festivals and celebrations. Contrast catholics in EU vs South America.
Also religion can be seen as a stop gap solution to education. It provides answers to questions - knowledge (though of varying quality). The higher education the lower interest in religion, for one the science + critical thinking exposes errors and fallacies in religious texts. So religion as a source of knowledge looses appeal in educated populations.