amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-auto-ads fails with "Unexpected end of JSON input"

Open jamescridland opened this issue 9 years ago • 20 comments

What's the issue?

When implementing amp-auto-ads according to the specifications, the module fails with an error in the console, saying: url.js:345 amp-auto-ads config xhr failed: SyntaxError: Unexpected end of JSON input​​​ and no ads are visible in the browser or requested.

On examining the network traffic, a call is made to a configuration file, at a URL looking similar to: https://pagead2.googlesyndication.com/getconfig/ama?client=ca-pub-(mypublishercode)&plah=(myURL)&ama_t=amp&url=https%3A%2F%2F(myURL)%2F&__amp_source_origin=https%3A%2F%2F(myURL)

This call returns a 200 OK response from Google AdSense, with HTTP headers indicating a zero-byte JSON file, "f.txt", should be downloaded:

content-disposition: attachment; filename="f.txt" content-length: 0 content-type: application/json; charset=UTF-8

Presumably, an attempt to parse this JSON file causes the error referred to at the top of this report.

How do we reproduce the issue?

A public URL is https://podnews.net/article/how-podcast-show-notes-display

Inspecting the console will display the error. No ads will be displayed. In the network tab, the zero-length file is requested in the file resource starting "ama?"

The AdSense account referred to in the code has amp-auto-ads marked as enabled.

What browsers are affected?

No ads display on any browser.

Which AMP version is affected?

This has never worked for me. Powered by AMP ⚡ HTML – Version 1509747505247

Other notes

I think this is a Google AdSense issue, and not really an amp-auto-ads issue. Repeated attempts to contact Google AdSense have failed. The 'feedback' from AdSense goes into a black hole. Leaving messages in the AdSense product forum are responded to by community editors telling me to leave a message in the AMP product forum. amp-auto-ads are only currently supported by Google AdSense, and I'm hoping that by leaving a full bug report here, the relevant people at AdSense and those involved with the amp-auto-ads module will be able to compare notes.

jamescridland avatar Nov 09 '17 10:11 jamescridland

/to @jasti @zhouyx

aghassemi avatar Nov 09 '17 17:11 aghassemi

@jasti Assigning to you for now given it seems related to Google AdSense more than AMP based on assessment by @jamescridland

aghassemi avatar Nov 09 '17 17:11 aghassemi

@jamescridland sorry about the hassle with AdSense product forum. Adding @tlong2 who is the TL for auto ads in Adsense, who can probably help take a look at this. Will also escalate internally to review support channels. Thanks for the report.

jasti avatar Nov 09 '17 18:11 jasti

