Assume that the pair $Z,M$ is oriented. There are two cases: If $Z$ represent a non-vanishing $n-1$-cycle, then the map
$H^{n-1}(M)\to H^{n-1}(Z)\stackrel{\int_Z}{\to} \mathbb{R}$ is onto by Poincare duality (the restriction of a cocycle to $Z$ and integrating is like cupping with the poincare dual of $Z$ which can not anihilate the cup pairing).
In that case the long exact sequence of the pair $(Z,M)$ gives us an isomorphism $H^n(M,Z)\cong H^n(M)$ and the invariant is the integral.
In the case where $0=[Z]\in H_{n-1}(M)$ we can find a domain $U$ in $M$ such that $Z=\partial U$. Then, we can consider the invariant $\mu\mapsto \int_U \mu$. Note that this is well defined only on forms with total integral $0$ because we can replace $U$ by its complement, but once we have chosen $U$ we can consider the map $\alpha \mapsto (\int_U \alpha, \int_M \alpha)$ which gives us a map $H^n(M,Z)\to \mathbb{R}^2$.
Note that the first is well defined because it vanishes in forms of type $d\beta$ with $\beta|_Z=0$ by Stokes formula.
Moreover, the idea to consider this functional is by formally interpret the long exact sequence of the pair: We take a form $\alpha$ with total integral $0$ and write it as $d\beta$ for $\beta$ not nessesarily $0$ on $Z$. Then its class in $H^{n-1}(Z)$ is exactly the preimage of $\alpha$ in $H^{n-1}(Z)$, and this is well defined only modulo $H^{n-1}(M)$ since we could add a closed form to $\beta$. But the class of $\beta$ in $H^{n-1}(Z)$ is represented by its integral, which by stokes theorem is exactly the integral of $\alpha$ on $U$, so we don't really need to choose $\beta$ to compute it!