Google Analytics Reporting API - Get Activity with User ID - google-analytics

I can't get User Activity from the Google Analytics Reporting API (v4) using a User ID.
Client ID (in a different, non-User ID view) works, however.
Am I missing something?
--
For Client ID
I go here in my Google Analytics web interface:
https://analytics.google.com/analytics/web/#/report/visitors-user-activity/a45743608w76484324p79062844/_u.date00=20190327&_u.date01=20190402&_r.userId=1142688158.1525244974
I get user activity details as expected:
--
I call the following:
POST https://analyticsreporting.googleapis.com/v4/userActivity:search?key={YOUR_API_KEY}
{
"viewId": "79062844",
"dateRange": {
"startDate": "2019-03-27",
"endDate": "2019-04-02"
},
"user": {
"type": "CLIENT_ID",
"userId": "1142688158.1525244974"
}
}
I get the expected response:
{
"sessions": [
…
],
"totalRows": 14,
"sampleRate": 1
}
--
For User ID
I go here in my Google Analytics web interface:
https://analytics.google.com/analytics/web/#/report/visitors-user-activity/a45743608w76484324p185098721/_u.date00=20190327&_u.date01=20190402&_r.userId=Not%20Logged%20In-
I get user activity details as expected:
--
I call the following:
POST https://analyticsreporting.googleapis.com/v4/userActivity:search?key={YOUR_API_KEY}
{
"viewId": "185098721",
"dateRange": {
"startDate": "2019-03-27",
"endDate": "2019-04-02"
},
"user": {
"type": "USER_ID",
"userId": "Not Logged In-"
}
}
I get an error instead:
{
"error": {
"code": 400,
"message": "USER_ID: Not Logged In- not found.",
"status": "INVALID_ARGUMENT"
}
}
--
I have tried different IDs, different dates, changing the type to CLIENT_ID, URL encoding the User ID, and User IDs with no spaces - no joy.

It seems this is indeed a bug which several others are also experiencing.
This bug can be +1'd and followed here:
https://issuetracker.google.com/issues/130161158
Edit: This has now been fixed.

From your URL, you are looking for an ID called Not%20Logged%20In- which is not a valid id. Its probably changing the id when you copy paste the URL.

Related

Google Calendar API Freebusy query returns "notFound" error

I'm trying to learn how to use this query; I created an API key and used Postman to
Post https://www.googleapis.com/calendar/v3/freeBusy?key="THE_API_KEY"
with this request body:
{
"timeMin": "2022-11-16T00:00:31-00:00",
"timeMax": "2022-11-16T14:00:00-00:00",
"groupExpansionMax": 100,
"calendarExpansionMax": 50,
"items": [
{
"id": "MY_OWN_GMAIL_ADDRESS"
},
{
"id": "OTHER_GMAIL_ADDRESS"
}
]
}
and got this response:
{
"kind": "calendar#freeBusy",
"timeMin": "2022-11-16T00:00:31.000Z",
"timeMax": "2022-11-16T14:00:00.000Z",
"calendars": {
"MY_OWN_GMAIL_ADDRESS": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
},
"OTHER_GMAIL_ADDRESS": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
}
}
}
What am I missing?
The Freebusy: query returns information about weither or not there is an event at the time of the request.
This method does not require authorization when being used against a public google calendar. There are a number of such calendars the holiday calendars are all public. You could also set your own calendar to public if you wish and then you would be able to use use an api key to access it.
API keys give you access to public methods only.
In order to access private user data. You need to be authorized using oauth2 with one of the following scopes.
If you do not have access to a calendar then it will return not found as you cant see it so your not going to be able to find it.
The solution i your case to fix your issue would be to either set the calendar to public and continue to use the api key. You will only be able to preform read actions against the calendar.
Or to switch to using oauth2 and send an authorization header with a bearer token.
Your post didnt include the Authorization header. Did you include it in your Postman Request?
Your need to send your Access Token as a Bearer Token in the Authorization Header
You can see an example for a request here:
https://developers.google.com/calendar/api/v3/reference/freebusy/query?apix=true#try-it

