Welcome to Android Central! I'm sorry, but what do you mean by a factory reset through ads you found on your phone? If the phone is resetting due to tapping on some popup ad on your phone, there's a good chance it's due to some malware that you inadvertently installed. Never tap on anything in a suspicious popup.