The ruling came as a result of Viacom's legal action against Google - owner of the YouTube video site - over alleged copyright infringement. The court case is taking part in the US, but it's expected that Viacom will look to enforce it globally. Viacom is the owner of TV and movie makers MTV and Paramount.
Google now has to divulge the 'viewing log' details to Viacom. As well as user ID, the log contains details of each video watched, and the IP address used.
Viacom claims that YouTube regularly infringes copyright. It initiated the court case in March last year after, it says, finding around 160,000 clips of its content on YouTube. According to Viacom, the unauthorised clips had been viewed around 1.5 billion times.
At the time YouTube believed it wasn't responsible for its users' actions, but in a bid to escape the legal action it introduced video filtering tools to keep unauthorised content off the site.
Now Google will have to hand over the details of all its users, which is believed to be around 12TB of data. Google must also disclose to YouTube the details of all videos that have been ever appeared on the site and been removed.
Privacy and liberty campaigners have expressed outrage at the divulging of such data.