(this is an edit made after user65432 caught me assuming implicitly that $G$ is connected.)
In case $G$ is connected, $f=0$ iff $\mathfrak{g}$ has no center. This provides an answer toIn the general case, (1) and$G/G^0$ acts on the answer tocenter $\mathfrak{z}<\mathfrak{g}$ and $f=0$ iff there are no invariant vectors for this action (2$G^0$ denotes here the connected component of $G$).
An example for the latter case is "yes"$G=\{-1,1\}\ltimes S^1$, where $f=0$ though $\mathfrak{g}$ has a one dimensional center.
The proof is standard:
For every finite dimensional representation $\rho\colon G\to \text{GL}(V)$, $f(v)=\int \rho(g)vdg$ gives a linear operator on $V$ which is the projection on the subspace of invariants $V^G$ (clearly the image of $f$ consists of invariant vectors and $f$ is the identity on invariant vectors). For
Specializing to $\rho=\text{Ad}$, and noting that $\mathfrak{g}^G$ is$\mathfrak{z}=\mathfrak{g}^{G^0}$ gives the center of $\mathfrak{g}$answer.