Establishing a Connection
Authenticate via OAuth Authentication
Use the OAuth authentication standard to connect to Google Analytics. You can authenticate with a user account or with a service account. A service account is required to grant organization-wide access scopes to the provider. The provider facilitates these authentication flows as described below.
Authenticate with a User Account
Get and Refresh the OAuth Access Token
After setting the following, you are ready to connect:
- OAuthClientId: Set this to the client Id assigned when you registered your app.
- OAuthClientSecret: Set this to the client secret assigned when you registered your app.
- InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
- Profile: Set this to the Google Analytics profile or view you want to connect to. This value can be retrieved from the Profiles table. If this is not specified, the first Profile returned will be used.
When you connect the provider opens the OAuth endpoint in your default browser. Log in and grant permissions to the application. The provider then completes the OAuth process:
- Extracts the access token from the callback URL and authenticates requests.
- Refreshes the access token when it expires.
- Saves OAuth values in OAuthSettingsLocation to be persisted across connections.
Authenticate with a Service Account
Service accounts have silent authentication, without user authentication in the browser. You can also use a service account to delegate enterprise-wide access scopes to the provider.
You need to create an OAuth application in this flow.
After setting the following connection properties, you are ready to connect:
- InitiateOAuth: Set this to GETANDREFRESH.
- OAuthClientId: Set this to the Client Id in your app settings.
- OAuthClientSecret: Set this to the Client Secret in your app settings.
- OAuthJWTCertType: Set this to "PEMKEY_FILE".
- OAuthJWTCert: Set this to the path to the .pem file you generated.
- OAuthJWTCertPassword: Set this to the password of the .pem file.
- OAuthJWTCertSubject: Set this to "*" to pick the first certificate in the certificate store.
- OAuthJWTSubject: Set this to the email address of the user for whom the application is requesting delegate access. Note that delegate access must be granted by an administrator.
- Profile: Set this to the Google Analytics profile or view you want to connect to. This value can be retrieved from the Profiles table. If this is not specified, the first Profile returned will be used.
- Creates and signs the JWT with the claim set required by the provider.
- Exchanges the JWT for the access token.
- Saves OAuth values in OAuthSettingsLocation to be persisted across connections.
- Submits the JWT for a new access token when the token expires.
Creating a Custom OAuth App
Create an OAuth App for User Account Authentication
Follow the procedure below to register an app and obtain the OAuthClientId and OAuthClientSecret.
Create a Custom OAuth App: Desktop
- Log into the Google API Console and open a project. Select the API Manager from the main menu.
-
In the user consent flow, click Credentials -> Create Credentials -> OAuth Client Id. Click Other. After creating the app, the OAuthClientId and OAuthClientSecret are displayed.
- Click Library -> Analytics API -> Enable API.
Create a Custom OAuth App: Web Apps
- Log into the Google API Console and open a project. Select the API Manager from the main menu.
- Click Credentials -> Create Credentials -> OAuth Client Id -> Web Application. In the Authorized Redirect URIs box, enter the URL you want to be used as a trusted redirect URL, where the user will return with the token that verifies that they have granted your app access. After creating the app, the OAuthClientId and OAuthClientSecret are displayed.
- Click Library -> Analytics API -> Enable API.
Create a Custom OAuth App: Headless Machines
Follow the procedure below to register an app and obtain the OAuth client credentials.
- Log into the Google API Console and open a project. Select the API Manager from the main menu.
- Click Credentials -> Create Credentials -> OAuth Client Id. Click Other. After creating the app, the OAuthClientId and OAuthClientSecret are displayed.
- Click Library -> Analytics API -> Enable API.
Create an OAuth App for Service Account Authentication
Follow the steps below to create an OAuth application and generate a private key. You will then authorize the service account.
- Log into the Google API Console and open a project. Select the API Manager from the main menu.
- Click Create Credentials -> Service Account Key.
- In the Service Account menu, select New Service Account or select an existing service account.
- If you are creating a new service account, additionally select one or more roles. You can assign primitive roles at the project level in the IAM and Admin section; other roles enable you to further customize access to Google APIs.
- In the Key Type section, select the P12 key type.
- Create the app to download the key pair. The private key's password is displayed: Set this in OAuthJWTCertPassword.
- In the service accounts section, click Manage Service Accounts and set OAuthJWTIssuer to the email address displayed in the service account Id field.
- Click Library -> Analytics API -> Enable API.
Data Model
Name | Type | Description |
Accounts | Table | Lists all Accounts to which the user has access. |
Goals | Table | A Goals resource describes a goal for one of a user's profiles. |
Profiles | Table | Lists all Profiles to which the user has access. |
Segments | Table | Lists all Segments to which the user has access. |
UserActivity | Table | Lists Web Properties to which the user has access. |
WebProperties | Table | Lists Web Properties to which the user has access. |
AdSense | View | Retrieves AdSense data. |
AdWords | View | Retrieves AdWords data. |
Ecommerce | View | Retrieves Ecommerce data. |
Events | View | Retrieves Event data. |
GoalCompletions | View | Retrieves Goal Completion data. |
SiteContent | View | Retrieves internal Site Content data. |
SiteSearch | View | Retrieves internal Site Search data. |
SiteSpeed | View | Retrieves internal Site Speed data. |
Traffic | View | Retrieves all Traffic data. |
Connection Strings
Name | Description |
ApiVersion | Specify the API version you want to use. |
AutoCache | Automatically caches the results of SELECT queries into a cache database specified by either CacheLocation or both of CacheConnection and CacheProvider . |
CacheConnection | The connection string for the cache database. This property is always used in conjunction with CacheProvider . Setting both properties will override the value set for CacheLocation for caching data. |
CacheLocation | Specifies the path to the cache when caching to a file. |
CacheMetadata | This property determines whether or not to cache the table metadata to a file store. |
CacheProvider | The name of the provider to be used to cache data. |
CacheTolerance | The tolerance for stale data in the cache specified in seconds when using AutoCache . |
ConnectionLifeTime | The maximum lifetime of a connection in seconds. Once the time has elapsed, the connection object is disposed. |
DefaultFilter | A default filter to be applied to all queries. Convenient for setting default Dimensions, StartDate, EndDate, and Segments for all queries. These values will be overridden if set in the query. Example value: Dimensions='Year' AND EndDate='Today'. |
FirewallPassword | A password used to authenticate to a proxy-based firewall. |
FirewallPort | The TCP port for a proxy-based firewall. |
FirewallServer | The name or IP address of a proxy-based firewall. |
FirewallType | The protocol used by a proxy-based firewall. |
FirewallUser | The user name to use to authenticate with a proxy-based firewall. |
IncludeEmptyRows | This connection property can be set only when using the V4 API. If set to false, the provider does not include rows if all the retrieved metrics are equal to zero. The default is true which will include these rows. |
InitiateOAuth | Set this property to initiate the process to obtain or refresh the OAuth access token when you connect. |
Location | A path to the directory that contains the schema files defining tables, views, and stored procedures. |
Logfile | A path to the log file. |
MaxLogFileCount | A string specifying the maximum file count of log files. When the limit is hit, a new log is created in the same folder with the date and time appended to the end and the oldest log file will be deleted. |
MaxLogFileSize | A string specifying the maximum size in bytes for a log file (for example, 10 MB). When the limit is hit, a new log is created in the same folder with the date and time appended to the end. |
MaxRows | Limits the number of rows returned rows when no aggregation or group by is used in the query. This helps avoid performance issues at design time. |
OAuthAccessToken | The access token for connecting using OAuth. |
OAuthClientId | The client ID assigned when you register your application with an OAuth authorization server. |
OAuthClientSecret | The client secret assigned when you register your application with an OAuth authorization server. |
OAuthJWTCert | The JWT Certificate store. |
OAuthJWTCertPassword | The password for the OAuth JWT certificate. |
OAuthJWTCertSubject | The subject of the OAuth JWT certificate. |
OAuthJWTCertType | The type of key store containing the JWT Certificate. |
OAuthJWTIssuer | The issuer of the Java Web Token. |
OAuthJWTSubject | The user subject for which the application is requesting delegated access. |
OAuthRefreshToken | The OAuth refresh token for the corresponding OAuth access token. |
OAuthSettingsLocation | The location of the settings file where OAuth values are saved when InitiateOAuth is set to GETANDREFRESH or REFRESH. Alternatively, this can be held in memory by specifying a value starting with memory://. |
OAuthVerifier | The verifier code returned from the OAuth authorization URL. |
Offline | Use offline mode to get the data from the cache instead of the live source. |
Other | These hidden properties are used only in specific use cases. |
Pagesize | The maximum number of results to return per page from Google Analytics. |
PoolIdleTimeout | The allowed idle time for a connection before it is closed. |
PoolMaxSize | The maximum connections in the pool. |
PoolMinSize | The minimum number of connections in the pool. |
PoolWaitTime | The max seconds to wait for an available connection. |
Profile | The Google Analytics View (Profile). This can be set to either the Id or website URL for the Profile. If not specified, the first Profile returned will be used. |
ProxyAuthScheme | The authentication type to use to authenticate to the ProxyServer proxy. |
ProxyAutoDetect | This indicates whether to use the system proxy settings or not. This takes precedence over other proxy settings, so you'll need to set ProxyAutoDetect to FALSE in order use custom proxy settings. |
ProxyExceptions | A semicolon separated list of hosts or IPs that are exempt from connecting through the ProxyServer . |
ProxyPassword | A password to be used to authenticate to the ProxyServer proxy. |
ProxyPort | The TCP port the ProxyServer proxy is running on. |
ProxyServer | The hostname or IP address of a proxy to route HTTP traffic through. |
ProxySSLType | The SSL type to use when connecting to the ProxyServer proxy. |
ProxyUser | A user name to be used to authenticate to the ProxyServer proxy. |
PseudoColumns | This property indicates whether or not to include pseudo columns as columns to the table. |
RTK | The runtime key used for licensing. |
SamplingLevel | The desired sampling level. Can be set to run faster at the cost of accuracy or for higher accuracy but a decrease in query execution speed. |
SSLServerCert | The certificate to be accepted from the server when connecting using TLS/SSL. |
SupportEnhancedSQL | This property enhances SQL functionality beyond what can be supported through the API directly, by enabling in-memory client-side processing. |
Tables | This property restricts the tables reported to a subset of the available tables. For example, Tables=TableA,TableB,TableC. |
Timeout | The value in seconds until the timeout error is thrown, canceling the operation. |
UseConnectionPooling | This property enables connection pooling. |
Verbosity | The verbosity level that determines the amount of detail included in the log file. |
Views | Restricts the views reported to a subset of the available tables. For example, Views=ViewA,ViewB,ViewC. |