This is an old revision of the document!


type:
integration
supports-foxycart-version-from:
2.0
system:
google
name:
Google Customer Reviews (Survey Opt-In)
description:
Add the Survey Opt-In display to your receipt for Google Customer Reviews
tags:
customer reviews

Google Customer Reviews (Survey Opt-In)

Please note: The code on this page is submitted by members of the FoxyCart community, and may not verified by FoxyCart.com LLC in any way, shape, or form. Please double check the code before installing. If you need help with it please post in our forum, but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance.

Adding Google Customer Reviews to your Foxy store

First you'll need to enable Customer Reviews for your Google account - review their documentation here for completing that.

Once you have it enabled for your account - you'll then need to add some code to your store. Head to the “configuration” section of your store's Foxy administration, and if it isn't already enabled, enable the “Add custom header and footer code to your templates” option. Within the “footer” textarea, paste the following code:

{% if context == "receipt" %}
<!-- BEGIN GCR Opt-in Module Code -->
<script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer>
</script>
{% set gtin = [] %}
{% for item in items %}
  {% for option in item.options %}
    {% if option.class == "gtin" %}
      {% set gtin = gtin|merge(['{"gtin":"' ~ option.value ~ '"}']) %}
    {% endif %}
  {% endfor %}
{% endfor %}
<script>
  window.renderOptIn = function() { 
    window.gapi.load('surveyoptin', function() {
      window.gapi.surveyoptin.render(
        {
          // REQUIRED
          "merchant_id":"MERCHANT_ID",
          "order_id": "{{ transaction_id }}",
          "email": "{{ customer_email }}",
          "delivery_country": "{{ shipping_address.country }}",
          "estimated_delivery_date": "{{ checkout_date|date_modify("+7 day")|date("Y-m-d") }}",
 
          // OPTIONAL
          "opt_in_style": "CENTER_DIALOG",
          {% if gtin|length > 0 %}
          "products": [{{ gtin|join(", ") }}]
          {% endif %}
        }); 
     });
  }
</script>
<!-- END GCR Opt-in Module Code -->
{% endif %}

In the code above, make sure you update the MERCHANT_ID text with your own Google Merchant ID, which you can get from the Google Merchant Center.

You may also need to modify the estimated delivery date value. The code above defaults to setting it to be 1 week after the transaction date. If you need to provide a different estimated delivery date, you will want to edit this portion of the code: "+7 day". For example, if you estimate delivery within 5 days, you would make it "+5 day".

Supporting product reviews with GTINs

The survey opt-in also allows for supporting product reviews, which requires that you pass GTIN (Global Trade Item Numbers) for each of your products. The code above does support passing the GTIN, and just require that you set a custom option to each of your product with a name of gtin. For example, in a link like &gtin=123456789 or in a form like <input type="hidden" name="gtin" value="123456789">.

You can use this page to find GTINs for your products.

Site Tools