Over a million developers have joined DZone.

Google Analytics for REST APIs

DZone's Guide to

Google Analytics for REST APIs

Google Analytics provides great real-time and historical reports for websites, and with WSO2 API Cloud, you can easily get them to report your REST API usage as well.

· Integration Zone ·
Free Resource

WSO2 is the only open source vendor to be named a leader in The Forrester Wave™: API Management Solutions, Q4 2018 Report. Download the report now or try out our product for free.

Google Analytics provides great real-time and historical reports for websites, and with WSO2 API Cloud, you can easily get them to report your REST API usage as well.

To do that you simply have to:

  1. Create a tracking ID in Google Analytics.

  2. Configure WSO2 API Cloud to report to Google Analytics and provide the ID.

  3. See real-time and historical API usage reports.

Let’s go through all of these steps in details.

1. Create a Tracking ID in Google Analytics

This is not really specific to WSO2 API Cloud in any way. You basically create a Google Analytics account like you normally would.

1a. Go to the Google Analytics homepage and log in or sign up.

1b. Click the Admin tab.

Admin menu in Google Analytics

1c. From the Accounts dropdown, select Create new account.

Create new Google Analytics account

1d. Provide the name of the account and site as you see fit. For the website URL, either provide the custom URL that you have configured in API Cloud or just gateway.api.cloud.wso2.com if you have not done so.

Setting up Google Analytics account

1e. Click the Get Tracking ID button and accept terms and conditions, and Google Analytics will get you to the Tracking ID page of the new account. Right at the top of the page, it will have the ID that you need, i.e., UA-12345678-9.

2. Hook Up WSO2 API Cloud and Google Analytics

2a. From your API Publisher view, copy your domain-qualified ID that is displayed in the top-right corner.

Copy domain-qualified WSO2 Cloud username

2b. Go to advanced Gateway admin console here.

2c. Sign in with the domain-qualified name that you got in Step 1 and your regular password.

Gateway sign-in

2d. In the left-hand pane, click Resources/Browse.

2e. Browse to /_system/governance/apimgt/statistics/ga-config.xml:.

Resources Browse to GA analytics configuration

2f. Click edit as text.

Edit as text

2g. Change false to true, copy and paste the TrackingID that you got when setting up the Google Analytics account, and click Save Content:

Editing Google Analytics config

That is it. Now all API calls for your APIs get registered in Google Analytics.

3. Enjoy Google Analytics Reports for APIs

Once the configuration changes go into effect, your usage data will start showing up in Google Analytics reports.

Real-time Google Analytics API report

Real-time report shows subscribers invoking your API right now

Behavior Overview Google Analytics report for APIs

Behavior reports can show trends over time, popular REST paths, and so on

And of course, you can use various Google Analytics functionality to work with trends, grouping, custom reports, filtering, and so on.

Read the WSO2 Methodology for Agility to see how you can transform your integration projects from semi-agile to a scalable continuous agile approach.

api cloud ,rest apis ,google analytics ,integration

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}