added async, moved analytics code