A factory reset should remove any tracking or spy app in your phone. Just make sure to backup all the information you don't want to lose since the reset will also delete all personal data. I'd recommend you to change your main passwords, specially in your Google account.