• Resolved Ronak Ganatra

    (@ronakganatra)


    When AMP is activated it conflicts with Google Product & Review rich snippet.

    When AMP is active, the AMP plugin adds a javascript in the head to redirect to the amp but that is somehow making some issues and in the google rich snippet testing tool when we try to test the URL or code it gives an error or doesn’t show the product and review rich snippet and if we disable the AMP, it works correctly and show the Product and review rich snippets.

    Video:

    https://www.loom.com/share/cfa9de8d2f724f8b8523f891fa0df56f?sid=26a8da85-eb63-4c5a-a853-8f6ae7c8058e

    Code Affecting :
    plugins/amp/assets/js/mobile-redirection.js
    plugins/amp/src/MobileRedirection.php
    in the function : add_mobile_redirect_script – ‘mobileUserAgents’ => $this->get_mobile_user_agents(), ( due to below part the issue exist )

    I tried with the latest plugin version 2.5.4

    Not Working Code on rich snippets:

    <script type="text/javascript">
        /* <![CDATA[ */
        (()=>{var e={};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),function({ampUrl:n,isCustomizePreview:t,isAmpDevMode:r,noampQueryVarName:o,noampQueryVarValue:s,disabledStorageKey:i,mobileUserAgents:a,regexRegex:c}){if("undefined"==typeof sessionStorage)return;const d=new RegExp(c);if(!a.some((e=>{const n=e.match(d);return!(!n||!new RegExp(n[1],n[2]).test(navigator.userAgent))||navigator.userAgent.includes(e)})))return;e.g.addEventListener("DOMContentLoaded",(()=>{const e=document.getElementById("amp-mobile-version-switcher");if(!e)return;e.hidden=!1;const n=e.querySelector("a[href]");n&&n.addEventListener("click",(()=>{sessionStorage.removeItem(i)}))}));const g=r&&["paired-browsing-non-amp","paired-browsing-amp"].includes(window.name);if(sessionStorage.getItem(i)||t||g)return;const u=new URL(location.href),m=new URL(n);m.hash=u.hash,u.searchParams.has(o)&&s===u.searchParams.get(o)?sessionStorage.setItem(i,"1"):m.href!==u.href&&(window.stop(),location.replace(m.href))}({"ampUrl":"https:\/\/example.co?amp","noampQueryVarName":"noamp","noampQueryVarValue":"mobile","disabledStorageKey":"amp_mobile_redirect_disabled","mobileUserAgents":["Mobile","Android","Silk\/","Kindle","BlackBerry","Opera Mini","Opera Mobi"],"regexRegex":"^\\\/((?:.|\\n)+)\\\/([i]*)$","isCustomizePreview":false,"isAmpDevMode":true})})();
        /* ]]> */
        </script>`
        
       <script type="application/ld+json">{"@context":"https://schema.org/","@type":"Product","name":"The Nike Air Force 1 “Be The One” Inspires Athletes Ahead Of The 2024 Olympics","image":"https://example.com?w=780&h=550&crop=1","aggregateRating":{"@type":"AggregateRating","ratingValue":5,"reviewCount":10}}</script>
    

    Working Code on Rich snippets:

    <script type="text/javascript">
          /* <![CDATA[ */
          (()=>{var e={};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),function({ampUrl:n,isCustomizePreview:t,isAmpDevMode:r,noampQueryVarName:o,noampQueryVarValue:s,disabledStorageKey:i,mobileUserAgents:a,regexRegex:c}){if("undefined"==typeof sessionStorage)return;const d=new RegExp(c);if(!a.some((e=>{const n=e.match(d);return!(!n||!new RegExp(n[1],n[2]).test(navigator.userAgent))||navigator.userAgent.includes(e)})))return;e.g.addEventListener("DOMContentLoaded",(()=>{const e=document.getElementById("amp-mobile-version-switcher");if(!e)return;e.hidden=!1;const n=e.querySelector("a[href]");n&&n.addEventListener("click",(()=>{sessionStorage.removeItem(i)}))}));const g=r&&["paired-browsing-non-amp","paired-browsing-amp"].includes(window.name);if(sessionStorage.getItem(i)||t||g)return;const u=new URL(location.href),m=new URL(n);m.hash=u.hash,u.searchParams.has(o)&&s===u.searchParams.get(o)?sessionStorage.setItem(i,"1"):m.href!==u.href&&(window.stop(),location.replace(m.href))}({"ampUrl":"https:\/\/example.co?amp","noampQueryVarName":"noamp","noampQueryVarValue":"mobile","disabledStorageKey":"amp_mobile_redirect_disabled","regexRegex":"^\\\/((?:.|\\n)+)\\\/([i]*)$","isCustomizePreview":false,"isAmpDevMode":true})})();
          /* ]]> */
          </script>
          
          <script type="application/ld+json">{"@context":"https://schema.org/","@type":"Product","name":"The Nike Air Force 1 “Be The One” Inspires Athletes Ahead Of The 2024 Olympics","image":"https://example.com?w=780&h=550&crop=1","aggregateRating":{"@type":"AggregateRating","ratingValue":5,"reviewCount":10}}. </script>
    
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Milind More

    (@milindmore22)

    Hello @ronakganatra

    Thanks for reaching out.

    We use a small JavaScript code on non-AMP pages to detect mobile devices and redirect them to the faster AMP version for a better user experience. We never faced issue about user agents affecting rich results.

    To troubleshoot, please check your website for browser console errors when viewing it in mobile mode, make sure it’s not conflicting.

    If you prefer, you can disable mobile redirection in the AMP plugin settings. This will stop redirects on the mobile devices, but your website will still serve AMP pages from search results.

    We hope this helps!

    Thread Starter Ronak Ganatra

    (@ronakganatra)

    Hello @milindmore22 ,

    I understand your reply and I know it is about to redirect. The issue is due to the code added from AMP plugin is clear and I have verified with other plugins as there is not any other plugin conflicts.
    Browser console doesn’t have any errors but it is conflict with Google Rich snippets and that too with Product schema ( For Article it is working ).

    I have clearly explained in the video and also provided code snippets and the part of code which is conflicting, I hope your support team can help to fix it.

    If this is due to browserr console error it should not show error on the rich snippet tool.
    Video: https://www.loom.com/share/cfa9de8d2f724f8b8523f891fa0df56f?sid=26a8da85-eb63-4c5a-a853-8f6ae7c8058e

    Not Working Code on rich snippets:

    <script type="text/javascript">
        /* <![CDATA[ */
        (()=>{var e={};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),function({ampUrl:n,isCustomizePreview:t,isAmpDevMode:r,noampQueryVarName:o,noampQueryVarValue:s,disabledStorageKey:i,mobileUserAgents:a,regexRegex:c}){if("undefined"==typeof sessionStorage)return;const d=new RegExp(c);if(!a.some((e=>{const n=e.match(d);return!(!n||!new RegExp(n[1],n[2]).test(navigator.userAgent))||navigator.userAgent.includes(e)})))return;e.g.addEventListener("DOMContentLoaded",(()=>{const e=document.getElementById("amp-mobile-version-switcher");if(!e)return;e.hidden=!1;const n=e.querySelector("a[href]");n&&n.addEventListener("click",(()=>{sessionStorage.removeItem(i)}))}));const g=r&&["paired-browsing-non-amp","paired-browsing-amp"].includes(window.name);if(sessionStorage.getItem(i)||t||g)return;const u=new URL(location.href),m=new URL(n);m.hash=u.hash,u.searchParams.has(o)&&s===u.searchParams.get(o)?sessionStorage.setItem(i,"1"):m.href!==u.href&&(window.stop(),location.replace(m.href))}({"ampUrl":"https:\/\/example.co?amp","noampQueryVarName":"noamp","noampQueryVarValue":"mobile","disabledStorageKey":"amp_mobile_redirect_disabled","mobileUserAgents":["Mobile","Android","Silk\/","Kindle","BlackBerry","Opera Mini","Opera Mobi"],"regexRegex":"^\\\/((?:.|\\n)+)\\\/([i]*)$","isCustomizePreview":false,"isAmpDevMode":true})})();
        /* ]]> */
        </script>`
        
       <script type="application/ld+json">{"@context":"https://schema.org/","@type":"Product","name":"The Nike Air Force 1 “Be The One” Inspires Athletes Ahead Of The 2024 Olympics","image":"https://example.com?w=780&h=550&crop=1","aggregateRating":{"@type":"AggregateRating","ratingValue":5,"reviewCount":10}}</script>
    

    Working Code on Rich snippets:

    <script type="text/javascript">
          /* <![CDATA[ */
          (()=>{var e={};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),function({ampUrl:n,isCustomizePreview:t,isAmpDevMode:r,noampQueryVarName:o,noampQueryVarValue:s,disabledStorageKey:i,mobileUserAgents:a,regexRegex:c}){if("undefined"==typeof sessionStorage)return;const d=new RegExp(c);if(!a.some((e=>{const n=e.match(d);return!(!n||!new RegExp(n[1],n[2]).test(navigator.userAgent))||navigator.userAgent.includes(e)})))return;e.g.addEventListener("DOMContentLoaded",(()=>{const e=document.getElementById("amp-mobile-version-switcher");if(!e)return;e.hidden=!1;const n=e.querySelector("a[href]");n&&n.addEventListener("click",(()=>{sessionStorage.removeItem(i)}))}));const g=r&&["paired-browsing-non-amp","paired-browsing-amp"].includes(window.name);if(sessionStorage.getItem(i)||t||g)return;const u=new URL(location.href),m=new URL(n);m.hash=u.hash,u.searchParams.has(o)&&s===u.searchParams.get(o)?sessionStorage.setItem(i,"1"):m.href!==u.href&&(window.stop(),location.replace(m.href))}({"ampUrl":"https:\/\/example.co?amp","noampQueryVarName":"noamp","noampQueryVarValue":"mobile","disabledStorageKey":"amp_mobile_redirect_disabled","regexRegex":"^\\\/((?:.|\\n)+)\\\/([i]*)$","isCustomizePreview":false,"isAmpDevMode":true})})();
          /* ]]> */
          </script>
          
          <script type="application/ld+json">{"@context":"https://schema.org/","@type":"Product","name":"The Nike Air Force 1 “Be The One” Inspires Athletes Ahead Of The 2024 Olympics","image":"https://example.com?w=780&h=550&crop=1","aggregateRating":{"@type":"AggregateRating","ratingValue":5,"reviewCount":10}}. </script>
    Plugin Author Weston Ruter

    (@westonruter)

    It seems like the issue is not with the AMP plugin but rather with Google’s Rich Results Test, right? Apparently it isn’t working correctly with JavaScript-based redirection. So I think there are a few options:

    1. Switch to server-side redirection via this plugin code: add_filter( 'amp_mobile_client_side_redirection', ' __return_false' ); As long as your page cache is varying by mobile and desktop, then this would be the best solution.
    2. When using the Google Rich Results Test, switch from using the “smartphone” user agent to the “desktop” user agent in the dropdown next to the Test URL button.
    3. Turn off mobile redirection when you want to test a URL.
    4. Append ?noamp=mobile to the canonical URL that you’re testing. This will disable redirection for the URL.
    Plugin Support Milind More

    (@milindmore22)

    @ronakganatra As we didn’t receive a response I’ll mark this as resolved. Feel free to open a new support topic if you require any further assistance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.