Commit 17d11ff7 by liumengfei

Merge branch 'developer' into production

parents 33236a82 c098b3c0
<?php
namespace Joshine\GoogleFeed\Helper;
use \Magento\Framework\App\Helper\AbstractHelper;
class GAHelper extends AbstractHelper
{
public static function normalizeAndHash(string $hashAlgorithm, string $value): string
{
return hash($hashAlgorithm, strtolower(trim($value)));
}
public static function normalizeAndHashEmailAddress(
string $hashAlgorithm,
string $emailAddress
): string {
$normalizedEmail = strtolower($emailAddress);
$emailParts = explode("@", $normalizedEmail);
if (
count($emailParts) > 1
&& preg_match('/^(gmail|googlemail)\.com\s*/', $emailParts[1])
) {
$emailParts[0] = str_replace(".", "", $emailParts[0]);
$normalizedEmail = sprintf('%s@%s', $emailParts[0], $emailParts[1]);
}
return self::normalizeAndHash($hashAlgorithm, $normalizedEmail);
}
}
\ No newline at end of file
......@@ -7,8 +7,8 @@
$lid = $block->getOrderId();
$totalPrice = 0;
$googleItems = [];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
if ($lid) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($lid);
if ($order) {
$totalPrice = $order->getGrandTotal();
......@@ -18,11 +18,17 @@ if ($lid) {
$_item['id'] = $value->getSku();
$googleItems[] = $_item;
}
$email = $order->getCustomerEmail();
}
}
$currency = $block->getCurrency();
$tracking_show = $block->getTrackingEnabled();
$tracking_conversion = $block->getTrackingConversion();
$helper = $objectManager->get('Joshine\GoogleFeed\Helper\GAHelper');
?>
<div class="checkout-success">
......@@ -72,20 +78,33 @@ $tracking_conversion = $block->getTrackingConversion();
</style>
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'purchase',
'value': <?= $totalPrice ?>,
'items': <?= json_encode($googleItems, true) ?>
});
//window.dataLayer = window.dataLayer || [];
//dataLayer.push({
// 'event': 'purchase',
// 'value': <?php //= $totalPrice ?>//,
// 'items': <?php //= json_encode($googleItems, true) ?>
//});
<?php if ($block->getOrderId() && $tracking_show > 0 && !empty($tracking_conversion)) :?>
setTimeout(function () {
gtag('event', 'conversion', {
'send_to': '<?= /* @noEscape */ $tracking_conversion ?>',
'value': <?= /* @noEscape */ $totalPrice ?>,
'value': '<?= /* @noEscape */ $totalPrice ?>',
'currency': '<?= /* @noEscape */ $currency ?>',
'transaction_id': '<?= /* @noEscape */ $block->getOrderId() ?>'
});
gtag('event', 'purchase', {
"transaction_id": '<?= /* @noEscape */ $block->getOrderId() ?>',
"value": '<?= /* @noEscape */ $totalPrice ?>',
"currency": '<?= /* @noEscape */ $currency ?>',,
"items": <?= json_encode($googleItems, true); ?>
});
<?php if (isset($email) && !empty($email)) :?>
gtag('set' , 'user_data' , {
"sha256_email_address" : '<?= $helper::normalizeAndHashEmailAddress("sha256", $email); ?>'
});
<?php endif; ?>
}, 1500);
<?php endif;?>
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment