It is permissible to go to the gym prior to immersing in the mikveh. The custom is to avoid sticky substances on mikveh day or other activities that will get in the way of
preparations. So long as you take care to do a proper preparation subsequent to your exercise, there should not be a problem.
Try to think ahead to avoid problems. (For example, remove make-up prior to working out, etc.) If you find somehow that sweatiness is not easily reversed in the shower, as with matted hair, then you should seek a solution prior to scheduling mikveh this way again.