How can I import file with API in Google Analytics GA4
Is your feature request related to a problem? Please describe. Can't find any method for uploading files via GA4 (https://github.com/googleapis/php-analytics-data)
Describe the solution you'd like https://developers.google.com/analytics/devguides/config/mgmt/v3/data-import with fixed issue:
@exstreme actually this issue should be posed to google-api-php-client repo instead.
Does this code snippet not work for you, ref?
$analytics->management_uploads->uploadData(
'123456',
'UA-123456-1',
'122333444455555',
array('data' => file_get_contents('example.csv'),
'mimeType' => 'application/octet-stream',
'uploadType' => 'media'));
You can initialize a client like this:
$KEY_FILE_LOCATION = __DIR__ . '/service-account-credentials.json';
// Create and configure a new client object.
$client = new Google_Client();
$client->setApplicationName("Hello Analytics Reporting");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
$analytics = new Google_Service_Analytics($client);
Hello, @vishwarajanand , thank you for your response! Your code snippet is for Google Analytics Universal (UA), I would find a solution for GA4. They are different, such as using protocols (GA4 is working with gRPC) and formats. Of course, I tried use queries as for UA, but became an error: "Invalid value 'G-XXXXXXXXX'. Values must match the following regular expression: 'UA-\d+-\d+'"
Only one working library with GA4 is https://github.com/googleapis/php-analytics-data , that's why I posted issue there. Of course, I can implement method manually, but there is no documentation about this.
@exstreme unfortunately it doesn't look like there is an API to upload this data with for GA4 yet, the best I can offer is the following: https://support.google.com/analytics/answer/10071301?hl=en
If you'd like to see this happen sooner, please make sure to reach out to the analytics team's support to request the feature.
@dwsupplee where can I request this feature?
@exstreme it looks like there is an existing feature request on the issue tracker: https://issuetracker.google.com/issues/235588725
This would be a great place to boost the signal :).
@dwsupplee Thanks for advice! Can you tell me, how can I comment this issue or it is impossible?
On the top right of the issue there is a button you can click that indicates a vote for whether this impacts you or not.
@dwsupplee Thanks! Is it only single way, how to boost issue? Do you know anything about partner issue tracker?
I think that would be the best way to boost the signal, your other option would be to open another issue but I can't say whether that will get you better traction or not. I'm not very familiar with how the analytics team manages their issue tracker.
@dwsupplee I can't create new issue: "You do not have permission to create issues in this component."
Interesting, I can't speak as to why the tracker for analytics has had its permissions modified. I'd recommend reaching out here: https://support.google.com/analytics/gethelp
For history: it is useless talk with Analytics support, they don't support API or any external tools else UI