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

Created on 9 Nov 2017  Â·  20Comments  Â·  Source: ampproject/amphtml

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.

Soon Bug monetization

Most helpful comment

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.

All 20 comments

/to @jasti @zhouyx

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

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

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

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.

@tlong2 any updates on documenting this?

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.

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?

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.

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.

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

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.

5 months and this is still an issue :(

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?

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

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.

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

Ads are not loading on desktop.

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.

16599 and #12614 appear to be similar bugs.

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

Was this page helpful?
0 / 5 - 0 ratings