I'm not sure it can stay out of them.
Anyway, the Spanish American colonies stay with Spain, which is always good. It depends on what direction Spain swings, liberalism or absolutism, how soon the Spanish American colonies secede. I think them seceding is almost a certainty, though, I find it impossible to imagine Spain controlling half a continent and all of Central America until the modern time. Maybe Spain forms a Commonwealth like Britain did?
If Spain isn't devastated in the Napoleonic Wars, it would be in a much better position economically and politically. If any independance movements would rise, I'm sure Spain could squash them.