API  Examples

 
This section reproduces some of the dimension and metric combinations
 
Visitors and Pageviews Over Time
This query returns the total visitors and pageviews for the specified time period. Note that this query doesn't require any dimensions.
metrics=ga:visits,ga:pageviews
 
Mobile Traffic
This query returns some information about visits which occurred from mobile devices. Note that "Mobile Traffic" is defined using the default segment ID -11.
dimensions=ga:browser,ga:operatingSystem,ga:source
metrics=ga:visits,ga:pageviews,ga:timeOnSite
segment=gaid::-11
 
Revenue Generating Campaigns
This query returns campaign and site usage data for campaigns that led to more than one purchase through your site.
dimensions=ga:source,ga:medium
metrics=ga:visits,ga:pageviews,ga:timeOnSite,ga:bounces
segment=dynamic::ga:transactions>1
 
Visitors
New vs Returning Visits
This query returns the number of new visits vs returning visits.
dimensions=ga:visitorType
metrics=ga:visits
 
Visits by Country
This query returns a breakdown of your visits by country, sorted by number of visits.
dimensions=ga:country
metrics=ga:visits
sort=-ga:visits
 
Browser and Operating System
This query returns a breakdown of visits by the Operating System, web browser, and browser version used.
dimensions=ga:operatingSystem,ga:operatingSystemVersion,ga:browser,ga:browserVersion
metrics=ga:visits
 
Time on Site
This query returns the number of visits and total time on site, which can be used to calculate average time on site.
metrics=ga:visits,ga:timeOnSite
 
Traffic Sources
All Traffic Sources - Usage
This query returns the site usage data broken down by source and medium, sorted by visits in descending order.
dimensions=ga:source,ga:medium
metrics=ga:visits,ga:pageviews,ga:timeOnSite,ga:exits
sort=-ga:visits
 
All Traffic Sources - Goals
This query returns data for the first and all goals defined, sorted by total goal completions in descending order.
dimensions=ga:source,ga:medium
metrics=ga:visits,ga:goal1Starts,ga:goal1Completions,ga:goal1Value,ga:goalStartsAll,ga:goalCompletionsAll,ga:goalValueAll
sort=-ga:goalCompletionsAll
 
All Traffic Sources - E-Commerce
This query returns information on revenue generated through the site for the given time span, sorted by visits in descending order.
dimensions=ga:source,ga:medium
metrics=ga:visits,ga:transactionRevenue,ga:transactions,ga:uniquePurchases
sort=-ga:visits
 
Referring Sites
This query returns a list of domains and how many visits each referred to your site, sorted by pageviews in descending order.
dimensions=ga:source
metrics=ga:pageviews,ga:timeOnSite,ga:exits
filters=ga:medium==referral
sort=-ga:pageviews
 
Search Engines
This query returns site usage data for all traffic by search engine, sorted by pageviews in descending order.
dimensions=ga:source
metrics=ga:pageviews,ga:timeOnSite,ga:exits
filters=ga:medium==cpa,ga:medium==cpc,ga:medium==cpm,ga:medium==cpp,ga:medium==cpv,ga:medium==organic,ga:medium==ppc
sort=-ga:pageviews
 
Search Engines - Organic Search
This query returns site usage data for organic traffic by search engine, sorted by pageviews in descending order.
dimensions=ga:source
metrics=ga:pageviews,ga:timeOnSite,ga:exits
filters=ga:medium==organic
sort=-ga:pageviews
 
Search Engines - Paid Search
This query returns site usage data for paid traffic by search engine, sorted by pageviews in descending order.
dimensions=ga:source
metrics=ga:pageviews,ga:timeOnSite,ga:exits
filters=ga:medium==cpa,ga:medium==cpc,ga:medium==cpm,ga:medium==cpp,ga:medium==cpv,ga:medium==ppc
sort=-ga:pageviews
 
Keywords
This query returns visits broken down by search engine keywords used, sorted by visits in descending order.
dimensions=ga:keyword
metrics=ga:visits
sort=-ga:visits
 
 
Top Content
This query returns your most popular content, sorted by most pageviews.
dimensions=ga:pagePath
metrics=ga:pageviews,ga:uniquePageviews,ga:timeOnPage,ga:bounces,ga:entrances,ga:exits
sort=-ga:pageviews
 
Top Landing Pages
This query returns your most popular landing pages, sorted by entrances in descending order.
dimensions=ga:landingPagePath
metrics=ga:entrances,ga:bounces
sort=-ga:entrances
 
Top Exit Pages
This query returns your most common exit pages, sorted by exits in descending order.
dimensions=ga:exitPagePath
metrics=ga:exits,ga:pageviews
sort=-ga:exits
 
Site Search - Search Terms
This query returns the number of visits broken down by internal site search, sorted by number of unique searches for a keyword in descending order.
dimensions=ga:searchKeyword
metrics=ga:searchUniques
sort=-ga:searchUniques
 
Use online Web Dashboards in the cloud or download and host your own Dashboards