There are many ways in which musicians get paid. For advertising music in particular, aside from upfront fees, most of the time back-end royalties and other residuals can be collected.

Below are links to a few resources for further reading.

Publisher and Composer Royalties Collection Societies:

ASCAP

BMI

SESAC

Unions:

American Federation of Musicians

SAG-AFTRA

Performance Royalties Collection Society (digital only):

SoundExchange