Order details for Thank you page

Hello,

I need to run some Javascript Google code on thank you page (here is the code: https://jsfiddle.net/ycskgLjo/), for that I need to know some order details, how can I get all that for Thank you page? Do SimpleCart has (I didn’t find unfortunately) some basic mechanism or should I f.e. create postHook and load order details with new placeholders? Any additional info will be helpful.

Thanks a lot!

Please skip this, I’ve already found the answer, there is one useful snippet, let me share it here, probably it’ll help for others:

orderSuccessChunk:

<p>Thank you for your order!</p>
[[getGAEcommerceCode?
	&id=`[[+order.order_id]]`
]]
<!-- Google Code for  purchase Conversion Page -->
<script type="text/javascript">
var google_conversion_id = ********;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "********";
var google_remarketing_only = false;
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/********/?label=*********&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

getGAEcommerceCode snippet code:

<?php
$orderId = (int)$modx->getOption('id', $scriptProperties);
if ($orderId < 1) {
    return '';
}
$sc = $modx->getService('simplecart', 'SimpleCart', $modx->getOption('simplecart.core_path', null, $modx->getOption('core_path') . 'components/simplecart/') . 'model/simplecart/', $scriptProperties);
if (!($sc instanceof SimpleCart)) {
	return '';
}
$order = $modx->getObject('simpleCartOrder', array(
    'id' => $orderId,
));
if (!$order) {
    return '';
}
$orderNumber = trim($order->get('ordernr'));
$products = $order->getMany('Product');
if (empty($products)) {
    return '';
}
$productsJs = '';
$productsTotal = 0;
$productsTax = 0;
$count = count($products);
$totalDiscount = 0;
foreach ($products as $product) {
    $tax = 0;
    $quantity = $product->get('quantity');
    $price = round($product->get('total'), 2);
    $totals = $product->get('totals');
    if (!is_array($totals)) {
        $totals = array();
    }
    $discountPercent = isset($totals['discount_percent']) ? ($totals['discount_percent'] / 100) : 0;
    $totalDiscount += $discountPercent;
    $discount = isset($totals['discount']) ? ($totals['discount'] / $quantity) : 0;
    $price = round($price + $discount, 2);
    if (isset($totals['price_ex_vat']) && $totals['price_ex_vat'] > 0) {
        $priceExTax = round($totals['price_ex_vat'] + $discount, 2);
        if ($priceExTax != $price) {
            $tax = isset($totals['vat_price']) ? round($totals['vat_price'] / (1 - $discountPercent), 2) : 0;
            $price = $priceExTax;
            $productsTax += $tax * $quantity;
        }
    }
    $productsTotal += $price * $quantity;
    $product = array_merge($product->toArray(), array(
        'price_ex_tax' => $price,
        'tax' => $tax,
    ));
    $data = array(
        'id' => $orderNumber,
        'name' => $product['title'],
        'price' => round($product['price_ex_tax'] + $product['tax'], 2),
        'quantity' => $product['quantity'],
    );
    if (!empty($product['productcode'])) {
        $data['sku'] = $product['productcode'];
    }
    $productsJs .= 'ga("ecommerce:addItem", ' . $modx->toJSON($data) . ');';
}
$productsDiscount = $totalDiscount / $count;

$orderData = array_merge($order->toArray(), array(
    'delivery' => 0,
    'fee' => 0,
    'tax' => 0,
    'discount' => 0,
));
$orderTotals = $order->get('totals');
$taxDiff = 0;
if (is_array($orderTotals)) {
    $orderData['tax'] = $productsTax;
    $orderData['discount'] = isset($orderTotals['discount']) && $orderTotals['discount'] > 0 ? round($orderTotals['discount'], 2) : 0;
    if ($taxDiff < 0) {
        $orderData['discount'] -= $taxDiff;
    }
    if (isset($orderTotals['delivery']) && $orderTotals['delivery'] > 0) {
        $orderData['delivery'] = round($orderTotals['delivery'], 2);
    }
    $fee = isset($orderTotals['payment']) && $orderTotals['payment'] > 0 ? round($orderTotals['payment'], 2) : 0;
    if ($taxDiff > 0) {
        $fee += $taxDiff;
    }
    if ($fee) {
        $orderData['fee'] = $fee;
    }
}
$totalAmount = round($order->get('total'), 2);
$orderData['discount'] += $orderData['tax'] * $productsDiscount;
$subTotalAmount = $totalAmount - $orderData['delivery'] - $orderData['fee'] - $orderData['tax'] + $orderData['discount'];
$subTotalAmountDiff = round($subTotalAmount - $productsTotal, 2);
if ($subTotalAmountDiff) {
    $orderData[$subTotalAmountDiff > 0 ? ($orderData['fee'] > 0 ? 'fee' : 'delivery') : 'discount'] += $subTotalAmountDiff;
}
foreach (array('delivery', 'fee', 'discount') as $field) {
    if ($field == 'discount') {
        $orderData[$field . '_ex_tax'] = $productsTax > 0 ? round($orderData[$field] - $productsTax * $productsDiscount, 2) : $orderData[$field];
    } else {
        $orderData[$field . '_ex_tax'] = $productsTax > 0 ? round($orderData[$field] / 1.2, 2) : $orderData[$field];
    }
    $tax = $orderData[$field] - $orderData[$field . '_ex_tax'];
    if ($tax) {
        $orderData['tax'] += $tax * ($field == 'discount' ? -1 : 1);
    }
    $orderData[$field . '_tax'] = $tax;
}
$orderData['delivery'] += $orderData['fee'];
$data = array(
    'id' => $orderNumber,
    'revenue' => $orderData['total'],
);
if ($orderData['delivery'] > 0) {
    $data['shipping'] = $orderData['delivery'];
}
if ($orderData['tax'] > 0) {
    $data['tax'] = $orderData['tax'];
}
$orderJs = 'ga("ecommerce:addTransaction", ' . $modx->toJSON($data) . ');';
$script = <<<EOD
<script>
    if (typeof ga !== 'undefined') {
        ga('require', 'ecommerce');
        {$orderJs}
        {$productsJs}
        ga('ecommerce:send');
    }
</script>
EOD;
return $script;