In my personal experience in Vancouver (from some years back), it is Check-in -> Immigration -> Customs. (They won't let you go to the immigration desk without the boarding pass; and customs always  follow immigration, in US airports or border crossings as well). If one flies e.g. YHZ-YUL-EWR, one checks in in Halifax, but only goes thru US immigration and customs in YUL, on the way to his US-bound flight.