Stamped aggregate rating & review error

#38390
  • Resolved peeyoosh kumar
    Rank Math pro

    Hello:

    We are using Stamped as review collector on our website along with rankmath suite. When we test the data from Google structure data tools & Rich results are getting error message on “aggregateRating” & “review” fields.

    When i contacted Stamped they shared the attached file to be replaced and the below script to be added to footer. Although i do not want to change the source file of Rankmath plugin as once i upgrade those changes would be lost and it would be a tough task to get it back again up and running.

    1.In this location, please update the class-product.php (attached in this ticket)
    /wp-content/plugins/seo-by-rank-math/includes/modules/rich-snippet/snippets
    2.In WooCommerce footer, please add these JS script:

    <script>
    function addEventListenerStamped(el, eventName, handler) {
    if (el.addEventListener) { el.addEventListener(eventName, handler); }
    else { el.attachEvent('on' + eventName, function () { handler.call(el); }); }
    }
    
    addEventListenerStamped(document, 'stamped:reviews:loaded', function(e) {
    var ratingCount = jQuery('meta[itemprop="reviewCount"]').attr('content');
    var ratingValue = jQuery('meta[itemprop="ratingValue"]').attr('content');
    
    var richSnippet = {
    "@id": location.href + '#product',
    "@context": "http://schema.org",
    "@type": "Product"
    }
    
    if (parseInt(ratingValue) > 0){
    richSnippet.aggregateRating = {
    "@type": "AggregateRating",
    "ratingValue": ratingValue,
    "reviewCount": ratingCount
    }
    }
    var script = document.createElement('script');
    script.type = 'application/ld+json';
    script.innerHTML = JSON.stringify(richSnippet);
    document.getElementsByTagName('head')[0].appendChild(script);
    });
    
    </script>

    Is there some solution Rankmath team can offer so it works out of the box?

    Regards

Viewing 15 replies - 1 through 15 (of 18 total)
  • Hello,

    Thank you for contacting Rank Math today.

    I have submitted this suggested fix to our dev team and we will be reaching out in a short while to discuss this further.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Since there is no option to attach a file here which they amended, let me know how to share that as well? Since that file i have not shared initially in the ticket.

    Hi Peeyoosh,

    Thanks for the reply.

    Please upload the file to Google Drive and then share the public access link on the sensitive data section.

    We are looking forward to your response.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    I see in the new file, you added the @id & mpn attributes in the product schema. You can do this by adding following filter code in your theme’s functions.php file:

    
    add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
    	global $post;
    	$entity[ '@id' ] = get_the_permalink( $post ) . '#product';
    	$entity[ 'mpn' ] =  isset( $entity[ 'brand' ] ) ? $entity[ 'brand' ] : '';
    	return $entity;
    });
    
    

    I hope that helps.

    OK so just to understand it correct.

    The JS script i shared initially goes in the footer of woocommerce.

    the code snippet Pratik shared goes in Themefunctions.php of child theme.

    And this should do the job?

    Regards

    Well i tried that and it does not solve the problem.
    https://prntscr.com/rmgosy

    Hello,

    Well, i tried that and it does not solve the problem.
    https://prntscr.com/rmgosy

    On which product, do you get this error? Can you add the link in the Sensitive Data Section with your site’s admin access?

    Looking forward to helping you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    We tried on Variable products and the result is same for all variable products. After adding the code you can select any variable product from home page.

    Hello:

    Any update on this?

    Regards

    Hi Peeyoosh,

    Apologies for the delay in getting back to you.

    We are checking this and we will be in touch in a short while.

    Your continued patience is highly appreciated. Thank you.

    Hi:

    I just extended the login to another week so the support is able to login just in case they faced any trouble.

    Regards

    Hello,

    I logged into your site and I added the code which I provided you before. Now, I see the Product schema is showing unique ID.

    Can you please contact the Stamped plugin team and ask them, how to get the Reviews data using PHP code? Adding Javascript code which they had provided will not fix the issue. The GSC will still throw the error as it reads the data which is in the DOM when document is loaded.

    Please let us know once they provide the PHP function.

    Thank you.

    Hello Pratik:

    I contacted Stamped.Io support and this is what they told. Let me know please if that helps.

    The ratings are stored on WooCommerce, so rankmath can actually use the following PHP codes:

    $stampedDBData = get_post_meta($product_id, “stamped_io_product_reviews_new”, true);
    $stampedDBData[“rating”];
    $stampedDBData[“count”];

    Please let us know if that works?

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 15 replies - 1 through 15 (of 18 total)

The ticket ‘Stamped aggregate rating & review error’ is closed to new replies.