@jamescridland, AdSense currently only returns a configuration for amp-auto-ads when the request is from a mobile user agent. When I emulate a mobile browser on the page you link to, I see a config returned (although it appears that it doesn't insert any ads on that particular URL).

Sorry the error message is not very helpful, I'll look into improving that.

tlong2 avatar Nov 10 '17 10:11 tlong2

OK. That needs documenting. I use AMP for all desktop web as well as mobile, and since all other AdSense calls work on desktop, it was a reasonable expectation that this one would. I'm quite disappointed about this.

I have tried to use amp-auto-ads on a high traffic website with 90% AdSense fill rate. It didn't work there either (on mobile either) so not sure what's going on.

OK, I'll cut my losses and remove this code. Please do document this for others.

jamescridland avatar Nov 10 '17 12:11 jamescridland

@tlong2 any updates on documenting this?

jasti avatar Dec 08 '17 20:12 jasti

Any updates? I get the same "Unexpected end of JSON input" error even when emulating a mobile browser (using Chrome Dev Tools). However, I'm not sure how the ad placements are supposed to be configured (or if I actually need to do that). The official docs say:

Given a sufficient number of valid placements (supplied in the configuration), amp-auto-ads tries to insert additional ads while adhering to a set of constraints specified by the ad network.

Further down there is a configuration spec which looks like it should be what I'm supposed to use, but it says:

The configuration is fetched from a third-party ad network at the URL defined in ad-network-config.js.

Which implies that it's not something that I write, and there's no indication of where I would put the code if it is. I read somewhere that it would pick up any existing <amp-ad> slots and use those, but when I left those in I get these warnings in Search Console:

The tag 'amp-ad extension .js script' is missing or incorrect, but required by 'amp-ad'. This will soon be an error.

Removing the <amp-ad> elements stops any ads showing on the pages.

svivian avatar Jan 22 '18 11:01 svivian

Wow, so this deviates from the other ads, in that it doesn't work on desktop? That caught me off-guard too (was debugging breakages and ended up here)

I still don't see this documented on https://www.ampproject.org/docs/reference/components/amp-ad or on https://github.com/ampproject/amphtml/blob/master/ads/google/adsense.md . Though given this seems to be a Google-Adsense-only restriction (in that other ad networks might work totally fine on desktop), perhaps the latter document is a better place to document it.

I'm guessing @jasti is the correct person to assign this to, based on commit history to amp-ads-related code?

mikelambert avatar Mar 10 '18 05:03 mikelambert

Hi, Mike - yes, they only work on mobile, unlike every single other AdSense implementation within AMP.

The amp-auto-ads implementation guide now says "Amp Auto ads will currently only show for users using a mobile device. Please test your site in a mobile device to see AMP auto ads." (though you can also test it in Chrome's mobile emulator). Of note: the ad units appear on iPads: so it appears not to be an issue with screen size, but instead is a policy decision.

It's frustratingly different from the standard adsense auto ads, and given that AMP has been very, very clear that AMP is for all websites, not just mobile, it's another example of one part of Google not knowing what another part of Google is doing.

Attempts to contact anyone within AdSense fails for a sub-$1000 monthly earner like me, so I have no way of getting anyone within AdSense to see sense here (if you'll pardon the pun).

In the meantime, you can implement these by also including standard AMP ads with a media control to only show above a certain screen size. auto-ads can coexist with standard AMP ad units.

jamescridland avatar Mar 10 '18 06:03 jamescridland

I'd add for @tlong2 's benefit: if standard AdSense auto-ads are now released to all and are seemingly the preferred style for AdSense going forward (and, in my experience, pay more), it seems nonsensical to restrict amp-auto-ads to mobile devices. I would welcome the opportunity to be able to feed this back higher-up the AdSense chain, if only I knew how; site feedback from AdSense's website falls into a black hole and never gets replied to.

jamescridland avatar Mar 10 '18 06:03 jamescridland

Any updates for "Unexpected end of JSON input" error even when emulating a mobile browser (using Chrome Dev Tools) My Error detail as blow amp-auto-ads config xhr failed: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data log.js:162:6 pa log.js:162:6 f.Pe log.js:217:6 f.error log.js:233:18 ea/< amp-auto-ads.js:99:10

stan0714 avatar Mar 15 '18 08:03 stan0714

Just a quick update - this issue has been communicated to the adsense team and they are looking into better documentation or opening it up to desktop. Thanks for your patience.

jasti avatar Mar 15 '18 23:03 jasti

5 months and this is still an issue :(

RadekHavelka avatar Mar 28 '18 12:03 RadekHavelka

this is still an issue:

here are some details found on https://www.locavores.co/loc amp-auto-ads config xhr failed: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data v0.js:2:163 qa https://cdn.ampproject.org/v0.js:2:163 f.Pe https://cdn.ampproject.org/v0.js:3:124 f.error https://cdn.ampproject.org/v0.js:3:297 fa/< https://cdn.ampproject.org/v0/amp-auto-ads-0.1.js:23:376

Any idea for a workaround?

ava007 avatar Mar 30 '18 05:03 ava007

@jasti @tlong2 I get this error even on mobile devices

seanthegeek avatar Apr 30 '18 12:04 seanthegeek

Web pages and ads published in the AMP open-source format load near instantly, giving users a smooth, more engaging experience on mobile and desktop.

NOPE.

sbefort avatar May 11 '18 17:05 sbefort

I believe I'm being also affected by this issue here: https://ppc.land

Ads are not loading on desktop.

rijoio avatar Jul 04 '18 17:07 rijoio

I am now getting ads on desktop using AMP auto-ads. https://media.info (mostly AMP) has a limited amount of automatic ads appearing.

Lots of errors, including "unable to fulfil ad strategy", and I don't really understand how to fix the HTML to make that happen; but it's there now, and works. I'm not entirely sure it's working as desired.

jamescridland avatar Jul 04 '18 18:07 jamescridland

#16599 and #12614 appear to be similar bugs.

jamescridland avatar Jul 12 '18 12:07 jamescridland

Duplicated with #16599 . let's track over there.

lannka avatar Jul 16 '18 19:07 lannka