This ad functionality is not a bug, but a normal feature of some ads. These ads automatically bring you to the store where you are prompted to download after seeing the ad, but you will not leave the game.
 
The advertised apps will not download automatically, but if you have other questions about these ads please let us know!