Google Analytics enables organizations to get complete details of all the user interactions on their websites or mobile applications. Decision-makers can rely on data from Google Analytics to choose marketing alternatives and decide what to focus on, in their customer acquisition journey. They export Google Analytics data to Google Sheets or other Reporting tools to analyze and generate insights.
It also provides a simple interface to set up machine learning algorithms on user data. Even though the reporting dashboard is comprehensive, organizations sometimes need access to raw hit-level or view-level data from their websites to perform deeper analysis.
Google allows us to export Google Analytics data through its paid offering called GA360. The cost of this offering makes it inaccessible for smaller organizations. This article aims to explain how to export Google Analytics data. More specifically, you will cover how to get raw hit-level data from Google Analytics without having access to GA360.
5 Methods to Export Google Analytics Data
There are 5 methods to export Google Analytics data that are discussed below:
Method 1: Export Google Analytics Data using Hevo
Hevo Data, a No-code Data Pipeline, helps you to directly transfer data from 150+ Data Sources(40+ free sources), including Google Analytics, to Data Warehouses, BI tools, or a destination of your choice in a completely hassle-free & automated manner. Its fault-tolerant architecture ensures that the data is handled securely and consistently with zero data loss.
Get Started with Hevo for Free
The steps to export Google Analytics data using Hevo Data are as follows:
As a prerequisite, Hevo needs permission to view your reports and other reporting entity details. You can read more about these permissions here.
- In the Configure your Google Analytics Account page, do the following:
- Select a previously configured account and click CONTINUE.
- Click + ADD GOOGLE ANALYTICS ACCOUNT and perform the following steps to configure an account:
- Select your linked Google account.
- Click Allow to provide Hevo read access to your analytics data
- In the Select Source Type page, select Google Analytics and specify the following:
You have successfully set up Google Analytics Data Integration using Hevo Data.
- Learn how to set up Google Analytics as a source here.
After setting up the source, you can configure a Hevo destination connector to migrate the Google Analytics data.
Simplify data integration with Hevo today and Sign up here for a 14-day free trial!.
Method 2: Manual export of Google Analytics dashboard
This is the most used method to extract Google Analytics data. In this option, Google Analytics users manually export Google Analytics data from the dashboard.
- First, select the Google Analytics report that you want to export.
- Then, click on the “Export” button located at the top right corner.
- Choose the format in which you want to export Google Analytics data.
- After some loading and preparation of data, the report will be downloaded to your local system.
Download the Whitepaper on Automating Data Integration
Learn the key benefits of automating Data Integration
Method 3: Add-on to export Google Analytics data to Google Sheets
In this option to extract Google Analytics data, a Google Analytics add-on is used to export Google Analytics data that you can find in Google Workspace Marketplace and install it. Get the add-on here. This option is widely used because of a few reasons:
- Users can customize the dimensions and metrics to include in the report.
- You can automate the export of Google Analytics data to Google Sheets by scheduling it.
- You can specify the maximum number of rows to return for your Google Analytics report.
Method 4: Google Analytics API for fetching datasets
Google Analytics API offers a great analytical experience using a few APIs. For larger datasets, exporting Google Analytics data may involve leveraging the Google Analytics API for automated and more complex data retrieval.
- Reporting API: It allows you to access data in GA Universal Properties and export Google Analytics data.
- Realtime API: It allows users to access real-time data.
- Data API: It allows users access to report data of GA4 properties.
- Multi-Channel Funnels API: It reveals user interactions with various traffic sources across multiple sessions before converting.
Method 5: Google Analytics Query Explorer for GA export
The Google Analytics Query Explorer retrieves data from Google Analytics by constructing API queries. Ideal for non-technical users, this tool simplifies data exploration, allowing you to pull information based on a variety of dimensions and metrics. Unlike the standard Google Analytics interface, it surpasses the 5000-row limit, offering extensive data export capabilities. You can download the data in TSV format (easily convertible to CSV) or directly utilize the API query.
- Choose the appropriate account, property, and view from which you wish to extract data.
- Input the desired dimensions, metrics, and date range for the data you require. This step also permits sorting, segmenting, or filtering based on any chosen dimensions or metrics.
- Click the ‘Run Query’ button to initiate the data retrieval process.
Can Google Analytics Export All Data?
Exporting all Google Analytics data in one go is always required. Users need historical data and cannot manually export Google Analytics data for different time frames or intervals. There are 3 ways to export all Google Analytics data:
- Manually exporting reports: It can take some time based on the volume of data you have in Google Analytics.
- Exporting aggregated reports to Google Sheets using the Google Analytics add-on.
- Exporting aggregates reports using Google Analytics API.
How to Automate Data Export From Google Analytics
Apart from programmatically exporting Google Analytics data, only one option is available: using the Google Analytics add-on for Google Sheets. This Google Analytics export data method provides options for frequency and intervals to export Google Analytics data and custom reports.
How to Export Data from Google Analytics
Google enables programmatic access to GA data through Reporting API V4. The data is structured in terms of dimensions and metrics. Dimensions are factors based on which data is aggregated and metrics are the keys that provide information. For example, ‘country’ is a dimension and the number of sessions is a metric.
Google Analytics provides a set of dimensions and metrics as default. Users can also create their own dimensions and metrics by making small modifications to the tracking code that is deployed with the website. To get hold of raw hit level data from Google Analytics, you need to use some custom dimensions.
Here are the steps you will cover in this section:
Creating Custom Dimensions In Google Analytics
Go to the admin section and navigate to the property where the custom dimension is to be added. Click on ‘Create New Custom Dimension’ and add the dimension name. For now, let us define it as hit_id. Select the scope as ‘hit’, check the active box, and click on ‘Create’.
Adding The Custom Dimension Tracking Code To The Google Analytics Script
Google Analytics uses a script called gtag.js to track user behavior on your website. Add the below snippet in your gtag.js part on the web page for which you want to get hit level data:
gtag('config', 'GA_MEASUREMENT_ID', {
'custom_map': {'dimension1': hit_id, ‘dimension2’:brow_id}
});
In the above code, use an arbitrary identifier as the GA_MEASUREMENT_ID. Google Analytics follows a convention of dimension<number from 1-20> as the key in the custom map. The value is the name of the dimension that will be used here.
You must now create a unique id for the user’s browser using the below snippet:
if (document.cookie.indexOf('browser_uuid_set=1') == -1) {
gtag(‘set’,{‘brow_id’,Math.random()})
document.cookie = 'browser_uuid_set=1; expires=Fri, 01 Jan 2100 12:00:00 UTC; domain=.arem.us; path=/';
}
gtag(‘set’,{'hit_id',new Date().getTime()})
gtag('event', 'page_view');
Time is being used as an identifier of the hit here. Every time a hit is made, gtag.js will send a page_view event with two details – The browser id which was created, and the timestamp of that view.
In the next step, this raw hit level data that is reaching the GA server will be gotten hold of.
Installing Google Reporting API V4 Python Library
You will now try to access the data using Google Reporting API V4. Install the python library for Google Reporting API using the below command:
sudo pip install --upgrade google-api-python-client
Importing The Required Libraries
Using the python library, create a script to download the hit level data into a CSV. Begin by importing the required libraries. Use the below snippet:
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
Initializing The Required Variables
SCOPES = ['https://www.googleapis.com/auth/analytics.readonly']
KEY_FILE_LOCATION = '<KEY_JSON_FILE>'
VIEW_ID = '<REPLACE_WITH_VIEW_ID>'
The above variables are required for OAuth authentication. You have to replace the key file location and the view id with the assets you obtained while setting up the service account for Google Analytics. VIEW_ID can be seen in the admin section.
Initializing The Objects
Initialize the objects for accessing the data using the below snippet:
credentials = ServiceAccountCredentials.from_json_keyfile_name(KEY_FILE_LOCATION, SCOPES)
# Build the service object.
analytics = build('analyticsreporting', 'v4', credentials=credentials)
Retrieving Response From Reporting API
Use the batchGet method in the library to retrieve the response from the Reporting API.
response = analytics.reports().batchGet(
body={
'reportRequests': [
{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': '7daysAgo', 'endDate': 'today'}],
'dimensions': [{ "name":"ga:dimension1" },
{"name":"ga:dimension2" }],
}]
}
).execute()
The response will be a JSON file that contains a nested map of the two dimensions that were sent to Google Analytics for each page view. The JSON file can be parsed into CSV or directly loaded into a data warehouse after required transformations.
How to Enable Google Analytics API for Exporting Data
Google API client libraries support many languages such as Java, .NET, Python, etc. These client libraries allow you to access and program using the Google Analytics APIs. But you can only access these libraries and APIs after enabling the target API and getting the application credentials. Let’s have a look at how to enable Google Analytics API. The steps are listed below:
Step 1: Create a New Project on Google API Console
- Log in to your Google API Console account.
- Here, create a new project and name as per your wish.
- Then, click on the Create button.
Step 2: Enabling the Google Analytics API
- Now, select the project from the top menu bar.
- Then, go to the Dashboard of the APIs & Services menu.
- Here, click on the “Enable APIs and Services“.
- Now, search for “Google Analytics” and select ay of the Google Analytics API that you want to use.
- Then, click on the “Enable” button.
Step 3: OAuth Consent Screen and Credentials
- Click on the “Create Credentials” option and then navigate to the OAuth consent screen.
- Select the user type as “External” and click on the “Create” button.
- It will navigate you to the next page where you need to configure the following settings.
- App Information:
- App Name
- User Support E-Mail
- Developer Contact Information
- Then click on the “Save and Continue” button.
- Navigate to the Scopes page and click on the “Save and Continue” button.
- Go to Test Users Page and click on the “Add users” option to add a new E-Mail address.
- Then, click on the “Save and Continue” button.
- On the Summary page click on the “Back to Dashboard“.
- Now, you have to navigate to the Credentials Menu, and here, click on the “Create Credentials” option.
- Select the type of credentials to use.
- Then create the credentials.
Here are some of the typical challenges developers face while implementing the above approach in production:
- This approach requires you to modify the tracking code and write a custom script using the Reporting API Python library to download the data. Taking this to production will require you to write even more code. Cloud-based ETL tools like Hevo can accomplish this without writing any custom code.
- The above approach will work well for one offload, but in data warehousing scenarios, that is rarely the case. You will need to build additional logic to execute this continuously. Hevo’s scheduling capability will handle such problems for you, and hence saving critical development time. Reporting API has quotas and limits associated with it. So the application logic should have the ability to work around the limits. Hevo automatically adheres to such throttling limits and relieves you of this implementation.
- The raw data in most cases will have to be transformed into different formats before inserting it into the data warehouse. Hevo comes with comprehensive transformation support and helps you accomplish these in a few clicks.
VISIT OUR WEBSITE TO EXPLORE HEVO
Conclusion
Great! You have now learned how to export Google Analytics data. You have learned how to add custom dimensions to Google Analytics tracking code and also how to extract hit-level data using custom dimensions. Google Analytics export raw data provides the unaggregated, event-level details that can be crucial for in-depth user behavior analysis.
So if all that scripting magic and the associated challenges feel like too much effort, you can think of using a completely automatic, cloud-based ETL tool like Hevo that can extract, transform and load Google Analytics data to almost any data warehouse for Free in a matter of a few clicks. Hevo provides a simple user interface and comes with complex transformation support.
Want to take Hevo for a spin?
SIGN UP and experience the feature-rich Hevo suite first hand. You can also have a look at the unbeatable Hevo Pricing that will help you choose the right plan for your business needs.
Share your thoughts on how to export Google Analytics raw data in the comments. We would love to hear from you!
Vivek Sinha has extensive experience in real-time analytics and cloud-native technologies. With a focus on Apache Pinot, he was a driving force in shaping innovation and defensible differentiators, including enhanced query processing, data mutability support, and cost-effective tiered storage solutions at Hevo. He also demonstrates a passion for exploring and implementing innovative trends within the dynamic data industry landscape.