I know that every rotationally invariant function $f(x,y,z)$ in two-sphere $S^2$ must satisfy \begin{align*} f(x,y,z)=f(h(\theta)(x,y,z)^T) \end{align*} for all $\theta$ and $x,y,z$, where \begin{align*} h(\theta)=\begin{pmatrix} \cos\theta &-\sin\theta\ &0\\ \sin\theta & \cos\theta & 0\\0&0&1 \end{pmatrix}. \end{align*} Here the rotation is assumed to be around $z$-axis.
What I am still confused about is, how to generalize this in case of three-sphere $S^3$? I know that we can somehow use the fact that $S^3$ is a group of unit quaternions but I do not know where to start. Any idea would be appreciated.