The Google Analytics API lets you access data from your Google Analytics account to build custom reports and dashboards. With the API, you can query data from your account, customize the data returned, and access data in real time.
Here are some examples of what you can build with the Google Analytics API:
import { axios } from "@pipedream/platform"
export default defineComponent({
props: {
google_analytics: {
type: "app",
app: "google_analytics",
}
},
async run({steps, $}) {
return await axios($, {
method: "post",
url: `https://analyticsreporting.googleapis.com/v4/reports:batchGet`,
headers: {
Authorization: `Bearer ${this.google_analytics.$auth.oauth_access_token}`,
},
})
},
})
Return report metrics based on a start and end date. See the docs here
Google Analytics uses OAuth authentication. When you connect your Google Analytics account, Pipedream will open a popup window where you can sign into Google Analytics and grant Pipedream permission to connect to your account. Pipedream securely stores and automatically refreshes the OAuth tokens so you can easily authenticate any Google Analytics API.
Pipedream requests the following authorization scopes when you connect your account:
email
profile
https://www.googleapis.com/auth/analytics.readonly
GET
https://accounts.google.com/o/oauth2/auth
?
client_id={{oauth.client_id}}
&
redirect_uri={{oauth.redirect_uri}}
&
state={{oauth.state}}
&
response_type=code
&
scope={{oauth.space_separated_scopes}}
&
prompt=consent
&
access_type=offline
POST
https://oauth2.googleapis.com/token
content-type: application/x-www-form-urlencoded
accept: application/json
client_id={{oauth.client_id}}
&
client_secret={{oauth.client_secret}}
&
redirect_uri={{oauth.redirect_uri}}
&
grant_type=authorization_code
&
code={{oauth.code}}
POST
https://oauth2.googleapis.com/token
content-type: application/x-www-form-urlencoded
accept: application/json
client_id={{oauth.client_id}}
&
client_secret={{oauth.client_secret}}
&
grant_type=refresh_token
&
refresh_token={{oauth.refresh_token}}