I had a history professor some 35+- years ago who spent some weeks on the subject. I found it interesting so I still remember the basics of his argument. I don't have all the data that he presented to support his thesis but the fundamentals go like this:
Religion is a development of civilization. There is no common belief system until you have large numbers of people who interact with each other. Nomads and hunter-gathers and such have beliefs but don't formalize it because everything is based on their own experience.
Civilization always begins at river deltas because that is where the best soil gathers and it is easier to generate good crops. Once people start taking ownership and responsibility for food sources you have the basis for a civilization.
Leaders emerge, usually because they can make everybody else believe that they are more likely to be correct than them. In an agrarian society, knowing the flood times of the river are critical. The brighter leaders, who can predict the flood schedule, can also make guesses on other things with some authority. At this point it is good to have a god. The god only talks directly to the leader and is the authority behind the guesses. This means that the leader doesn't have to explain a lot or convince the sheeple. God said it, I believe it, you do it. Now comes the fun part...
If you have a river like the Tigris-Euphrates, which has an erratic flooding schedule, the god(s) CAN'T be wrong; they're pissed off because the sheeple did something wrong. You end up with an angry, vengeful deity with no sense of humor whatsoever. If you have a river like the Nile, where you can set your watch on the flood times, you end up with fairly non-hostile animistic gods. Vagaries of nature are just whimsy of the deities. In the long run, the god(s) are just an authority figure that can be used as a control mechanism. In societies where other control mechanisms are stronger, gods tend to be less defined and powerful. They are still a good black box way for people to explain things that don't make normal sense to them.
That is a very rough overview of his thesis. He presented a lot of data on expansion of civilization and related it back to human behavior patterns. I found it both interesting and persuasive. YMMV.
The profs name was Dr. Faust. He was a lawyer who was clobbered in the McCarthy era, who subsequently went back to get a doctorate in history. Interesting guy. One of my favorite professors.