  (Abridged) We present a large sample of o-H$_2$D$^+$ observations in
high-mass star-forming regions and discuss possible empirical correlations with
relevant physical quantities to assess its role as a chronometer of
star-forming regions through different evolutionary stages. APEX observations
of the ground-state transition of o-H$_2$D$^+$ were analysed in a sample of
massive clumps selected from ATLASGAL at different evolutionary stages. Column
densities and beam-averaged abundances of o-H$_2$D$^+$ with respect to H$_2$,
$X$(o-H$_2$D$^+$), were obtained by modelling the spectra under the assumption
of local thermodynamic equilibrium. We detect 16 sources in o-H$_2$D$^+$ and
find clear correlations between $X$(o-H$_2$D$^+$) and the clump bolometric
luminosity and the dust temperature, while only a mild correlation is found
with the CO-depletion factor. In addition, we see a clear correlation with the
luminosity-to-mass ratio, which is known to trace the evolution of the star
formation process. This would indicate that the deuterated forms of H$_3^+$ are
more abundant in the early stages of the star formation process and that
deuteration is influenced by the time evolution of the clumps. In this respect,
our findings would suggest that the $X$(o-H$_2$D$^+$) abundance is mainly
affected by the thermal changes rather than density changes in the gas. We have
employed these findings together with observations of H$^{13}$CO$^+$, DCO$^+$,
and C$^{17}$O to provide an estimate of the cosmic-ray ionisation rate in a
sub-sample of eight clumps based on recent analytical work. Our study presents
the largest sample of o-H$_2$D$^+$ in star-forming regions to date. The results
confirm that the deuteration process is strongly affected by temperature and
suggests that o-H$_2$D$^+$ can be considered a reliable chemical clock during
the star formation processes, as proved by its strong temporal dependence.
