Add it after the fermentation has stopped.
I use a half a 1/4 ounce packet per five gallons. I suspend it in about 3/4 cup of cold water, then heat it to near boiling in the microwave, stopping to stir it every once in a while. If you bring it to a boil, you will get lumps which will be wasted. Then I dilute it with a bit of beer and stir it into the carboy, stirring with a racking cane.
There are people who say not to boil it because it will denature the proteins. That is silly. Gelatin is denatured proteins. It's prepared by boiling. Further boiling won't hurt it at all, but it will make lumps that you can't easily get rid of.
It's really cool to watch the beer settle out from the top down, hour by hour. A flashlight helps.