Jump to content

Google Analytics API not woking


Recommended Posts

Hi guys,

 

I have looked through the forum and can only really find 1 post with the same problem but its has had no replies. SO im starting a new threat to hopefully get some attention to it. 

 

I have loaded and put in my Google Analytics code (the UA-65xxxxxx code) into the module as normal. All seems to work fine there. However when I go to the Google Analytics API v1.1.0 Module and try and load in my credentials I get the following error. 

 

400. That’s an error.

Error: invalid_request

Invalid parameter value for redirect_uri: Missing scheme: modules/gapi/oauth2callback.php

Learn more

Request Details
  • scope=https://www.googleapis.com/auth/analytics.readonly
  • response_type=code
  • access_type=offline
  • redirect_uri=modules/gapi/oauth2callback.php
  • approval_prompt=force
  • state=1-e9f5f745e933668baadd02a2fefae061
  • client_id=300039335954-tr0pli7nb88ir979a2ne3brbnp6sr3af.apps.googleusercontent.com

That’s all we know.

 

I have tried just about everthing I could find on the little posts I could find.

 

Any help or suggestions would be much appreciated.

  • Like 2
Link to comment
Share on other sites

Is it this problem you get (see attachment).

 

If it's, I think it is after you pressed the button 'no tests received' into PS backoffice>modules>Google API

 

Well after you get the error, just go to the previous page on your internet browser and normally you will get a green button with example: "yesterday your shop received 100 visitors for a total of...".

 

If not, you need to Enable your API into Google developers.

post-1006077-0-21219600-1436904372_thumb.png

Edited by mynewborn (see edit history)
Link to comment
Share on other sites

Hi mynewborn,

 

Thanks for the reply. That is the error Im getting. If I go back to the previous page all I get is the Google Analytics API module asking me to ender in the details again.

 

My API is active in google developers and the credentials are setup as well. Maybe Ive done something wrong there.

post-783184-0-25375700-1436908710_thumb.jpg

post-783184-0-55216500-1436908805_thumb.jpg

Edited by RedPig (see edit history)
Link to comment
Share on other sites

Hi mynewborn,

 

Thats exactly where I did mine. How ever when I go to the screen (like in your attachment) No requests or anything are there. I have loaded everything as per the instructions with and with out www. Still when I add the credential details to the Google API module I get that error.

Link to comment
Share on other sites

So gone through it all step by step and reloaded and refreshed everything. Does somebody know where I could download that module again. (the ones in the store are all paide modules) Maybe deleting the module and re-installing it will help. The only thing I can think of now is that the module has an issue.

Link to comment
Share on other sites

Hi navodyc4

 

Thanks so much for the reply. I have tried your suggestion.

 

It finally seems to be doing somthing at least. It now asked me for permission which I granted. However when its done I get the following messages.

 

Google API Authorization granted but access token cannot be retrieved and Cannot retrieve test results.

 

Thanks navodyc4 It finally feels like IM getting somewhere. Do you perhaps know why I would be getting those 2 errors above?

 

UPDATE:

 

I have tried to submit the details a few times now and get a mixture of the above 2 errors and Google is unreachable (check your firewall).

 

Final UPDATE:

 

After re-submitting about 10 times it finally took and everything is working.

 

THANK YOU SO MUCH navodyc4 and to all who tried to help. This has been bugging me for WEEKS.

Edited by RedPig (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

navodyc4 - you genius :)

 

For about 5 weeks I have been trying to get this working after it stopped randomly for some reason. Your fix has worked immediately. Thank you so much. This has ben bugging the hell out of me. Contacted web hosts, have uninstalled google modules so many times, have created new projects, reset secret etc etc. I am now very happy :)

Link to comment
Share on other sites

 

Hi,

 

 

but problem is in API Google Analytics module. Try change in modules/gapi/gapi.php this two rows:

 

$shop = new Shop(Shop::getContextShopID(true));

and

$shop = new Shop(Shop::getContextShopID(true));

to (only remove true)

$shop = new Shop(Shop::getContextShopID());

How do manipulate module code?  I've tried everything state above multiple multiple times.  It seems somewhere the prestashop directions are outdated or missing something.  When you go through google  and enable api's in the https://console.developers.google.com/project/agile-polymer-102103/apiui/apis/library?authuser=1 the UI is different... then when you "create client ID"  a you can't enter your site and site/modules/gapi/oauth2callback.php until you "configure consent". 

 

I'm thoroughly confused... Also, does the analytics information get pulled to the Prestashop Dashboard after all this?

Link to comment
Share on other sites

 

Hi,

 

 

but problem is in API Google Analytics module. Try change in modules/gapi/gapi.php this two rows:

 

$shop = new Shop(Shop::getContextShopID(true));

and

$shop = new Shop(Shop::getContextShopID(true));

to (only remove true)

$shop = new Shop(Shop::getContextShopID());

myshop/gapi/gapi.php is blank.

Link to comment
Share on other sites

 

Hi,

 

 

but problem is in API Google Analytics module. Try change in modules/gapi/gapi.php this two rows:

 

