The ratio of the $B^0_s$ and $B^0$ fragmentation fractions, $f_s/f_d$, in proton-proton collisions at the LHC, is obtained as a function of $B$-meson transverse momentum and collision centre-of-mass energy from the combined analysis of different $B$-decay channels measured by the LHCb experiment. The results are described by a linear function of the meson transverse momentum, or with a function inspired by Tsallis statistics. Precise measurements of the branching fractions of the $B^0_s to J/psi phi$ and $B^0_s to D^-_s pi^+$ decays are performed, reducing their uncertainty by about a factor of two with respect to previous world averages. Numerous $B^0_s$ decay branching fractions, measured at the LHCb experiment, are also updated using the new values of $f_s/f_d$ and branching fractions of normalisation channels. These results reduce a major source of systematic uncertainty in several searches for new physics performed through measurements of $B^0_s$ branching fractions.