Support » Plugin: AMP » amp-ad extension .js script’ is missing or incorrect errors

  • Resolved gooma2

    (@gooma2)


    Hi,

    Thanks so much for this great plugin. As Google has done the new search console, I’m seeing this error message and trying to figure out if anyone has an answer to fix this please.

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

    I don’t know if this fix will be in an AMP plugin update coming up or if it’s something we need to figure out for ourselves.

    Thanks again.

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    What is an example AMP URL that has the problem?

    I am also having this issue. When I look in the network tab of my browser I see it is loading the amp-ad-0.1.js file but it is not in the HTML so it is not valid according to Google. See below for a link to a post with the warning:

    https://skift.com/2018/02/12/airbnb-hedge-fund/amp

    Plugin Author Weston Ruter

    (@westonruter)

    @mikeiskool On https://validator.ampproject.org/#url=https%3A%2F%2Fskift.com%2F2018%2F02%2F12%2Fairbnb-hedge-fund%2Famp I see:

    The tag ‘amp-ad extension .js script’ is missing or incorrect, but required by ‘amp-ad’. This will soon be an error. DEPRECATION
    line 3, column 383

    So I think the issue is that your are using amp-ad but aren’t explicitly including the component script. Apparently this used to not be required but it soon will be.

    How are you adding amp-ad to your AMP pages?

    We are loading the amp-ad using amp_content_sanitizers (see below). How would you recommend we load the amp-ad extension script?

    
    class SK_AMP_Ad extends AMP_Base_Sanitizer {
        public function sanitize() {
            $body = $this->get_body_node();
    
            // Build our amp-ad tag
            $style_node = AMP_DOM_Utils::create_node( $this->dom, 'div', array(
                'class' => 'amp-ad-style',
                ));
            
            $ad_node = AMP_DOM_Utils::create_node( $this->dom, 'amp-ad', array(
                // Taken from example at https://github.com/ampproject/amphtml/blob/master/builtins/amp-ad.md
                'width' => 300,
                'height' => 250,
                'type' => 'doubleclick',
                'data-slot' => '/xxx/640x480_ROS',
                'json' => $sponsAd,
            ) );
    
            // Add a placeholder to show while loading
            $fallback_node = AMP_DOM_Utils::create_node( $this->dom, 'amp-img', array(
                'placeholder' => '',
                'layout' => 'fill',
                'src' => 'https://placehold.it/300X250/fff/ccc?text=ADVERTISEMENT',
            ) );
            $ad_node->appendChild( $fallback_node );
            $style_node->appendChild( $ad_node );
        }
    }
    
    • This reply was modified 1 year, 5 months ago by  mikeiskool.

    I added the Adsense for AMP plugin and now the ‘valid with warnings’ errors have all gone away into the valid links box.

    I guess it needed that.

    Plugin Author Weston Ruter

    (@westonruter)

    A custom AMP component script can be added using code like the following placed in your theme or plugin:

    add_filter( 'amp_post_template_data', function( $data ) {
    	$data['amp_component_scripts'] = array_merge(
    		$data['amp_component_scripts'],
    		array(
    			'amp-ad' => 'https://cdn.ampproject.org/v0/amp-ad-latest.js',
    		)
    	);
    	return $data;
    } );

    Note that as of v0.7 of the plugin this will be unnecessary, as the components will be automatically looked up based on the sanitized content.

    • This reply was modified 1 year, 5 months ago by  Weston Ruter.
    Plugin Author Weston Ruter

    (@westonruter)

    Sorry, I had a typo and should have referenced amp-ad-latest.js not amp-ads-latest.js. Fixed in my reply as well.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘amp-ad extension .js script’ is missing or incorrect errors’ is closed to new replies.