updated code for analytics