Your simplest solution is probably to use shapekeys and animate them. For this, you'll need to work backwards. First, animate your beer liquid (the nonfoamy part) from start to end; if you want your foam to keep foaming after the liquid stops pouring, make sure to add some frames for padding at the end. On the final frame, model your end result foam and add it as a shapekey. Then without adding or subtracting any vertices, model it to a new shape a little further up the glass and a little less foamy, and make a shapekey for that. Continue on in this manner until you reach the beginning of your foam. To finish up, either scale everything to zero and add a final shapekey for it, or add a transparent shader to to your material setup and keyframe a mix node at the appropriate points.
Now the fun part! Go along your animation and tweak your shape keys at whatever points you feel necessary, playing with the sliders. When you have something you want, keyframe all the strength sliders.
I hope this helps! Happy Blending!