Google Customer Review script code (Estimated Delivery Date)

1.8k Views Asked by At

I'm implementing the Google Customer Review script on my ecommerce's "Thank You" page. The only problem is that I can't pull a date 1 month from current month to show up on "estimated_delivery_date". Everything else is working fine.

The date has to be exactly in this format: "yyyy-mm-dd".

Here's the code I have so far:

<script>
var emailAddress = Order[9]; // pulls customer's email
var datePurchased = new Date();
var yyyy = datePurchased.getFullYear();
var mm = datePurchased.getMonth()+1;
var dd = datePurchased.getDate();
var delivery = yyyy+'-'+mm+'-'+dd;

  window.renderOptIn = function() {
    window.gapi.load('surveyoptin', function() {

      window.gapi.surveyoptin.render(
        {
          "merchant_id": 7654321,
          "order_id": "$(OrderNo)", // pulls order number
          "email": emailAddress, // pulls customer's email
          "delivery_country": "US",
          "estimated_delivery_date": "delivery", // not pulling delivery date. Why?
        });
    });
  }
</script>

Thanks for the help!

1

There are 1 best solutions below

0
On BEST ANSWER

You are passing delivery as string:

"estimated_delivery_date": "delivery", // not pulling delivery date. Why?

Try:

<script>
var emailAddress = Order[9];
var datePurchased = new Date();
var yyyy = datePurchased.getFullYear();
var mm = datePurchased.getMonth()+1;
var dd = datePurchased.getDate();
var delivery = yyyy+'-'+mm+'-'+dd;

  window.renderOptIn = function() {
    window.gapi.load('surveyoptin', function() {

      window.gapi.surveyoptin.render(
        {
          "merchant_id": 7654321,
          "order_id": "$(OrderNo)",
          "email": emailAddress,
          "delivery_country": "US",
          "estimated_delivery_date": delivery
        });
    });
  }
</script>