When AMP is activated it conflicts with Google Product & Review rich snippet
-
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>
- You must be logged in to reply to this topic.