Google OptIn Integration / Google Product Reviews

I finally figured out a solution to this problem. Don’t know if it will help anyone since this topic is so old, but I hope future people can find this answer.

The process involves using the getOrder function that @stant helpfully posted. On the checkout page, you can use getOrder to grab variables such as the customer email, order number and date.

When you have the variables, we need to pass it to the HTML iframe. Because iframes change the request url to a ‘yourdomain’.fileusr.com, it messes up the Google API call. To workaround this, I used http-functions (add a http-functions.js to your backend code). This is what I have for the code in that file:

`import { ok, badRequest } from 'wix-http-functions';

export function use_gcr(params) {
  let resource_options = {
        "headers": {
            'Access-Control-Allow-Origin': '*',
            'Content-Type': 'text/html'
        }
    };

  const customerEmail = String(params.query["email"]);
  const customerOrder = String(params.query["order"]);
  const customerDate = String(params.query["date"]);
  
  let strBody = `<html>

    <head>

    <!-- BEGIN GCR Opt-in Module Code -->
      <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
        "merchant_id": "##########", //change to your ID
        "order_id": "${customerOrder}",
        "email": "${customerEmail}",
        "delivery_country": "US", //country was constant for me, change if needed
        "estimated_delivery_date": "${customerDate}",
          
        });
      });
      }
      </script>
      <!-- END GCR Opt-in Module Code -->

    </head>

    </html>`;

    resource_options.body = strBody;

    return ok(resource_options);
}`

Once the http-function is setup, we can pass the variables to the HTML iframe by changing the .src and plugging in the variables gotten from the getOrder function. Here’s how I had that setup on the checkout page code:

$w('#html1').src = 'https://mydomain.com/_functions/gcr?email='+customerEmail+'&order='+customerOrder+'&date='+orderDate;

So far I have been able to make the survey opt-in to appear in the html element showing the correct information for some test orders.

I hope this helps someone in this thread and future people trying to integrate Google Customer Reviews into Wix! Spent a lot of time researching this.