Enhanced Analytics Code

Moved the `if statement` to its own section to make it easier to read