  The fully-differential beam function (dBF) is a universal ingredient in
resummed predictions of hadron collider observables that probe the full
kinematics of the incoming parton from each colliding proton -- the virtuality
and transverse momentum as well as the light-cone momentum fraction $x$. In
this paper we compute the matching coefficients between the unpolarized gluon
dBF and the usual parton distribution functions (PDFs) at the two-loop order.
For observables probing both the virtuality and transverse momentum of incoming
gluons, our results provide the part of the NNLO singular cross section related
to collinear initial-state radiation, and are required for the resummation of
large logarithms through N$^3$LL. Further to this, the dBF is closely linked to
the beam function appearing in a generalized version of threshold
factorization, via a simple integration. By performing this integration for the
two-loop gluon matching coefficients, we also obtain the corresponding
quantities for the generalized threshold beam function.
