SAN FRANCISCO — Wiretapping is typically the stuff of spy dramas and shady criminal escapades. But now, one of the world’s biggest Web companies, Google, must defend itself against accusations that it is illegally wiretapping in the course of its everyday business — gathering data about Internet users and showing them related ads.

The accusations, made over several years in various lawsuits that have been merged into two separate cases, ask whether Google went too far in collecting user data in Gmail and Street View, its mapping project. Two federal judges have ruled, over Google’s protests, that both cases can move forward.

The wiretapping rulings are the latest example of judges and regulators prodding Google over privacy violations. The company is on the defensive, struggling to persuade overseers and its users that it protects consumer data, while arguing that the law is stuck in the past and has failed to keep up with new technologies.

“It’s been a bad month for Google,” said Alan Butler, a lawyer at the Electronic Privacy Information Center. “What’s at stake is a core digital privacy issue for consumers right now, which is the extent to which their digital communications are protected from use by third parties.” For the most part, Google has managed to avoid major privacy penalties. The Gmail case could have broad effects, though, because nearly half a billion people worldwide use the service, and because if it is, as expected, certified as a class action, the fines could be enormous. At the same time, the case could have long-term consequences for all e-mail services — including those from Yahoo and Microsoft — and for the issue of how confidential is online data.