$shop = new Shop(Shop::getContextShopID(true));

and

$shop = new Shop(Shop::getContextShopID(true));

to (only remove true)

$shop = new Shop(Shop::getContextShopID());

This actually worked! I can't believe it took 3 days to find your work around... and then another half an hour to get implemented.  THANKS.  I'll just look for your post after the next updates. :)

  • Like 1
Link to comment
Share on other sites

 

Hi,

 

 

but problem is in API Google Analytics module. Try change in modules/gapi/gapi.php this two rows:

 

$shop = new Shop(Shop::getContextShopID(true));

and

$shop = new Shop(Shop::getContextShopID(true));

to (only remove true)

$shop = new Shop(Shop::getContextShopID());

Applied this change, still got same error..

Link to comment
Share on other sites

 

Hi,

 

 

but problem is in API Google Analytics module. Try change in modules/gapi/gapi.php this two rows:

 

$shop = new Shop(Shop::getContextShopID(true));

and

$shop = new Shop(Shop::getContextShopID(true));

to (only remove true)

$shop = new Shop(Shop::getContextShopID());

 

Thanks a lot for this! It worked for me also. Can't believe it took me 2 days to find this post to help me solve the problem :(

Link to comment
Share on other sites

What can I do? I have the same problem but I use Cloud version so to change the rows I think it is impossible... Please help.

 

If you setup a FTP account from My store > Manage store you will be able to modify your modules files.

Link to comment
Share on other sites

 

Hi,

 

 

but problem is in API Google Analytics module. Try change in modules/gapi/gapi.php this two rows:

 

$shop = new Shop(Shop::getContextShopID(true));

and

$shop = new Shop(Shop::getContextShopID(true));

to (only remove true)

$shop = new Shop(Shop::getContextShopID());

 

This worked for me, Thank you!! Connection was successful but I have the following message "Cannot retrieve test results". 

Edited by dformica (see edit history)
Link to comment
Share on other sites

Worked for me too

 

 

Hi,

 

 

but problem is in API Google Analytics module. Try change in modules/gapi/gapi.php this two rows:
 

$shop = new Shop(Shop::getContextShopID(true));

and

$shop = new Shop(Shop::getContextShopID(true));

to (only remove true)

$shop = new Shop(Shop::getContextShopID());

THIS WORKED FOR ME TOO. AFTER 3 HOURS OF SEARCHING. Thnak you so much !

Link to comment
Share on other sites

 

Hi,

 

 

but problem is in API Google Analytics module. Try change in modules/gapi/gapi.php this two rows:

 

$shop = new Shop(Shop::getContextShopID(true));

and

$shop = new Shop(Shop::getContextShopID(true));

to (only remove true)

$shop = new Shop(Shop::getContextShopID());

 

Thanks Mate... like a boss

Link to comment
Share on other sites

The fix worked for me as well on 1.6.1.1 but it gives this error on the backend on module and performance tabs at the top:

2 errors 

  1. gapi (parse error in /modules/gapi/gapi.php)
  2. gapi (class missing in /modules/gapi/gapi.php)

When I replace the gapi.php with original this error is gone but the module goes back to not working.   Remove the two "true" words from the code as per the fix and the module works but I get this error.

 

How can I remove this error?

Link to comment
Share on other sites

The fix worked for me as well on 1.6.1.1 but it gives this error on the backend on module and performance tabs at the top:

2 errors 

  1. gapi (parse error in /modules/gapi/gapi.php)
  2. gapi (class missing in /modules/gapi/gapi.php)

When I replace the gapi.php with original this error is gone but the module goes back to not working.   Remove the two "true" words from the code as per the fix and the module works but I get this error.

 

How can I remove this error?

  Anyone have any thoughts?   Module seems to work great with this basic fix, just removing the 8 characters outlined in this post fixed it for me ("true" & " true"), but it left me with this error on the backoffice, it is on the dashboard and everywhere in backoffice.

Link to comment
Share on other sites

I had the same problems. 


Regarding those 2 errors in backoffice, go to your modules and check Google Analytics API because after that fixing it came again like "Install". I clicked on it, and it was written that it is already installed but errors disappeared. 


 


Then regarding "Cannot retrieve test results" and this error:


Error: redirect_uri_mismatch


Application: TPV Analytics API


The redirect URI in the request: http:/..... /modules/gapi/oauth2callback.php did not match a registered redirect URI... 


 


I have found that google sometimes cannot read "www" and really this worked for me: 


 


1) In Developers Console - Consent Screen in Homepage URL - remove "www"   so it will stay only   http://domain.com  and 


2) in Developers Console - Credentials - Cliend ID - Authorized Javascript Origins


               http://www.domain.com 


               http://domain.com


3)              and in Authorized redirect URI


              http://www.domain.com/modules/gapi/oauth2callback.php 

Link to comment
Share on other sites

 

I had the same problems. 

Regarding those 2 errors in backoffice, go to your modules and check Google Analytics API because after that fixing it came again like "Install". I clicked on it, and it was written that it is already installed but errors disappeared. 

 

 

 

 

