Multiple factors influence whether rainwater is safe to drink. One factor is the atmosphere it passes through. If you’re in a city where there is air pollution, harmful particles may find their way into your rainwater (source).
The collection system used to gather the rainwater also plays a role in how safe it is to drink. If you collect the rainwater from rooftops, you may be drinking bacteria left behind by bird droppings.
If you’re determined to drink rainwater or you have no other water source available to you at the moment, your best bet is to boil it for at least one minute before drinking it. If you’re in areas of higher elevation, boil it for three minutes.