Gonna is extremely informal [some would say sub-standard, at least in writing], so there are no hard rules for its use. I would use it, in speaking, only before a bare infinitive (as you said, it replaces 'going to'). It is often preceded by 'a': I'm a-gonna do this or that.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.