by Firecheckout Support

How to use Miscellaneous scripts snippets on the success page?

Here we’ll show you some code snippets that can be used in the Miscellaneous scripts field of the Checkout Success Page module. It will help you to override the order success page in Magento 2 according to your requirements.

Google AdWords conversion tracking tag

This is just an example. The send_to property has to have your own value.

<script>
    gtag('event', 'conversion', {'send_to': 'AW-123456789/AbC-D_efG-h12_34-567',
        'value': {{orderAmount}},
        'currency': '{{currency}}'
    });
</script>

Google Customer Reviews

Google Customer Reviews is a free program that allows Google to collect seller reviews on your behalf from your customers. Read more at Introducing Google Customer Reviews page. We took the code below from Read more at Add the opt-in code and slightly edited it to make it work nice at checkout success page. Check the source link to get more info about code below.

<!-- BEGIN GCR Opt-in Module Code -->
<script src="https://apis.google.com/js/platform.js?onload=renderOptIn"
  async defer>
</script>

<script>
  window.renderOptIn = function() {
    window.gapi.load('surveyoptin', function() {
      var shippingData = {{orderShippingAddress}},
          today = new Date(),
          estimatedDate = new Date();

      estimatedDate.setDate(today.getDate() + 3); // estimated delivery date is 3 days from now
      window.gapi.surveyoptin.render(
        {
          // REQUIRED
          "merchant_id":"MERCHANT_ID",
          "order_id": "{{orderId}}", // ORDER_ID
          "email": "{{customerEmail}}", // CUSTOMER_EMAIL
          "delivery_country": shippingData.country_id,
          "estimated_delivery_date": estimatedDate.toISOString().slice(0, 10),

          // OPTIONAL
          "opt_in_style": "OPT_IN_STYLE"
        });
     });
  }
</script>
<!-- END GCR Opt-in Module Code -->

Customer type (guest or registered customer)

<script type="text/javascript">
    var customerType = '{{customerId}}' ? 'registered' : 'guest';
</script>

Ordered Items SKUs

Note: adding this requires the Checkout Success Page version 1.1.3 or higher.

<script type="text/javascript">
    var orderedItems = {{orderItems}};
    var orderedSKUs = jQuery.map(orderedItems, function(v){ return v.sku; }); // Array
</script>

Quantity of ordered products

Note: adding this requires the Checkout Success Page version 1.1.3 or higher.

<script type="text/javascript">
    var orderedItems = {{orderItems}};
    var orderedQty = 0;
    jQuery.map(orderedItems, function(v){ orderedQty += parseFloat(v.qty_ordered); });
    // now orderedQty containes quantity of ordered products
</script>

Estimated delivery date

This is just an example of how you can calculate the estimated delivery date. Please know that here we know that the shipping method with code FAST_DELIVERY delivers products within 1 day, THREE_DAYS_DELIVERY - delivers within 3 days and all other methods deliver within 4 days.
<script type="text/javascript">
    var today = new Date(),
        estimatedDate = new Date(),
        shippingMethod = '{{shippingCode}}';
    if (shippingMethod == 'FAST_DELIVERY') {
        estimatedDate.setDate(today.getDate() + 1);
    } else if (shippingMethod == 'THREE_DAYS_DELIVERY') {
        estimatedDate.setDate(today.getDate() + 3);
    } else {
        // all other methods delivers within 4 days
        estimatedDate.setDate(today.getDate() + 4);
    }
    // now estimatedDate containes delivery date depending
    // on shipping method customer used in order
</script>

Recent articles

up