How can I keep my electrolytes up during triathlons?

Training. Same way you do in training. Race the way you train.You should have a regular fluid intake plan throughout the event, whether training or racing.Much depends on the length of the event.Sprints, not so much. Olympics , more attention and halfs/ fulls, extreme attention. Training should include fluid /food intake at planned times. Gels, gatorade, water, banana, etc. You need to be able to digest on fly.
Drink sports drinks. Staying hydrated and replenishing electrolytes are important to avoid cramps and hitting the wall (aka "bonking") during races. There are a number of products out there, but its hard to say which one is best because we all lose different amounts when we sweat. If you aren't voiding (urinating, peeing) you aren't drinking enough. If you aren't sweating, it can be an early sign of heat stroke.