We use the past perfect to indicate a past event or situation which occurred before another past event or situation.
He's been awake for quite a while before the alarm rang.
Although we arrived on time, Andy had already started working.
Note: A time conjunction sometimes replaces the past perfect to show which of the two past events occurred first. In this case both events can be in the simple past tense.
Nigel called me before he left.
PAST PERFECT CONTINUOUS
We use the continuous form when we want to emphasize the continuity and duration of this event.
Greg had been trying to get a job for over a year before he was offered his present one.