AMP-Analytics: Errors with Google Tag-Manager
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>m.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
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?
CC @newmuis for prod patch
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>m.url=SOURCE_URL&__amp_source_origin=https%3A%2F%2Fwww.simgolf.dk'. (see https://www.ampproject.org/docs/reference/components/amp-analytics)
Yes, the work-around doesn't work. The production release is being rolled back and things should return to normal soon.
Versioned prod has finished rolling out 1516337355291. Still waiting on unversioned prod.
Unversioned prod has finished rolling out 1516337355291 as well.
@newmuis thanks! was having the same issue as well. Thankfully I found this ticket! Thanks for creating the ticket @lintal
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.
Confirmed that the fix is in prod and canary.
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>m.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 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 See this page for example.
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.
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>m.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 I got a 503 on the above link.
/cc @zhouyx
@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)
Any Update? Due to this I was stuck and can not able to use gtm in my page
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?
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!
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?