When is a fianchetto strategic to play? I know that some openings include fianchettoing the bishop. But sometimes, this isn't part of the opening, but I still need to decide whether to bring my bishop one rank forward (like Bg7) or to the other side of the board (like Bc4).
Someone told me that usually the fianchetto is useless if you push the center pawn closer to the fianchetto's bishop.
What should I look for to decide whether I should fianchetto or bring my bishop further up the board?
Edit
As an example, in the Sicilian as Black, I usually do 1. e4 c5 2. Nf3 d6. At this point, I've already moved two pawns, so I am not going to do e5.
In a lot of cases you just rely on your intuition. With enough experience you can tell whether a fianchetto makes sense in setups like the Sicilian. But here are some tips for when to do it:

If the long diagonal is open, since the bishop will not be blocked along it.
If your opponent doesn't have a bishop on the same colour as the soon to be fianchettoed bishop. This will make it more difficult for your opponent to trade off your bishop. Note that if the bishop does get traded off, it's not a huge deal, but now there's a hole in front of your king.
If the bishop has no responsibilities on its normal diagonal of development. E.g., in the Sicilian, if you've pushed ...d6 and then either ...e6 or ...e5, your bishop is often important in defending the d6-pawn. So fianchettoing it here usually isn't recommended. But if the e-pawn is left on e7 (like in the Dragon), there are no issues with the d6-pawn when you fianchetto.
If it would take two moves to develop the bishop anyway along the normal development diagonal. I.e., if your e-pawn hasn't moved yet, you'll have to spend a tempo pushing it and then bringing out the bishop. This means that if you go for the fianchetto, at least it won't waste any extra time.

All of these guidelines can absolutely be broken though. They are just some things to factor into your decision -- each position should be treated on a case by case basis.