Depends where you buy it from.
Take The Witcher 2 for example, if you buy it from the store, the profits get divided and distributed to the store you bought it from, the publisher, the developer, and a few others. Most of the time the developer gets very little.
If you buy it off, say Steam, it gets divided between Steam, the Publisher, and Developer. A bit more evenly split, but it depends on the terms you set with the publisher/Steam.
If you buy it off GoG.com, most of it goes to the developer, while some goes to the publisher. I think, all may go to the developer.
So in short, to make sure the developer gets the most profit, try to buy directly from them.