Ready to get started?

Learn more about the CData JDBC Driver for Adobe Analytics or download a free trial:

Download Now

Create a Data Access Object for Adobe Analytics Data using JDBI

A brief overview of creating a SQL Object API for Adobe Analytics data in JDBI.

JDBI is a SQL convenience library for Java that exposes two different style APIs, a fluent style and a SQL object style. The CData JDBC Driver for Adobe Analytics integrates connectivity to live Adobe Analytics data in Java applications. By pairing these technologies, you gain simple, programmatic access to Adobe Analytics data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read Adobe Analytics data.

Create a DAO for the Adobe Analytics AdsReport Entity

The interface below declares the desired behavior for the SQL object to create a single method for each SQL statement to be implemented.

public interface MyAdsReportDAO { //request specific data from Adobe Analytics (String type is used for simplicity) @SqlQuery("SELECT PageViews FROM AdsReport WHERE City = :city") String findPageViewsByCity(@Bind("city") String city); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Adobe Analytics

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Adobe Analytics.

Adobe Analytics uses the OAuth authentication standard. To authenticate using OAuth, you will need to create an app to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties. See the "Getting Started" section of the help documentation for a guide.

Retrieving GlobalCompanyId

GlobalCompanyId is a required connection property. If you do not know your Global Company ID, you can find it in the request URL for the users/me endpoint on the Swagger UI. After logging into the Swagger UI Url, expand the users endpoint and then click the GET users/me button. Click the Try it out and Execute buttons. Note your Global Company ID shown in the Request URL immediately preceding the users/me endpoint.

Retrieving Report Suite Id

Report Suite ID (RSID) is also a required connection property. In the Adobe Analytics UI, navigate to Admin -> Report Suites and you will get a list of your report suites along with their identifiers next to the name.

After setting the GlobalCompanyId, RSID and OAuth connection properties, you are ready to connect to Adobe Analytics.

Built-in Connection String Designer

For assistance in constructing the JDBC URL, use the connection string designer built into the Adobe Analytics JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

java -jar cdata.jdbc.adobeanalytics.jar

Fill in the connection properties and copy the connection string to the clipboard.

A connection string for Adobe Analytics will typically look like the following:

jdbc:adobeanalytics:GlobalCompanyId=myGlobalCompanyId; RSID=myRSID; OAuthClientId=myOauthClientId; OauthClientSecret=myOAuthClientSecret; CallbackURL=myCallbackURL;

Use the configured JDBC URL to obtain an instance of the DAO interface. The particular method shown below will open a handle bound to the instance, so the instance needs to be closed explicitly to release the handle and the bound JDBC connection.

DBI dbi = new DBI("jdbc:adobeanalytics:GlobalCompanyId=myGlobalCompanyId; RSID=myRSID; OAuthClientId=myOauthClientId; OauthClientSecret=myOAuthClientSecret; CallbackURL=myCallbackURL;"); MyAdsReportDAO dao = dbi.open(MyAdsReportDAO.class); //do stuff with the DAO dao.close();

Read Adobe Analytics Data

With the connection open to Adobe Analytics, simply call the previously defined method to retrieve data from the AdsReport entity in Adobe Analytics.

//disply the result of our 'find' method String pageViews = dao.findPageViewsByCity("Chapel Hill"); System.out.println(pageViews);

Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for Adobe Analytics by integrating with the CData JDBC Driver for Adobe Analytics. Download a free trial and work with live Adobe Analytics data in custom Java applications today.