google-cloud-php icon indicating copy to clipboard operation
google-cloud-php copied to clipboard

How can I import file with API in Google Analytics GA4

Open exstreme opened this issue 3 years ago • 2 comments

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 avatar Aug 29 '22 13:08 exstreme

@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);

vishwarajanand avatar Sep 15 '22 10:09 vishwarajanand

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 avatar Sep 19 '22 07:09 exstreme

@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 avatar Dec 19 '22 04:12 dwsupplee

@dwsupplee where can I request this feature?

exstreme avatar Dec 19 '22 11:12 exstreme

@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 avatar Dec 19 '22 18:12 dwsupplee

@dwsupplee Thanks for advice! Can you tell me, how can I comment this issue or it is impossible?

exstreme avatar Dec 19 '22 20:12 exstreme

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 avatar Dec 19 '22 20:12 dwsupplee

@dwsupplee Thanks! Is it only single way, how to boost issue? Do you know anything about partner issue tracker?

exstreme avatar Dec 19 '22 20:12 exstreme

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 avatar Dec 19 '22 20:12 dwsupplee

@dwsupplee I can't create new issue: "You do not have permission to create issues in this component."

exstreme avatar Dec 19 '22 20:12 exstreme

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

dwsupplee avatar Dec 19 '22 20:12 dwsupplee

For history: it is useless talk with Analytics support, they don't support API or any external tools else UI

exstreme avatar Dec 20 '22 08:12 exstreme