Rhogam shot

So I’m supposed to get the rhogam shot at 28 weeks and then again up to 72 hours after birth if the baby is rh+

My question is do you really need to have the shot at 28 weeks? Can’t you just wait until birth to see if it’s needed? Or do you really need both?