amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-analytics is already registered. uncaught (in promise) Error

Open kevinlisota opened this issue 8 years ago • 9 comments

We are experiencing an issue with the amp-analytics script causing javascript errors because doubleclick is attempting to load it a second time.

Specifically, we get two errors:

  1. url.js:345 amp-analytics is already registered. The script tag for amp-analytics is likely included twice in the page.
  2. log.js:319 Uncaught (in promise) Error: amp-analytics is already registered. The script tag for amp-analytics is likely included twice in the page.​​​

Because we use amp-analytics, we include the required amp-analytics script in the page header. That loads and our analytics providers work fine.

Looking at the network log, I can see that amp-analytics-0.1.js is being loaded a second time. The initiator is https://securepubads.g.doubleclick.net/gampad/ads, so it is being loaded a second time by doubleclick.

Any ideas on how to resolve?

kevinlisota avatar Dec 09 '17 14:12 kevinlisota

/to @lannka

aghassemi avatar Dec 11 '17 19:12 aghassemi

@keithwrightbos do you in what case doubleclick fastfetch will reload amp-analytics extension? Or is it a regression that we failed to check existing extension on the page?

lannka avatar Dec 11 '17 19:12 lannka

Ping @keithwrightbos

jasti avatar Jan 18 '18 19:01 jasti

I'd just like to add that we've been seeing the same error for 3rd party serving of amphtml ads as well. There seems to be some kind of correlation between the error and the response time allowance - it appears under the 300ms deadline, but we never saw it when the time allowance was raised temporarily for testing purposes, then it started to appear again when we went back down to 300ms.

lexandera avatar Apr 20 '18 13:04 lexandera

We insert amp-analytics using src/extension-analytics#insertAnalyticsElement where we pass loadAnalytics as true (https://github.com/ampproject/amphtml/blob/master/extensions/amp-ad-network-doubleclick-impl/0.1/amp-ad-network-doubleclick-impl.js#L951). insertAnalyticsElement indicates that it will "Force load analytics extension if script not included in page" so if this is causing the extension to be loaded again, then I would argue the bug is within that code (https://github.com/ampproject/amphtml/blob/master/src/extension-analytics.js#L55)

We also potentially load amp-analytics as part of FIE rendering which calls extensions.preloadExtension (https://github.com/ampproject/amphtml/blob/master/src/friendly-iframe-embed.js#L138). This code also indicates it only loads the extension if necessary: "Returns the promise that will be resolved when the extension has been loaded. If necessary, adds the extension script to the page.": https://github.com/ampproject/amphtml/blob/master/src/service/extensions-impl.js#L256

I'm guessing there is a race condition somewhere within that code.

keithwrightbos avatar Apr 20 '18 17:04 keithwrightbos

This issue hasn't been updated in awhile. @keithwrightbos Do you have any updates?

ampprojectbot avatar Sep 25 '18 09:09 ampprojectbot

This issue hasn't been updated in awhile. @keithwrightbos Do you have any updates?

ampprojectbot avatar Jan 09 '19 11:01 ampprojectbot

Answer from Google contact: To speed up the load of the creatives, they get auto-wrapped with AMP code, which turns them from a regular HTML or image creative into an AMP creative. This is called AMP embedded ad, and aims to render lighter and faster ads. Ad Manager will decide at run time if it's better to return the creative as it was original defined, or if there's the opportunity to deliver it as an AMP creative. As a result, given that some creatives can turn into AMP creatives while others don't, those that get turned into AMP creatives request the amp-analytics library, so it could be the case that multiple creatives are returned as AMP creatives (which is what's happening here).

In summary, those errors that appear in the console should not negatively impact ad performance in any way, and are the result of returning the creatives with an AMP wrapper that helps speed up the ad serving process.

scemii avatar Jun 25 '19 08:06 scemii

Closing based on last comment. Feel free to reopen if there is an impact to creatives.

calebcordry avatar Jul 03 '19 21:07 calebcordry