added analytics logic