How to end a tracker and start a new one when user close the browser?

how to end a tracker and start a new one when user close the browser?