We investigate the merging rates of compact binaries in galaxies, and the related detection rate of gravitational wave (GW) events with AdvLIGO/Virgo and with the Einstein Telescope. To this purpose, we rely on three basic ingredients: (i) the redshift-dependent galaxy statistics provided by the latest determination of the star formation rate functions from UV+far-IR/(sub)millimeter/radio data; (ii) star formation and chemical enrichment histories for individual galaxies, modeled on the basis of observations; (iii) compact remnant mass distribution and prescriptions for merging of compact binaries from stellar evolution simulations. We present results for the intrinsic birthrate of compact remnants, the merging rates of compact binaries, GW detection rates and GW counts, attempting to differentiate the outcomes among BH-BH, NS-NS, and BH-NS mergers, and to estimate their occurrence in disk and spheroidal host galaxies. We compare our approach with the one based on cosmic SFR density and cosmic metallicity, exploited by many literature studies; the merging rates from the two approaches are in agreement within the overall astrophysical uncertainties. We also investigate the effects of galaxy-scale strong gravitational lensing of GW in enhancing the rate of detectable events toward high-redshift. Finally, we discuss the contribution of undetected GW emission from compact binary mergers to the stochastic background.