Global compactness results for nonlocal problems