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

Problem with GA3 import #361

Closed
studioekinox opened this issue Mar 1, 2023 · 16 comments
Closed

Problem with GA3 import #361

studioekinox opened this issue Mar 1, 2023 · 16 comments

Comments

@studioekinox
Copy link

I have a problem with Google Analytics Importer, only with Google Universal Analytics.
It’s work with GA4

I have allready migrate 10 website with GA3 but since 5 days, the module do not work.
I have this error
`

<title>Error 403 (Forbidden)!!1</title> <style> *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px} </style>

403. That’s an error.

Your client does not have permission to get URL /analytics/v3/management/accounts/xxxxxxxx/webproperties/UA-xxxxxxx-1/profiles/xxxxxxxxx/goals from this server. That’s all we know.

`
I have a website with GA3 and GA4 Tag => GA3 error / GA4 works
I reset and update the module and reset Google token, try in other GA3 websites but i have the same error.

Your Environment

Matomo version : 4.13.3
Google Analytics Importer : 4.5.0
PHP 8

Thk

@AltamashShaikh
Copy link
Contributor

@studioekinox Can you check if you have access to goals and use the same Google Login you used to authorize Matomo to import data

Its in the Admin section

Screenshot from 2023-03-01 14-11-07

Screenshot from 2023-03-01 14-08-53

@studioekinox
Copy link
Author

studioekinox commented Mar 1, 2023

Hi @AltamashShaikh

Yes it's a same login between Google Analytics and autorize to matomo import.

I don't have Goals for this website

goals

Last month, i have already import a website with no goals and it's worked

@studioekinox
Copy link
Author

If i try to create a new website import, i have the same error

`

403. That’s an error.

Your client does not have permission to get URL /analytics/v3/management/accounts/xxxxxx/webproperties/UA-xxxxxxxx-1 from this server. That’s all we know. `

If i try to import G4, it's work

@AltamashShaikh
Copy link
Contributor

@studioekinox The APIs we use for GA3 and GA4 is different, I would recommend you to check if following APIs are enabled or not?
Check point 6 and 7 from this guide

Screenshot from 2023-03-01 14-40-38
Screenshot from 2023-03-01 14-40-28

@studioekinox
Copy link
Author

@AltamashShaikh , Yes it's allready enable
api

I have the problem since last week. I started an import, it worked for 2 days and the data was imported well and I got this error.

@AltamashShaikh
Copy link
Contributor

@studioekinox Can you manually run the import and check tmp/logs/matomo.log for any exception ?
Command to run the import ./console googleanalyticsimporter:import-reports --idsite={importIDSite} -vvv

@studioekinox
Copy link
Author

@AltamashShaikh
No file created (tmp/log/matomo.log)

Console result :

`Import for site with ID = 10 has errored, will attempt to resume.
INFO [2023-03-01 09:47:44] 1079011 Unexpected Error: Google\Service\Exception:

<title>Error 403 (Forbidden)!!1</title> <style> *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px} </style>

403. That’s an error.

Your client does not have permission to get URL /analytics/v3/management/accounts/87079413/webproperties/UA-87079413-1/profiles/133291124/goals from this server. That’s all we know. in /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/plugins/GoogleAnalyticsImporter/vendor/google/apiclient/src/Http/REST.php:128 Stack trace: #0 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/plugins/GoogleAnalyticsImporter/vendor/google/apiclient/src/Http/REST.php(103): Google\Http\REST::decodeHttpResponse() #1 [internal function]: Google\Http\REST::doExecute() #2 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/plugins/GoogleAnalyticsImporter/vendor/google/apiclient/src/Task/Runner.php(182): call_user_func_array() #3 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/plugins/GoogleAnalyticsImporter/vendor/google/apiclient/src/Http/REST.php(66): Google\Task\Runner->run() #4 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/plugins/GoogleAnalyticsImporter/vendor/google/apiclient/src/Client.php(922): Google\Http\REST::execute() #5 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/plugins/GoogleAnalyticsImporter/vendor/google/apiclient/src/Service/Resource.php(238): Google\Client->execute() #6 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/plugins/GoogleAnalyticsImporter/vendor/google/apiclient-services/src/Analytics/Resource/ManagementGoals.php(89): Google\Service\Resource->call() #7 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/plugins/GoogleAnalyticsImporter/Importer.php(244): Google\Service\Analytics\Resource\ManagementGoals->listManagementGoals() #8 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/plugins/GoogleAnalyticsImporter/Importer.php(226): Piwik\Plugins\GoogleAnalyticsImporter\Importer->importGoals() #9 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/plugins/GoogleAnalyticsImporter/Commands/ImportReports.php(213): Piwik\Plugins\GoogleAnalyticsImporter\Importer->importEntities() #10 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/plugins/GoogleAnalyticsImporter/Commands/ImportReports.php(61): Piwik\Plugins\GoogleAnalyticsImporter\Commands\ImportReports->executeImpl() #11 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/vendor/symfony/console/Symfony/Component/Console/Command/Command.php(257): Piwik\Plugins\GoogleAnalyticsImporter\Commands\ImportReports->execute() #12 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/vendor/symfony/console/Symfony/Component/Console/Application.php(874): Symfony\Component\Console\Command\Command->run() #13 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/vendor/symfony/console/Symfony/Component/Console/Application.php(195): Symfony\Component\Console\Application->doRunCommand() #14 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/core/Console.php(108): Symfony\Component\Console\Application->doRun() #15 [internal function]: Piwik\Console->originDoRun() #16 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/core/Console.php(147): call_user_func() #17 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/core/Access.php(670): Piwik\Console->Piwik\{closure}() #18 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/core/Console.php(148): Piwik\Access::doAsSuperUser() #19 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/core/Console.php(87): Piwik\Console->doRunImpl() #20 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/vendor/symfony/console/Symfony/Component/Console/Application.php(126): Piwik\Console->doRun() #21 /var/www/vhosts/analytics.studio-ekinox.fr/httpdocs/console(32): Symfony\Component\Console\Application->run() #22 {main} Failed to import property entities, aborting. `

