I know what you're going through. I'm going through the same thing myself, only what started out as innocent, ending up physical for me. The first thing you have to ask yourself is what need your wife wasn't meeting that your online friend was. Then tell your wife. I'm not saying it's her fault for not meeting your need (I’m sure there are many needs of hers that you are failing to meet), but you should have had that conversation a long time ago (just like me).
I'm not with my wife right now (we want to be together, but I'm in the military), but we're making great progress. I'll see her next week for the holidays and I plan on telling her everything about my past (there’s a lot she doesn’t know yet). That will be a bad day indeed. But I know that you cannot rebuild a marriage on a foundation of lies. I’d rather face insurgents with rockets than my wife with the truth, but I know it has to be done.
Make sure she knows everything about you, every secret, every skeleton, everything. Find resources out there about how to fall in love and stay in love. Books like "His Needs, Her Needs" and "Every Man's Marriage" might get you on the right track. Don't think for one second that just because you didn't have sex with the OW that you did nothing wrong and are in the clear. In your BW’s mind (which is all that matters) you did. The betrayal is no different. It doesn't hurt her any less.
She'll ask you a bunch of questions about it, things that seem insignificant, but answer them honestly and fully, don't hold back. She needs this for her own healing, trust me; it's not pleasant, but necessary for her. Even years down the road, she'll still ask about it. So expect that. I'm no expert by any means, but I do have experience in this (unfortunately).
I hope this helps. Just know that you are not alone. We are all here for each other.