Quaternionic automorphic representations are one attempt to generalize to other groups the special place holomorphic modular forms have among automorphic representations of GL2. Like holomorphic modular forms, they are defined by having their real component be one of a particularly nice class (in this case, called quaternionic discrete series). We count quaternionic automorphic representations on the exceptional group G2 by developing a G2 version of the classical Eichler-Selberg trace formula for holomorphic modular forms. There are two main technical difficulties. First, quaternionic discrete series come in L-packets with non-quaternionic members and standard invariant trace formula techniques cannot easily distinguish between discrete series with real component in the same L-packet. Using the more modern stable trace formula resolves this issue. Second, quaternionic discrete series do not satisfy a technical condition of being "regular", so the trace formula can a priori pick up unwanted contributions from automorphic representations with non-tempered components at infinity. Applying some computations of Mundy, this miraculously does not happen for our specific case of quaternionic representations on G2. Finally, we are only studying level-1 forms, so we can apply some tricks of Chenevier and Taïbi to reduce the problem to counting representations on the compact form of G2 and certain pairs of modular forms. This avoids involved computations on the geometric side of the trace formula.