Google Analytics Tool
A newer version of the Google Analytics Tool is available from the Alteryx Analytics Gallery.
The Google Analytics tool returns statistics derived from the data collected by a Google Analytics tracking code. You use the Core Reporting API to query for dimensions and metrics in order to build customized reports.
Configure the tool
There are two tabs to configure, Authentication and Search.
Authentication
Specify the following Google Analytics credentials:
- Client ID: The client ID obtained from the Google Developers Console.
- Client Secret: The client secret obtained from the Google Developers Console.
- Refresh Token: The refresh token returned from the authorization code exchange on the OAuth 2.0 Playground.
Disable for Testing: When checked, you can test your query without making a call to the Analytics API.
Search
Profile (View) ID: The unique table ID for which your query will retrieve the data. Ask your Web Admin for the list of Profile IDs available to you, or get them here.
Metrics (max 10): The aggregated statistics for user activity to your site, such as clicks or pageviews.
- Any request must supply at least one metric; a request cannot consist of only of dimensions.
- You can supply a maximum of 10 metrics for any query.
- Most combinations of metrics can be used together, provided no dimensions are specified.
- Only valid combinations of metrics and dimensions can be used. See the guidelines.
Date Range: All Analytics data requests must specify a date range. Date format must be yyyy-mm-dd (e.g., 2014-01-01). Choose from the following options:
- Pre-defined Range: A list of pre-defined date ranges to use in your query.
- Calendar: A customized date range defined by your selections on a calendar.
- Manual Entry (yyyy-mm-dd): A customized date range defined by a keyboard entry.

Dimensions (max 7): Breaks down metrics by common criteria.
- You can supply a maximum of 7 dimensions in any query.
- You cannot send a query composed of only dimensions.
- Only valid combinations of dimensions can be used in the same query (e.g. https://developers.google.com/analytics/devguides/reporting/core/dimsmets)
Segments (max 1): Segments the data returned for your request.
Filter: An expression that acts like a filter; restricting the data returned for your request.
- Metric: Returns or restricts values for a specific metric that are ==, !=, >, <, >=, <= a value you supply. ga:timeOnPage==10 OR ga:timeOnPage!=10
- Dimension: Returns or restricts values in a specific dimension that are ==, !=, =@, !@, =~, !~ to a value you supply.
ga:country==United States;ga:browser==Firefox

There are several things you need in order to use the Google Analytics macro:
-
A Google account. This can be obtained by creating a gmail account.
-
Authorized Access to an existing Google Analytics account. See your web administrator to gain approval.
-
A Client ID, Client Secret, and Refresh Token
Register your application by creating a new project using the Google developer's console.
- Browse to the Google Developers Console
- From there, choose Create Project
- In the sidebar of the left, select APIs & auth. Make sure the status for the Analytics API is on.
Generate your Client ID and Client Secret
- In the sidebar on the left, select Credentials.
- Under OAuth select, Create New Client ID.
- From the Create Client ID pop-up window:
- Make sure the Application type selection is Web application.
- Change the Authorized
redirect URI to
https://developers.google.com/oauthplayground - Hit Create Client ID and wait a few seconds for Google to create your new project.
Acquire your Refresh Token
Before we move on make sure your Client ID and Client Secret are readily available (we’ll be using them soon)
-
Browse to Google’s OAuth Playground (https://developers.google.com/oauthplayground)
-
Click the
button near the upper-right corner of your monitor
-
Check the box Use your own OAuth credentials and make sure Access type is set to Offline.
-
Paste in your Client ID in OAuth Client ID.
-
Paste in your Client Secret in OAuth Client Secret.
-
Click Close.
-
In the sidebar on the left, scroll down to the Google Analytics API v3
under Step 1: Select & authorize APIs
-
Click the little grey triangle
on the left and select
-
Hit Authorize APIs to be directed to another page.
-
When prompted, hit Accept to be redirected back to the OAuth 2.0 Playground.
-
Once you’ve been redirected back to the OAuth 2.0 Playground hit the Exchange authorization code for tokens button.
-
Your Refresh Token will be contained in a JSON object towards the bottom of the Request / Response section.
Keep a copy of your Refresh Token, Client ID, and Client Secret somewhere safe but easily accessible.

According to Google, these are several of the most common queries made to the Analytics API.
These examples are meant to highlight the Metrics, Dimensions, and Filter parameters. Anyone using these queries should set the Date Range, Max Results, and Start Index in a manner suitable to their own needs.
General
Visitors and Pageviews Over Time
To return the total visitors and pageviews for the specified time period, select the Metrics:
- Page Tracking > Pageview
- Session > Visits
This query doesn't require any dimensions.
Revenue Generating Campaigns
To return campaign and site usage data for campaigns that led to more than one purchase through your site, select the Metrics:
- Page Tracking > Pageviews
- Session > Bounces
- Session > Time on Site
- Session > Visits
Select the Dimensions:
- Traffic Sources > Medium
- Traffic Sources > Source
The Google developer guide provides more general queries.
Visitors
Browser and Operating System
To return a breakdown of visits by the Operating System, web browser, and browser version used, select the Metrics:
- Session > Visits
Select the Dimensions:
- Platform or Device > Browser
- Platform or Device > Browser Version
- Platform or Device > Operating System
- Platform or Device > Operating System Version
The Google developer guide provides more visitor queries.
Traffic Sources
Referring Sites
To return a list of domains and how many visits each referred to your site, select the Metrics:
- Page Tracking > Exits
- Page Tracking > Pageviews
- Session > Time on Site
Select the Dimensions:
- Traffic Sources > Source
Select Filter, then select Dimension. Under Filter=, enter ga:medium==referral.
The Google developer guide provides more traffic source queries.
Content
Top Exit Pages
To return your most common exit pages, select the Metrics:
- Page Tracking > Exits
- Page Tracking > Pageviews
Select the Dimensions:
- Page Tracking > Exit Page Path
The Google developer guide provides more content queries.