It goes without saying, that you need an IR beam, its wavelength matched to the phototransistor's peak detection, which will be interrupted when the objects being counted crosses it.
Having said that, I would use a phototransistor with a visible-light filter, which the BPW77 does not have. Otherwise stray light may falsely trigger it.