WASHINGTON — The Department of Homeland Security will soon begin collecting social media data from all immigrants entering the United States, part of what agency officials call an effort to more effectively screen those coming to the country but privacy advocates see as an unnecessary intrusion that would do little to protect national security.

The department will begin collecting the information on Oct. 18, the same day the Trump administration’s new travel ban on citizens of seven countries and restrictions on those from two others are set to take effect.

Green card holders and naturalized citizens will also have their social media information collected, with the data becoming part of their immigration file. It was unclear whether the monitoring would take place only in the application process or could continue afterward.

The department published the new requirement in the Federal Register last week, saying it would collect “social media handles, aliases, associated identifiable information and search results,” which would be included in an applicant’s immigration file. It said the data would come from “publicly available information obtained from the internet, public records, public institutions, interviewees, commercial data providers.”