amphtml: 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&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

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 32 (17 by maintainers)

Most upvoted comments

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’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.

From the discussion above, I believe the cause to the issue above is that the container hasn’t been published yet. So the required header isn’t added by the server. The testing page probably hadn’t been updated for a while. @mrienstra Are you seeing the same error with your own site after publishing changes.

cc @zikas to comment on the GTM error message.

No triggers provided if I remember correctly, just a mistake on my part.

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!

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.