−Table of Contents
- type:
- integration
- supports-foxycart-version-from:
- 2.0
- system:
- name:
- Google Customer Reviews (Survey Opt-In)
- description:
- Add the Survey Opt-In display to your receipt for Google 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
Requirements
- Customer Reviews enabled on your Google Merchant Account - review their documentation here for completing that.
- A custom subdomain for your Foxy Store - The Opt-In Survey will also only display on your approved/validated domains. As such, your Foxy store will need to use a custom subdomain (like
secure.yourstore.com
), rather than on our standard FoxyCart subdomain (likeyourstore.foxycart.com
).
Add the integration code to your website
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(", ")|raw }}] {% 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 >in=123456789
or in a form like <input type="hidden" name="gtin" value="123456789">
.
You can use this page to find GTINs for your products.
Using product code instead of a custom product option for gtin
If you specify the gtin
value as your product code
already, you can use a modified version of the code to use the code
you're passing.
Specifically, replace this portion of the code:
{% 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 %}
With this version:
{% set gtin = [] %} {% for item in items %} {% set gtin = gtin|merge(['{"gtin":"' ~ item.code ~ '"}']) %} {% endfor %}