The discovery of GW170817, the merger of a binary neutron star (NS) triggered by a gravitational wave detection by LIGO and Virgo, has opened a new window of exploration in the physics of NSs and their cosmological role. Among the important quantities to measure are the mass and velocity of the ejecta produced by the tidally disrupted NSs and the delay - if any - between the merger and the launching of a relativistic jet. These encode information on the equation of state of the NS, the nature of the merger remnant, and the jet launching mechanism, as well as yielding an estimate of the mass available for r-process nucleosynthesis. Here we derive analytic estimates for the structure of jets expanding in environments with different density, velocity, and radial extent. We compute the jet-cocoon structure and the properties of the broadband afterglow emission as a function of the ejecta mass, velocity, and time delay between merger and launch of the jet. We show that modeling of the afterglow light curve can constrain the ejecta properties and, in turn, the physics of neutron density matter. Our results increase the interpretative power of electromagnetic observations by allowing for a direct connection with the merger physics.