Google (GOOG) will pay a $391.5 million settlement after over 40 states alleged that the tech giant illegally tracked users' locations.

The company was accused of violating state consumer protection laws by tracking consumers, including when their location tracking settings were turned off.

The investigation was led by Oregon and Nebraska and comes as state attorney generals have recently become more aggressive in targeting the firm's user tracking practices. The settlement is the largest consumer privacy settlement by states in U.S. history.

"For years Google has prioritized profit over their users' privacy," Ellen Rosenblum, Oregon's attorney general, said in a press release.

"They have been crafty and deceptive. Consumers thought they had turned off their location tracking features on Google, but the company continued to secretly record their movements and use that information for advertisers."

According to the Iowa attorney general's office, the settlement also requires Google to be more transparent regarding location tracking, letting consumers know when they are being tracked and giving them detailed information about the type of location-tracking data the company is collecting.

"When consumers make the decision to not share location data on their devices, they should be able to trust that a company will no longer track their every move," Iowa's attorney general Tom Miller said in a statement. "This settlement makes it clear that companies must be transparent in how they track customers and abide by state and federal privacy laws."

Large tech companies have faced backlash for using location-tracking data to provide more relevant advertising to consumers.

Google, owned by parent company Alphabet, previously settled a similar suit brought by the state of Arizona for $85 million. Indiana, Texas, Washington, and the District of Columbia also sued the company in January over deceptive location-tracking practices.

"Consistent with improvements we've made in recent years, we have settled this investigation which was based on outdated product policies that we changed years ago," Google's policy communications manager Jose Castaneda said.

Other tech companies have also faced consequences for failing to protect users' privacy. Meta was fined over $400 million by Ireland's Data Protection Commission in September for failing to safeguard children's private information on Instagram. Amazon was hit with a record $888 million fine last summer due to violations of the EU's data protection laws.

In the first half of 2022, Google reported revenue of over $111 billion from advertisers. Google has said it will change its location tracking disclosures in 2023.

As of Monday at 3:13 p.m. ET, shares of Alphabet were trading at $96.84, up $0.11, or 0.11%.