G protein-coupled receptors (GPCRs) are well known to signal via cyclic AMP (cAMP) production at the plasma membrane, but it is now clear that various GPCRs also signal after internalization. Apart from its temporal impact through prolonging the cellular response, we wondered whether the endosome-initiated signal encodes any discrete spatial information. Using the β2-adrenoceptor (β2-AR) as a model, we show that endocytosis is required for the full repertoire of downstream cAMP-dependent transcriptional control. Next, we describe an orthogonal optogenetic approach to definitively establish that the location of cAMP production is indeed the critical variable determining the transcriptional response. Finally, our results suggest that this spatial encoding scheme helps cells functionally discriminate chemically distinct β2-AR ligands according to differences in their ability to promote receptor endocytosis. These findings reveal a discrete principle for achieving cellular signaling specificity based on endosome-mediated spatial encoding of intracellular second messenger production and 'location-aware' downstream transcriptional control.