WASHINGTON — The federal government is collecting electronic records on the travel habits of millions of Americans who fly, drive or take cruises abroad, retaining data on the people with whom they travel or plan to stay, the personal items they carry during their journeys and the books travelers have carried, according to documents obtained by a group of civil-liberties advocates and statements by government officials.

The personal travel records are meant to be stored for up to 15 years as part of the Department of Homeland Security’s (DHS) effort to assess the security threat posed by all travelers entering the country.

Officials say the records, which are analyzed by the department’s Automated Targeting System, help border officials distinguish potential terrorists from innocent people entering the country.

But new details about the information being retained suggest the government is monitoring the personal habits of travelers more closely than previously acknowledged.

Most Read Stories

The details were learned when some activists requested copies of official records on their own travel. Those records included a description of a book on marijuana that one carried and small flashlights bearing the symbol of a marijuana leaf.

The Automated Targeting System (ATS) has been used to screen passengers since the mid-1990s, but the collection of data for it has been greatly expanded and automated since 2002, according to former DHS officials.

Officials Friday defended the retention of personal data on travelers not involved in or linked to any violations of the law.

But civil-liberties advocates have alleged that information preserved by the department raises alarms about the government’s ability to intrude into the lives of ordinary people. The millions of travelers whose records are kept are generally unaware of what their records say, and the government has not created an effective mechanism for reviewing the data and correcting errors, activists said.

The activists alleged that the data collection, as carried out now, violates the Privacy Act, which bars the gathering of data related to Americans’ exercise of their First Amendment rights, such as their choice of reading material or persons with whom they associate. They also expressed concern that such personal data could be used to impede their right to travel.

“The federal government is trying to build a surveillance society,” said John Gilmore, a civil-liberties activist in San Francisco whose records were requested by the Identity Project, a group of privacy advocates in California and Alaska.

The government, he said, “may be doing it with the best or worst of intentions. … But the job of building a surveillance database and populating it with information about us is happening largely without our awareness and without our consent.”

Gilmore’s file included a note from a Customs and Border Patrol officer that he carried the marijuana-related book “Drugs and Your Rights.”

DHS officials said this week that the government is not interested in passengers’ reading habits, that the program is transparent and that it affords redress for travelers who are inappropriately stymied.

“I flatly reject the premise that the department is interested in what travelers are reading,” DHS spokesman Russ Knocke said.

But, Knocke said, “if there is some indication based upon the behavior or an item in the traveler’s possession that leads the inspection officer to conclude there could be a possible violation of the law, it is the front-line officer’s duty to further scrutinize the traveler.”

The DHS database generally includes “passenger name record” (PNR) information and notes taken during secondary screenings of travelers.

PNR data — often provided to airlines and other companies when reservations are made — routinely include names, addresses and credit-card information, as well as telephone and e-mail contact details, itineraries, hotel and rental-car reservations, and the type of bed requested in a hotel.

The records the Identity Project obtained confirmed that the government is receiving data directly from commercial-reservation systems, such as Galileo and Sabre, but also showed that the data, in some cases, are more detailed than the information to which the airlines have access.

Ann Harrison, the communications director for a technology firm in Silicon Valley who was among those who obtained their personal files, said she was taken aback to see her dossier contained data on her race and on a European flight that did not begin or end in the United States or connect to a U.S.-bound flight.

“It was surprising that they were gathering so much information without my knowledge on my travel activities.”