Google Analytics works by tracking user activity on a website through the use of a tracking code. This code collects data such as pageviews, bounce rates, user demographics, and more. This data is then aggregated and presented in various reports, allowing businesses to analyze website performance and user behavior.