From my personal understanding, I think it is most important to take it immediately after a weight training workout, within an hour at least (I take mine as I’m walking out of the gym).
After cardio, your body wants/needs some variation of good carbs, protein isn’t a necessity because you’re not repairing broken muscle tissue.
Personally, I still take it after a cardio session because I use a protein shake as one of my six meals of the day.
There are also different kinds of protein, such as Whey or Casein. I use a Whey Protein Isolate for post-workout (this is digested out of your body in about an hour) and Casein protein (only after heavy-duty days) right before bed, it digests in about 6 hours and feeds your sore muscles overnight!