How is Battles Won counted?

My four maxed 98+% Machamps have a combined 30,000+ battles won but my Battle Girl badge displays only 15,000+ battles won.

I want to say the battle girl badge only counts attacking gyms, but the individual mon’s battle won stat counts attacking and defending, but I’m probably wrong

I believe all of the Pokemons in your team which is used to attack the gym get the record. E.g. 6 Machamp in one team, all of them win one battle even though you only used the first one