This didnt work for me at all I tried multiple times.

 

I overwrote the module with the version on github @ https://github.com/PrestaShop/gapi and it fixed this error and original problem.  Modification was not needed.

Link to comment
Share on other sites

I don't have such lines

  1. $shop = new Shop(Shop::getContextShopID(true));

and

  1. $shop = new Shop(Shop::getContextShopID(true));

In my modules/gapi/gapi.php and have same problem.

Any solution ?

 

My module version : 1.2.0

PRESTA SHOP: 1.6.0.14

Link to comment
Share on other sites

Hi,

I have the same problem as moderk, my version of presta is 1.6.0.5, because I made update this module to 1.2.0 and then I remove true value from getContextShopID functions.

When I make autorization then I saw message, that I should confirm - so I confirm this.

However in google Analitics, I see only how many users is on my site, I don't see conversions in E-commerce even I saw It earlier.

Can anybody know where the problem is?

Link to comment
Share on other sites

  • 2 weeks later...

 

Hi,

 

 

but problem is in API Google Analytics module. Try change in modules/gapi/gapi.php this two rows:

 

$shop = new Shop(Shop::getContextShopID(true));

and

$shop = new Shop(Shop::getContextShopID(true));

to (only remove true)

$shop = new Shop(Shop::getContextShopID());

 

 

Grazie!!! Thank u so much navodyc4 !!!! 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

This solution works 4 me ª!! tnx navodyc4

 

 

Hi,

 

 

but problem is in API Google Analytics module. Try change in modules/gapi/gapi.php this two rows:
 

$shop = new Shop(Shop::getContextShopID(true));

and

$shop = new Shop(Shop::getContextShopID(true));

to (only remove true)

$shop = new Shop(Shop::getContextShopID());
Link to comment
Share on other sites

It also worked for me!

 

 

Hi,

 

 

but problem is in API Google Analytics module. Try change in modules/gapi/gapi.php this two rows:

 

$shop = new Shop(Shop::getContextShopID(true));

and

$shop = new Shop(Shop::getContextShopID(true));

to (only remove true)

$shop = new Shop(Shop::getContextShopID());

Thank you navodyc4!

It worked for me!

Prestashop version 1.6.0.14

 

Edited by carmy (see edit history)
Link to comment
Share on other sites

Has anybody found a solution to get rid of this annoying error:

 

2 fouten

  1. gapi (parse fout in /modules/gapi/gapi.php)
  2. gapi (klasse ontbreekt in /modules/gapi/gapi.php)

Edit:

 

Found the solution. After you've edited the file and GAPI is working, put "true" back into the lines and upload the file again. Errors are gone and it is still working.

Edited by Eurobesparen (see edit history)
Link to comment
Share on other sites

I almost forgot how I got that error Cannot retrieve test results

Anyway, I went back to modules and searched gapi,

I copied the client id, client secret and profile info,

Then clicked save & configure & save & authenticate, no errors.

So I'm guessing the error is gone.

Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...

Hello,

 

I have the same issue as JackusD. It was working perfectly for nearly a year and suddenly started showing "Google is unreachable (check your firewall)".

 

I tried all the solutions I could find in this forum without success.

 

Does anyone have a real way to fix this ?

 

Thanks in advance,

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Hey @Vlam,

I've been dealing with an erratic working on the default Analytics module for several months, so what I decided to do was to simply put the analytics code directly into the header.tpl under the /themes/mytheme/ location and inside literal tags. Everything runs smoothly now.

Link to comment
Share on other sites

Thanks, @JLeonrp, I'll give this a go! Were you getting the "Google is unreachable (check your firewall)" error too?

Yes @JackusD, among others. Tested a lot of possible solutions but nothing worked, so I decided to go back to basis and write the code into the header and now the analytics work like a charm.

 

Of course, don't expect to see Google analytics graphs or results on your backoffice. I disabled the module to avoid confusion.

Link to comment
Share on other sites

  • 3 weeks later...
  • 5 months later...

I use PS 1.6.1.6 and gapi v1.2.1 still get this error after havin set up everything in Google and gapi module:

 

 

400. That’s an error.

Error: invalid_request

Missing required parameter: redirect_uri

Learn more

Request Details

 

But I don'T get it, the redirect_url is part of the reqeust as I can see in the last line: "amp;client_id=55059508707-dg3clu76j__removed_by_me__nrnajefogaik.apps.googleusercontent.com"

 

???

Edited by Marek_O (see edit history)
Link to comment
Share on other sites

I got a bit further, i found out the during the credential test, the gapi modules decode every "&" in the url to "amp;" but the url ends up corrupted ...

 

like "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=..." but it should be:

https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=

 

So after deleting all "amp;" and just hitting enter, i got the google page to grant access, but now i get the Error in the module saying:

 

"Google API Authorization granted but access token cannot be retrieved"
and

"Cannot retrieve test results"

Link to comment
Share on other sites

×
×
  • Create New...