Login With PayPal scopes not working properly

I'm working on a e-Commerce platform where sellers can sell their services. The only payment gateway I'm using is PayPal, I need to get information about the seller's PayPal account like the email address or account ID to store it and then forward payments to their account when a customer buys something from them, I plan to do this with Login With Paypal.
When I click on the button to sign in and get redirected to http://sandbox.paypal.com/signin, I type my email address and password to obtain a code using openid profile email scopes, everything goes as intended, when I add the https://uri.paypal.com/services/paypalattributes value to the scopes string to get access specifically to the account verification status and PayPal account ID though, I receive an error saying the request couldn't be processed and to try again, therefore never hitting the callback URL containing the code that I need, no matter how many times I try again I get the same error.
Just in case, I'm using a Sandbox environment. This is my Next.js Login With PayPal button code.
<Script src="https://www.paypalobjects.com/js/external/api.js"
onReady={() => {
paypal.use( ['login'], function (login) {
login.render ({
"appid":"...",
"authend":"sandbox",
"scopes":"openid profile email
https://uri.paypal.com/services/paypalattributes",
"containerid":"lippButton",
"responseType":"code",
"locale":"en-us",
"buttonType":"LWP",
"buttonShape":"pill",
"buttonSize":"lg",
"fullPage":"true",
"returnurl":"http://127.0.0.1:3000/api/paypal/callback"
})
})
}}/>
I've also checked Account verification status and PayPal account ID (payer ID) scopes in my PayPal account settings.
DevTooling the request, this is what I receive:
"errors": [
{
"message": "Invalid request during get consent content",
"locations": [
{
"line": 3,
"column": 5
}
],
"path": [
"connect",
"getConsent"
],
"extensions": {
"name": "INVALID_REQUEST",
"details": []
}
}
],
"data": {
"connect": {
"getConsent": null,
"__typename": "ConnectQuery"
}
},
"extensions": {
"tracing": {
"version": 1,
"startTime": "2022-10-07T01:54:28.831Z",
"endTime": "2022-10-07T01:54:29.053Z",
"duration": 221889707,
"execution": {
"resolvers": [
{
"path": [
"connect"
],
"parentType": "Query",
"fieldName": "connect",
"returnType": "ConnectQuery",
"startOffset": 1755903,
"duration": 28116203
},
{
"path": [
"connect",
"getConsent"
],
"parentType": "ConnectQuery",
"fieldName": "getConsent",
"returnType": "ConsentEvaluationResponse",
"startOffset": 30085850,
"duration": 188656843
}
]
}
},
"correlationId": "..."
}
}
If an account or app in the PayPal Sandbox environment appears to be behaving in a way you can't find an explanation for, the simplest resolution is often to simply create a new sandbox account/app and verify whether the problem occurs there as well. If it doesn't, use the new one -- if it does, you have have ruled out the account/app itself as an issue and can focus on configuration/integration issues or a real potential problem to report.

Google Analytics API - bad request for Ecommerce activity

I am running the following for our GA reporting v4 API - it works fine without the Ecommerce portion but once I add "ecommerce", it gave me an error.
def get_client_report(analytics):
return analytics.userActivity().search(
body=
{
"viewId": VIEW_ID,
"user": {
"type": "CLIENT_ID",
"userId": "REDACTED"
},
"activityTypes": [
"ECOMMERCE"
],
"dateRange": {
"startDate": "2020-04-02",
"endDate": "2020-04-02"
},
"ecommerce": {
"transaction": {
"transactionId" : "REDACTED"
}
}
}
).execute()
and I get the following error:
https://analyticsreporting.googleapis.com/v4/userActivity:search?alt=json returned "Invalid JSON payload received. Unknown name "ecommerce": Cannot find field.". Details: "[{'#type': 'type.googleapis.com/google.rpc.BadRequest', 'fieldViolations': [{'description': 'Invalid JSON payload received. Unknown name "ecommerce": Cannot find field.'}]}]">
Can you help me what is wrong here? Thank you!
your request body doesn't match the expected format. Take a closer look at docs.
only activityTypes field is supported and you cannot filter for a specific transactions ID. you'll have to perform filtering on your side after receiving a response in that case.

