Track visitors activity based on Login status

I have a custom coded PHP website where I have implemented Piwik tracking code.

I want to track users based on their login status. Like track the pages a user visited, classified according to his login status. Like pages that wrere visited before login and pages that were visited after login.

I am familiar with Custom variables in tracking code. I guess I need to use some custom fields and get desired data from Log_visit and Log_action table. Any pointers ?