@AltamashShaikh
Copy link
Contributor

@studioekinox I tried replicating this issue by passing wrong propertyId and dunno why it looks like an access issue, can you upload the config again and reauthorize and try ?

@studioekinox
Copy link
Author

@AltamashShaikh ,

I have remove configuration, upload json config file and authorize access and i have the same error if i try to restart import or if i try to create new import

@AltamashShaikh
Copy link
Contributor

@studioekinox I couldn't find why this will not work,maybe I can share a quick PHP script which you can run and see if the issue is with your Oauth App or not

@AltamashShaikh
Copy link
Contributor

@studioekinox Are you using SearchEngineKeywordsPerformance plugin ? and what version you are using ?
Also check if the config and accessToken saved is a valid JSON using this query
SELECT * FROM matomo_option where option_name='GoogleAnalyticsImporter.clientConfiguration'
SELECT * FROM matomo_option where option_name='GoogleAnalyticsImporter.oauthAccessToken'

@studioekinox
Copy link
Author

@AltamashShaikh ,

i don't use SearchEngineKeywordsPerformance

I check config and accessToken. it's a valid Json and accessToken not expired

@studioekinox
Copy link
Author

@AltamashShaikh ,

Yes i you want you can share a PHP script and i try this.
If you want i can share FTP matomo access or Google Analytics

Thank for you help

@AltamashShaikh
Copy link
Contributor

@studioekinox
Try this

  1. Create a empty folder testGAScript mkdire testGAScript
  2. cd into folder cd testGAScript
  3. composer require google/apiclient:^2.0
  4. Create testGA3Goals.php and add below content
  5. Run the php script php testGA3Goals.php and check if you get the same exception or not.
<?php

// Load the Google API PHP Client Library.
require_once __DIR__ . '/vendor/autoload.php';

$propertyId = '{PROPERTY_ID}'; //REPLACE THIS
$viewId = '{VIEW_ID}'; //REPLACE THIS
$accountId = '{ACCOUNT_ID}'; //REPLACE THIS

$googleClient = getClient();

$service = new \Google\Service\Analytics($googleClient);
$goals = $service->management_goals->listManagementGoals($accountId, $propertyId, $viewId);

/** @var Google_Service_Analytics_Goal $gaGoal */
foreach ($goals->getItems() as $gaGoal) {
   echo 'Goal Name: '.$gaGoal->getName().PHP_EOL;
}

function getClient() {
    $config = 'Output of SELECT option_value FROM matomo_option where option_name=\'GoogleAnalyticsImporter.clientConfiguration\''; //REPLACE THIS
    

    $accessToken = 'Output of SELECT option_value FROM matomo_option where option_name=\'GoogleAnalyticsImporter.oauthAccessToken\''; //REPLACE THIS


    $googleClient = new \Google\Client();
    $googleClient->addScope(\Google\Service\Analytics::ANALYTICS_READONLY);
    $googleClient->addScope(\Google\Service\AnalyticsReporting::ANALYTICS_READONLY);
    $googleClient->setAccessType('offline');
    $googleClient->setApprovalPrompt('force');
    $googleClient->setAuthConfig(json_decode($config, true));
    $googleClient->setAccessToken($accessToken);

    return $googleClient;
}

@studioekinox
Copy link
Author

@AltamashShaikh ,

I try and I get the same error ;-(

But if I try your script on another server and it works. ;-)
Ip of my server would be banned ??? I have never seen any documentation on this.

do you know where i can see this in google console

@AltamashShaikh
Copy link
Contributor

@studioekinox I am not aware of such blocking, but looks like its your server issue..I would recommend you to open a support ticket with Google and check

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

No branches or pull requests

2 participants