How can I use googles "Interesting Calendars" with their v3 FreeBusy API?

When I attempt to use a calendar such as en.usa#holiday#group.v.calendar.google.com (Or anything with the ID ending in group.v.calendar.google.com) The FreeBusy API errors with:
"calendars": {
"en.usa#holiday#group.v.calendar.google.com": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
}
}
Making the same request but asking for another calendar succeeds.
The request I am making is reproducible in the Google API Docs at https://developers.google.com/calendar/v3/reference/freebusy/query
Where the request body is:
{
"timeMin": "2018-07-01T11:21:53.682-04:00",
"timeMax": "2018-08-25T11:21:53.682-04:00",
"items": [
{
"id": "en.usa#holiday#group.v.calendar.google.com"
}
],
"timeZone": "UTC"
}
I ruled out credentials being an issue; the same credentials work with this calendarId when it is used on the events API. This should also mean that the calendarId is valid.
The google account being used has this interesting calendar added to it. (Those events show up in the combined view)

Campaign measurement is not sent to Google Analytics account

I am following campaign measurement guide to do
https://developers.google.com/analytics/devguides/collection/android/v4/campaigns
Google Play Campaign Attribution
General Campaign & Traffic Source Attribution
For the Google Play Campaign Attribution, after adding the campaign service and receiver to the androidManifest.xml, i followed the testing guide.
https://developers.google.com/analytics/solutions/testing-play-campaigns
In the log successfully received the install referrer intent.
07-29 17:05:32.968 8333-8363/? D/GAv4: Received installation campaign: content=test_content, keyword=test_term, medium=test_medium, name=test_name, source=test_source
But in my google analytic account, Acquisition -> Sources -> All, nothing shows up. Can anyone have any idea what is the root cause?
I also implemented the hit screen analytic, this is working.
My google-services.json is below:
{
"project_info": {
"project_number": "123456788680",
"project_id": "test-app-project"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:12345678680:android:488edac1c6c2df62",
"android_client_info": {
"package_name": "com.example.test.analytic"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "xxxxxxxx_xxxxxxxxxxxxxxKoT0XEkMgOCUe0c"
}
],
"services": {
"analytics_service": {
"status": 2,
"analytics_property": {
"tracking_id": "UA-xxxxxxxx-2"
}
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 1
}
}
},
{
"client_info": {
"mobilesdk_app_id": "1:12345678680:android:6092a3d09b6b18d2",
"android_client_info": {
"package_name": "com.example.test"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "xxxxxxxx_xxxxxxxxxxxxxxKoT0XEkMgOCUe0c"
}
],
"services": {
"analytics_service": {
"status": 2,
"analytics_property": {
"tracking_id": "UA-xxxxxxxx-2"
}
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 1
}
}
}
],
"configuration_version": "1"
}
I modified the project name and the key to post here. In my actual project, i didn't modify anything. There are 2 clients with different package name, because i have 2 projects, one is the main entry app and another is the library. All both needs to send info the google analytic. But both in one application, so I set it to use the same analytic property when request configuration form google. Is that impact? I think it shouldn't.
Can anyone help me?
For me, the information was not sent before building the tracker for the first time.
After sending the broadcast I also only get:
D/GAv4: Received installation campaign: content=test_content, keyword=test_term, medium=test_medium, name=test_name, source=test_source
Then after sending my first own tracking information to Google Analytis, I get:
D/GAv4: Sending first hit to property: UA-63098830-1
D/GAv4: Found relevant installation campaign: content=test_content, keyword=test_term, medium=test_medium, name=test_name, source=test_source
D/GAv4: Sending installation campaign to: UA-63098830-1, content=test_content, keyword=test_term, medium=test_medium, name=test_name, source=test_source

Resources