Prerequisites:

  • Client application registered with Google Cloud
  • The client ID and client secret
  • An access token or refresh token

After you have registered your client application with Google Cloud and obtained the required OAuth information, you may configure the driver to access Google Analytics resources using OAuth 2.0.

To configure the driver:
  • Set the AddTables property to specify the JSON string that defines custom tables, including dimensions and metrics, that appear in the Google Analytics 4 schema. For example: '{"TestTable":["sessions","totalUsers","_browser","_sessionSource"]}'.
    Note: You can generate a value for the property using the Configure Logical Schema tool in the Configuration Manager. See Generating connection URLs with the Configuration Manager for details.
  • Set either of the following properties:
    • Set the AccessToken property to specify the access token you have obtained from Google. Generally, an access token is available for a short period of time and may only be used for a single session.
    • Set the RefreshToken property to specify the refresh token you have obtained from Google. With a valid refresh token, the driver can obtain a new access token. In this way, a refresh token enables application access to Google for multiple sessions over an extended period of time.
    Note: The AccessToken and RefreshToken properties may both be specified. If a value for the AccessToken property is not specified, the driver uses the value of the RefreshToken property to make a connection. If both values are not specified, the driver cannot make a successful connection. If both are specified, the driver ignores the AccessToken value and uses the RefreshToken value to generate a new AccessToken value.

    See Obtain access and refresh tokens using the Configuration Manager for details on how to obtain an access or refresh token using the driver's Configuration Manager.

  • Set the ClientID property to specify the client ID for your application. See Registering your application with Google Cloud or Obtaining the client ID and client secret.
  • Set the ClientSecret property to specify the client secret for your application. See Registering your application with Google Cloud or Obtaining the client ID and client secret.
  • (Optionally) Set the Scope property to specify a space-separated list of OAuth scopes that limit the permissions granted by an access token. The default value is:
    scope=https://www.googleapis.com/auth/analytics.manage.users.readonly
    https://www.googleapis.com/auth/analytics 
    https://www.googleapis.com/auth/analytics.readonly

Example URL

Connection conn = DriverManager.getConnection
("jdbc:datadirect:googleanalytics4:AddTables='{myTableDefinitionString}';
AccessToken=abcDEF123ghi-456Jklmno789-Pqrst01234;
ClientID=ab123c45-def6-7g89-gh1i-m2345no67891.apps.googleusercontent.com;
ClientSecret=12a3=bCD/EfGh4Ijk+Lm5P67qR8s=//TuV+WXy1Zabcd;
RefreshToken=1//12a3=bCD/EfGh4Ijk+Lgd8g-44tk3c527831;Scope=scope;");

Example data source

GoogleAnalytics4DataSource mds = new GoogleAnalytics4DataSource();
mds.setDescription("My Google Analytics 4 Data Source");
mds.setAddTables("'{myTableDefinitionString}'");
mds.setAccessToken("abcDEF123ghi-456Jklmno789-Pqrst01234");
mds.setClientID("ab123c45-def6-7g89-gh1i-m2345no67891.apps.googleusercontent.com");
mds.setClientSecret("12a3=bCD/EfGh4Ijk+Lm5P67qR8s=//TuV+WXy1Zabcd");
mds.setRefreshToken("1//12a3=bCD/EfGh4Ijk+Lgd8g-44tk3c527831");
mds.setScope("scope");