Add analytics middleware