We are proud to share our inclusion in the 2024 Gartner Magic Quadrant for Data Integration Tools. We believe this recognition reflects the differentiated business outcomes CData delivers to our customers.
Get the Report →How to Visualize Adobe Analytics Data in Python with pandas
Use pandas and other modules to analyze and visualize live Adobe Analytics data in Python.
The rich ecosystem of Python modules lets you get to work quickly and integrate your systems more effectively. With the CData Python Connector for Adobe Analytics, the pandas & Matplotlib modules, and the SQLAlchemy toolkit, you can build Adobe Analytics-connected Python applications and scripts for visualizing Adobe Analytics data. This article shows how to use the pandas, SQLAlchemy, and Matplotlib built-in functions to connect to Adobe Analytics data, execute queries, and visualize the results.
With built-in optimized data processing, the CData Python Connector offers unmatched performance for interacting with live Adobe Analytics data in Python. When you issue complex SQL queries from Adobe Analytics, the driver pushes supported SQL operations, like filters and aggregations, directly to Adobe Analytics and utilizes the embedded SQL engine to process unsupported operations client-side (often SQL functions and JOIN operations).
Connecting to Adobe Analytics Data
Connecting to Adobe Analytics data looks just like connecting to any relational data source. Create a connection string using the required connection properties. For this article, you will pass the connection string as a parameter to the create_engine function.
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.
Follow the procedure below to install the required modules and start accessing Adobe Analytics through Python objects.
Install Required Modules
Use the pip utility to install the pandas & Matplotlib modules and the SQLAlchemy toolkit:
pip install pandas pip install matplotlib pip install sqlalchemy
Be sure to import the module with the following:
import pandas import matplotlib.pyplot as plt from sqlalchemy import create_engine
Visualize Adobe Analytics Data in Python
You can now connect with a connection string. Use the create_engine function to create an Engine for working with Adobe Analytics data.
engine = create_engine("adobeanalytics:///?GlobalCompanyId=myGlobalCompanyId& RSID=myRSID& OAuthClientId=myOauthClientId& OauthClientSecret=myOAuthClientSecret& CallbackURL=myCallbackURL")
Execute SQL to Adobe Analytics
Use the read_sql function from pandas to execute any SQL statement and store the resultset in a DataFrame.
df = pandas.read_sql("SELECT Page, PageViews FROM AdsReport WHERE City = 'Chapel Hill'", engine)
Visualize Adobe Analytics Data
With the query results stored in a DataFrame, use the plot function to build a chart to display the Adobe Analytics data. The show method displays the chart in a new window.
df.plot(kind="bar", x="Page", y="PageViews") plt.show()
Free Trial & More Information
Download a free, 30-day trial of the CData Python Connector for Adobe Analytics to start building Python apps and scripts with connectivity to Adobe Analytics data. Reach out to our Support Team if you have any questions.
Full Source Code
import pandas import matplotlib.pyplot as plt from sqlalchemy import create_engin engine = create_engine("adobeanalytics:///?GlobalCompanyId=myGlobalCompanyId& RSID=myRSID& OAuthClientId=myOauthClientId& OauthClientSecret=myOAuthClientSecret& CallbackURL=myCallbackURL") df = pandas.read_sql("SELECT Page, PageViews FROM AdsReport WHERE City = 'Chapel Hill'", engine) df.plot(kind="bar", x="Page", y="PageViews") plt.show()