Note that using a tool like Onyx to frequently "clean" your Mac is potentially more harmful than useful. That is something that should be done for troubleshooting only. See The myth of the dirty Mac.
As to the ad problem, there's no good reason for resetting Safari or cleaning the machine with Onyx to fix that problem, unless you were visiting sites that all used the same advertising company, which was using cookies to determine how to target your browser. Those sites would all have to be complicit in displaying the ads... nothing that would have been cleared using these techniques could have injected ads into sites that didn't explicitly support them.
If the ads come back, look for more solutions in Eliminating browser redirects and advertisements.