Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to report via Google Analytics Data API (GA4) #199

Open
fdiebel opened this issue Jun 17, 2022 · 4 comments
Open

Add ability to report via Google Analytics Data API (GA4) #199

fdiebel opened this issue Jun 17, 2022 · 4 comments
Assignees
Milestone

Comments

@fdiebel
Copy link
Member

fdiebel commented Jun 17, 2022

GA-3 is expiring next year. Oh shit.

@fdiebel fdiebel added this to the v4.0 milestone Jun 17, 2022
@fdiebel fdiebel self-assigned this Jun 17, 2022
@fdiebel
Copy link
Member Author

fdiebel commented Jun 18, 2022

@fdiebel
Copy link
Member Author

fdiebel commented Mar 9, 2023

With gcloud command

curl -X POST  -H "Authorization: Bearer "$(gcloud auth application-default print-access-token)  -H "Content-Type: application/json; charset=utf-8" \
https://analyticsdata.googleapis.com/v1beta/properties/$GA4_PROPERTY_ID:runReport -d '{"dateRanges":[{"startDate":"2020-03-31","endDate":"today"}],"dimensions":[{"name":"city"}],"metrics":[{"name":"activeUsers"}]}

Without, probably won't go this route

# Obtain an access token using the key file
curl -s -d "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=$(JWT=$(cat /path/to/keyfile.json); echo -n $JWT | openssl base64 -A)" https://oauth2.googleapis.com/token

# Use the access token to send your request using curl
curl -X POST  -H "Authorization: Bearer <ACCESS_TOKEN>"  -H "Content-Type: application/json; charset=utf-8" \
https://analyticsdata.googleapis.com/v1beta/properties/$GA4_PROPERTY_ID:runReport -d '{"dateRanges":[{"startDate":"2020-03-31","endDate":"today"}],"dimensions":[{"name":"city"}],"metrics":[{"name":"activeUsers"}]}'

@fdiebel
Copy link
Member Author

fdiebel commented Jul 18, 2023

More notes

property_id="###"
​
curl -X POST \
    -H "Authorization: Bearer $jwt" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @body.json \
    https://analyticsdata.googleapis.com/v1beta/properties/$property_id:runReport

@fdiebel
Copy link
Member Author

fdiebel commented Jul 18, 2023

basic endpoints

Organic
-----
activeUsers
newUsers                
sessionsPerUser
avgSessionDuration 
screenPageViews
screenPageViewsPerSession
screenPageViewsPerUser
organicGoogleSearchClicks
organicGoogleSearchImpressions 
bounceRate

Advertising
-----
impressions 
adClicks 
adCost 
CPC 
CTR 
costPerConversion 
transactions
transactionRevenue
revenuePerTransaction
revenuePerItem
transactionsPerSession
transactionsPerUser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant