Hello, I am looking into Tap Google Analytics <htt...
# plugins-general
d
Hello, I am looking into Tap Google Analytics https://hub.meltano.com/extractors/tap-google-analytics/#key-file-location and it tells me:
what does it mean?
m
Universal is deprecated by Google. Use this one - https://hub.meltano.com/extractors/tap-ga4
d
thank you
I ran
Copy code
meltano elt tap-google-analytics target-jsonl
and it works still, I will try the one you shared, thank you!
Maybe you know about the:
Copy code
oauth_credentials.access_token
oauth_credentials.client_id
oauth_credentials.client_secret
oauth_credentials.refresh_token
I've got the
client_id
and
client_secret
and then I use strange url to get
refresh token
Copy code
<https://accounts.google.com/o/oauth2/v2/auth?response_type=code&client_id=$CLIENT_ID&redirect_uri=http%3A%2F%2Flocalhost&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fanalytics.readonly&access_type=offline&prompt=consent>
After I use strange python:
Copy code
import requests

def exchange_code_for_tokens(client_id, client_secret, code):
    url = "<https://oauth2.googleapis.com/token>"
    data = {
        'code': code,
        'client_id': client_id,
        'client_secret': client_secret,
        'redirect_uri': '<http://localhost>',
        'grant_type': 'authorization_code',
    }
    response = <http://requests.post|requests.post>(url, data=data)
    return response.json()

client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
code = ""

tokens = exchange_code_for_tokens(client_id, client_secret, code)
print(tokens)
to get the
access_token
and this was enougth to export data from GA. However, the token will expire in 3000s, how meltano can obtain fresh token to run tap daily?
And I noticed this message:
Copy code
Note: If the Property Settings shows a "Tracking Id" such as "UA-123...-1", this Property is a Universal Analytics property, and the Analytics data for that property cannot be reported on in the Data API. For that property, you can use the Google Analytics Reporting API v4 to produce analytics data reports.
And I have the UA-... Tracking ID
p
@dima_anoshin see my message above about which version to use https://meltano.slack.com/archives/C013EKWA2Q1/p1689358883477349 it really depends if you want to pull new GA4 data or historical UA data. The tap supports oauth authentication and will handle all that behind the scenes for you via the google.oauth2 python client https://github.com/MeltanoLabs/tap-google-analytics/blob/b6a0f55825ea5527cc89aa3258231e478e711a8b/tap_google_analytics/tap.py#L99