I.e. indicates that is, and, e.g. means for example.
How to fix it
Whenever you write it, reread the sentence in your head with the full version, that is where the shortened version (i.e.) is. If it doesn’t make sense, then change it.
While not a universally used convention, I recommend punctuating like this:
Why? If you were writing for example in a sentence, how would you write it?
For example, that is,
You would include commas, right? So why wouldn’t you contain commas in the shortened versions? Plus, you look like you know about grammar, and that’s always a positive.