added conditional analytics logic