1) you visit to www.somesite.com
2) it serves an ad <iframe src="www.google.com/givemeanad?userforme=waps&hespent=500"
3) your browser does a request to google. It sends:
a) your login cookie from your gmail session (or ...)
b) the referrer header tells it which site to serve the ad on
c) any information the site itself wants to attach to the request
4) Google/Microsoft/Apple store this information and can provide advertisers with your identity, all sites you visit that have their ads, the "flow" (what you visited in what order, e.g. how far did you get in an ordering funnel) and any information those sites share about your account on their site.