We investigate the superfluid-insulator quantum phase transition in a disordered one-dimensional Bose gas in the mean-field limit by studying the probability distribution of the density. The superfluid phase is characterized by a vanishing probability to have zero density, whereas a nonzero probability marks the insulator phase. This relation is derived analytically and confirmed by a numerical study. This fragmentation criterion is particularly suited for detecting the phase transition in experiments. When a harmonic trap is included, the transition to the insulating phase can be extracted from the statistics of the local density distribution.