Rhogam?

Okay ladies... I was spotting for 5 days... went to the ER and they confirmed that I was miscarrying... they gave me the Rhogam shot after my miscarriage... was I supposed to get it before or after the miscarriage??