Magento – Adding Google Customer Reviews to Magento Success Page

googlemagento-1.9

I'm trying to add the google customer reviews opt-in survey to my order confirmation page using the code below. The script appears to be working, pulling the correct order information. However, there is no box in the middle of the screen for the customer to opt-in to the survey as google suggested there would be. If anyone has had any success implementing this on Magento 1.9 please help in any way you can.

Thank you.

<?php
    $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
    $order = Mage::getModel('sales/order')->load($orderId);
    ?>
    <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(
                {
                    "merchant_id": 112592416,
                    "order_id": "<?php echo $order->getIncrementId() ?>",
                    "email": <?php echo $order->getCustomerEmail() ?>,
                    "delivery_country":  "<?php echo $order->getShippingAddress()->getCountryId() ?>",
                    "estimated_delivery_date": "<?php $date = date("Y-m-d"); $mod_date = strtotime($date."+ 6 days"); echo date("Y-m-d",$mod_date); ?>"

                });
        });
    }
    </script>
<!-- END GCR Opt-in Module Code -->

Best Answer

Try to change this line:

"email": getCustomerEmail() ?>,

into

"email": "getCustomerEmail() ?>",

or, copy and past (check your Merchant ID):

<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({
              "merchant_id": 112592416,
              "order_id": "<?php echo $order->getIncrementId(); ?>",
              "email": "<?php echo $order->getCustomerEmail(); ?>",
              "delivery_country": "<?php echo $order->getShippingAddress()->getCountryId(); ?>",
              "estimated_delivery_date": "<?php $date = date('Y-m-d'); $mod_date = strtotime($date.'+ 3 days'); echo date('Y-m-d',$mod_date); ?>"
            });
        });
    }
    </script>
Related Topic