Step 1: Materials list
Zipper pull (hopefully the original that came off the zipper in the first place)
Hot glue gun
Step 2: Thread the zipper
One of the tracks should be slightly longer than the other, as they are staggered. Start with that track and feed into one of the 2 branches of the "Y", with the zipper pull facing out. Once you have the first track started, feed the other track into the other branch of the "Y".
Take your time with this step, you want the teeth to be able to mesh properly.
Step 3: Test and confirm the zipper can close again
Step 4: Gluing
Use the hot glue gun to seal the hole/tear where the zipper first came undone and reattach the end of the zipper to the inside lining of the bag.
Once the zipper is reattached to the inside lining of the bag, leave a large dot of glue at the very end of the zipper track. This both reinforces the end of the zipper, and gives a solid "stopper" for the zipper so it doesn't come off the track again.
Step 5: Completed!
For this bag, I actually reversed the direction of the zipper, but the teeth met up just fine and the glue is holding strong!