Jump to content

How to Google Customer Reviews Opt-In

Recommended Posts

Does anyone have experience with Google Customer Reviews Opt-in Integration on the order confirmation page?

I've followed all the instructions to the best of my understanding, but don't see the Opt-in dialog box appear on the order confirmation page when in test mode. For 7.1, if it matters.

*EDIT - Works if I put in a static date, but fails if I use PHP for a dynamic delivery date. I have no experience with PHP, so I don't know what the issue might be.

Here is my code in Settings>Advanced>Code Injection>Order Confirmation Page

<script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>
<script>
  window.renderOptIn = function() {
    window.gapi.load('surveyoptin', function() {
      window.gapi.surveyoptin.render(
        {
          // REQUIRED FIELDS
          "merchant_id": *********,
          "order_id": "{orderId}",
          "email": "{customerEmailAddress}",
          "delivery_country": "US",
          "estimated_delivery_date": "<?php echo date("Y-m-d", strtotime("+ 7 days")); ?>"
        });
    });
  }
</script>

Google's instructions are here - https://support.google.com/merchants/answer/7106244

Thanks for your advice!

Edited by CharlieW
Clarity, progress update
Link to comment
  • 1 month later...
  • 4 weeks later...
  • 1 month later...

Hello,

If you haven't sorted this already, you need to use Javascript to generate the date - won't work with PHP. I believe the date is used by Google to send the review to the cusomer so it needn't be too specific, in this example I've just added 7 days to the current date:

<script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>
<script>
  window.renderOptIn = function() {
    window.gapi.load('surveyoptin', function() {
      const deliveryDate = new Date();
      deliveryDate.setDate(deliveryDate.getDate() + 7);
      function formatDate(date) {
        var d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear();

        if (month.length < 2) 
               month = '0' + month;
        if (day.length < 2) 
            day = '0' + day;
        return [year, month, day].join('-');
    }
      
      window.gapi.surveyoptin.render(
        {
          // REQUIRED FIELDS
          "merchant_id": 12345678,
          "order_id": "{orderId}",
          "email": "{customerEmailAddress}",
          "delivery_country": "GB",
          "estimated_delivery_date": formatDate(deliveryDate)
          // OPTIONAL FIELDS
          //"products": [{"gtin":"GTIN1"}, {"gtin":"GTIN2"}]
        });
    });
  }
</script>

Hope it helps

Link to comment
  • 9 months later...
On 4/7/2021 at 10:39 AM, Adrian213 said:

Hello,

If you haven't sorted this already, you need to use Javascript to generate the date - won't work with PHP. I believe the date is used by Google to send the review to the cusomer so it needn't be too specific, in this example I've just added 7 days to the current date:

<script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>
<script>
  window.renderOptIn = function() {
    window.gapi.load('surveyoptin', function() {
      const deliveryDate = new Date();
      deliveryDate.setDate(deliveryDate.getDate() + 7);
      function formatDate(date) {
        var d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear();

        if (month.length < 2) 
               month = '0' + month;
        if (day.length < 2) 
            day = '0' + day;
        return [year, month, day].join('-');
    }
      
      window.gapi.surveyoptin.render(
        {
          // REQUIRED FIELDS
          "merchant_id": 12345678,
          "order_id": "{orderId}",
          "email": "{customerEmailAddress}",
          "delivery_country": "GB",
          "estimated_delivery_date": formatDate(deliveryDate)
          // OPTIONAL FIELDS
          //"products": [{"gtin":"GTIN1"}, {"gtin":"GTIN2"}]
        });
    });
  }
</script>

Hope it helps

Hi @Adrian213, 

Thank you very much for this. So does this code you've kindly shared work for you?

EDIT: Code above works a treat! I've noticed companies such as Nudie Jeans use this service and you are able to write a review straight after your purchase - has anybody any idea how you would be able to change the code so this happens?

Many thanks!

Edited by ferguswood
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.