DataLayer for Google Tag Manager
How To Configure
DataLayer for Google Tag Manager

Integrate Google Opt-in Survey with Magento 2

Please Note: The settings below require our Datalayer for Google Tag Manager for Magento 2.

The survey opt-in module lets customers take part in the Google Customer Reviews (GCR) program and also transmits the necessary transaction information to Google. This module is required on all order confirmation pages to participate in Google Customer Reviews

Purchase Page / Order Confirmation Page
Tag Configuration
  Tag type : Custom Html

Trigger Configuration
  Trigger: All Custom Events
  Event Name : purchase

HTML

<script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>

<script>
require(['DataLayerPurchaseApi'], function (dataLayerPurchaseApi) {
    
    var expectedDeliveryDays = 5;
    var getDeliveryDate = function() {
        var deliveryDate = new Date(new Date().getTime()+(expectedDeliveryDays*24*60*60*1000));
        return deliveryDate.getFullYear() + '/' + ('0' + deliveryDate.getMonth()).slice(-2) + '/' + ('0' + deliveryDate.getDay()).slice(-2);
    }
    
    var purchase = dataLayerPurchaseApi();
    window.renderOptIn = function() {
       window.gapi.load('surveyoptin', function() {
         window.gapi.surveyoptin.render({
             "merchant_id": "MERCHANT_ID",
             "order_id": purchase.getOrderId(),
             "email": purchase.getEmail(),
             "delivery_country": purchase.getCurrencyCode(),
             "estimated_delivery_date": getDeliveryDate(),
           });
        });
    } 
});
</script>
Related

Related Extensions

Get more from your Magento2 store!

Magento Enhanced E-commerce

If your are using Magento + Google Analytics, then you need Enhanced E-commerce for Google Tag Manager.

DataLayer for Tag Manager

Whether you are integrating Bing, Facebook, SnapChat, Pinterest, or any other services our extension make it easy.

Enhanced Success Page

Add cross-sell, upsell, related products, social media links and other elements to your order confirmation.