As has been stated, $M \rightarrow G$ factors via the group completion $\hat{M}$. Furthermore, since $G$ is abelian, the map $\hat{M} \rightarrow G$ factors via the abelianization $\hat{M}/[\hat{M},\hat{M}]$ of $\hat{M}$. Since the composite of the maps $M \rightarrow \hat{M} \rightarrow \hat{M}/[\hat{M},\hat{M}]$ is already known, $f$ is uniquely determined by the map $\hat{M}/[\hat{M},\hat{M}] \rightarrow G$, so we may assume $M$ to be an abelian group. Since $f = 0$ gives us no information, we may assume that $f$ is onto. Suppose we have a $G$ so that $f$ factors via it, and let us write $f = pg$, where $g \colon M \rightarrow G$ and $p \colon G \rightarrow \{0,1\}$. By $f = pg$ we must necessarily have $\ker(g) \subset \ker(f)$, so that $g$ is isomorphic to the canonical projection $M \rightarrow M/N$, where $N$ is a subgroup of $\ker(f)$. In addition, $|G|$ must be even. (If $f$ is onto, $p$ must take on the values $0$ and $1$ equally, since $|G| = 2|ker(p)|$.) I claim this is all $f$ tells you. Given $f$, we've just shown that we must have that $g$ is isomorphic to modding out by a subgroup of $\ker(f)$, and that $|G|$ is even. Conversely, given any map $g \colon M \rightarrow G$, whose kernel is a subgroup of $\ker(f)$, and such that $|G|$ is even, then the image of $\ker(f)$ will be of index 2 in $G$, so we can just compose this map with the map that mods out the image of $\ker(f)$ in $G$.