amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

AMP-Analytics: Errors with Google Tag-Manager

Open lintal opened this issue 8 years ago • 32 comments

What's the issue?

A change made in the following PR is resulting in the __amp_source_origin to be excluded from requests to an amp-analytics config file. https://github.com/ampproject/amphtml/pull/12787

Google Tag Manager appears to omit all CORS headers unless this GET parameter is included. Because Access-Control-Allow-Origin: * is therefore not included by GTM, the browser throws the following error:

Failed to load https://www.googletagmanager.com/amp.json?id=GTM-KCTM85F&gtm.url=https%3A%2F%2Fwww.simgolf.dk%2F: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.simgolf.dk' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

How do we reproduce the issue?

One example provided in the #general Slack channel was for https://www.simgolf.dk/

What browsers are affected?

I am assuming all.

Which AMP version is affected?

The latest build: https://github.com/ampproject/amphtml/releases/tag/1516396600278

lintal avatar Jan 24 '18 14:01 lintal

The work-around I can see for this is to manually append the __amp_source_origin parameter to the end of the amp-analytics config URL. However is there a better way?

lintal avatar Jan 24 '18 14:01 lintal

CC @newmuis for prod patch

cramforce avatar Jan 24 '18 15:01 cramforce

i want to add that the workaround that @lintal suggest makes tagmanager work, but doing that gives me the following amp validation error:

https://www.simgolf.dk/:1:42210 The attribute 'config' in tag 'amp-analytics' is set to the invalid value 'https://www.googletagmanager.com/amp.json?id=GTM-KCTM85F&gtm.url=SOURCE_URL&__amp_source_origin=https%3A%2F%2Fwww.simgolf.dk'. (see https://www.ampproject.org/docs/reference/components/amp-analytics)

SimonHogstromRonbol avatar Jan 24 '18 15:01 SimonHogstromRonbol

Yes, the work-around doesn't work. The production release is being rolled back and things should return to normal soon.

cramforce avatar Jan 24 '18 15:01 cramforce

Versioned prod has finished rolling out 1516337355291. Still waiting on unversioned prod.

newmuis avatar Jan 24 '18 15:01 newmuis

Unversioned prod has finished rolling out 1516337355291 as well.

newmuis avatar Jan 24 '18 16:01 newmuis

@newmuis thanks! was having the same issue as well. Thankfully I found this ticket! Thanks for creating the ticket @lintal

kristiandavid avatar Jan 24 '18 16:01 kristiandavid

In our analytics system, we have the same problems: browsers don't load config coz CORS headers are wrong. Workaround made using "Origin" header line (set AMP CORS headers using Origin instead of __amp_source_origin) does not work for Google AMP Cache requests.

ilnarb avatar Jan 24 '18 16:01 ilnarb

Confirmed that the fix is in prod and canary.

zhouyx avatar Jan 26 '18 00:01 zhouyx

I'm experiencing the same issue, even though it was said that the fix has been released. Do I need to change something in Google Tag Manager configuration?

Failed to load https://www.googletagmanager.com/amp.json?id=MY_ID&gtm.url=https%3A%2…mysite.com&__amp_source_origin=https%3A%2F%2Fwww.mysite.com: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.mysite.com' is therefore not allowed access. The response had HTTP status code 403. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

sryze avatar Mar 08 '18 05:03 sryze

@sryze I checked with the example provided in slack channel

One example provided in the #general Slack channel was for https://www.simgolf.dk/

And it works. Could you please provide me your example page to further test with. Thanks.

zhouyx avatar Mar 08 '18 19:03 zhouyx

@zhouyx See this page for example.

sryze avatar Mar 09 '18 01:03 sryze

Hi @sryze I ran your page and was able to see the __amp_source_origin setted correctly. I then ran your page locally but replaced the GTM id with another one. Then I was able to get the GTM response correctly. Could you please double check with GTM that you have configured it correctly. Thanks a lot! Please let us know if it still doesn't work.

zhouyx avatar Mar 09 '18 18:03 zhouyx

I'm experiencing the same issue, even though it was said that the fix has been released. Do I need to change something in Google Tag Manager configuration?

Failed to load https://www.googletagmanager.com/amp.json?id=GTM-TQFM9MR&gtm.url=https%3A%2F%2Fstaging.carwale.com%3A9012%2Famp%2Fused%2Fcars-in-pune%2F&__amp_source_origin=https%3A%2F%2Fstaging.carwale.com%3A9012: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://staging.carwale.com:9012' is therefore not allowed access. The response had HTTP status code 404. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

You can check it for following url. https://staging.carwale.com:9012/amp/used/cars-in-pune/#development=1

yajiv185 avatar Oct 10 '18 14:10 yajiv185

@yajiv185 I got a 503 on the above link.

/cc @zhouyx

lannka avatar Oct 10 '18 23:10 lannka

@lannka Actually, I have given a link of our testing environment, So it will be not available between 12:00 am-IST(6:30 PM UTC) to 9:00 am- IST(3:30 AM UTC). So if possible please don't check during this time.

Or you can check here(It is simple page which with no data, only amp-analytics code for gtm)

yajiv185 avatar Oct 11 '18 08:10 yajiv185

Any Update? Due to this I was stuck and can not able to use gtm in my page

yajiv185 avatar Oct 26 '18 14:10 yajiv185

Any Update? Due to this I was stuck and can not able to use gtm in my page

Maybe it's a silly question but, have you published your GTM container?

david-aa avatar Nov 14 '18 09:11 david-aa

I experienced this issue as well (same error message). I was attempting to verify proper AMP GTM setup before adding anything (tags / triggers / variables) to the new AMP GTM container, which perhaps effectively means the container had not been published.

It was resolved by publishing changes. After adding the first tag & trigger, I noticed the error disappeared when I turned on preview mode. I then published the changes, and have yet to see the error again.

@david-aa: Thanks for the clue!

mrienstra avatar Dec 11 '18 20:12 mrienstra

It's 2020 May 27th, and I viewing @sryze test page. It's still erroring out. It uses the code what GTAG site suggests. I'm experiencing the problem with my site as well. How to overcome this?

MrCsabaToth avatar May 27 '20 20:05 MrCsabaToth