Commit 850f50aa by dhn

订单成功页gtag

parent 8a11492c
...@@ -58,6 +58,18 @@ ...@@ -58,6 +58,18 @@
<label>instagram</label> <label>instagram</label>
<frontend_model>Joshine\InstagramFeed\Block\Adminhtml\System\Config\Account</frontend_model> <frontend_model>Joshine\InstagramFeed\Block\Adminhtml\System\Config\Account</frontend_model>
</group> </group>
<group id="tracking" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Tracking</label>
<field id="enabled" translate="label comment" type="select" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="conversion_id" translate="label comment" type="text" sortOrder="45" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Conversion Identification</label>
</field>
</group>
</section> </section>
</system> </system>
</config> </config>
...@@ -31,6 +31,7 @@ class Success extends \Magento\Framework\View\Element\Template ...@@ -31,6 +31,7 @@ class Success extends \Magento\Framework\View\Element\Template
*/ */
protected $httpContext; protected $httpContext;
protected $_scopeConfigInterface;
/** /**
* @param \Magento\Framework\View\Element\Template\Context $context * @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Checkout\Model\Session $checkoutSession
...@@ -50,6 +51,8 @@ class Success extends \Magento\Framework\View\Element\Template ...@@ -50,6 +51,8 @@ class Success extends \Magento\Framework\View\Element\Template
$this->_orderConfig = $orderConfig; $this->_orderConfig = $orderConfig;
$this->_isScopePrivate = true; $this->_isScopePrivate = true;
$this->httpContext = $httpContext; $this->httpContext = $httpContext;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$this->_scopeConfigInterface = $objectManager->get('\Magento\Framework\App\Config\ScopeConfigInterface');
} }
/** /**
...@@ -130,6 +133,26 @@ class Success extends \Magento\Framework\View\Element\Template ...@@ -130,6 +133,26 @@ class Success extends \Magento\Framework\View\Element\Template
* @return string * @return string
* @since 100.2.0 * @since 100.2.0
*/ */
public function getCurrency()
{
return $this->_storeManager->getStore()->getCurrentCurrency()->getCode();
}
public function getTrackingEnabled()
{
return $this->_scopeConfigInterface->getValue('joshine_instagram_feed/tracking/enabled');
}
public function getTrackingConversion()
{
return $this->_scopeConfigInterface->getValue('joshine_instagram_feed/tracking/conversion_id');
}
/**
* @return string
* @since 100.2.0
*/
public function getContinueUrl() public function getContinueUrl()
{ {
return $this->_storeManager->getStore()->getBaseUrl(); return $this->_storeManager->getStore()->getBaseUrl();
......
...@@ -20,6 +20,9 @@ if ($lid) { ...@@ -20,6 +20,9 @@ if ($lid) {
} }
} }
} }
$currency = $block->getCurrency();
$tracking_show = $block->getTrackingEnabled();
$tracking_conversion = $block->getTrackingConversion();
?> ?>
<div class="checkout-success"> <div class="checkout-success">
...@@ -67,6 +70,7 @@ if ($lid) { ...@@ -67,6 +70,7 @@ if ($lid) {
} }
</style> </style>
<script> <script>
dataLayer = []; dataLayer = [];
dataLayer.push({ dataLayer.push({
...@@ -74,4 +78,12 @@ if ($lid) { ...@@ -74,4 +78,12 @@ if ($lid) {
'value': <?= $totalPrice ?>, 'value': <?= $totalPrice ?>,
'items': <?= json_encode($googleItems, true) ?> 'items': <?= json_encode($googleItems, true) ?>
}); });
<?php if ($block->getOrderId() && $tracking_show > 0 && !empty($tracking_conversion)) :?>
gtag('event', 'conversion', {
'send_to': '<?= /* @noEscape */ $tracking_conversion ?>',
'value': <?= /* @noEscape */ $totalPrice ?>,
'currency': '<?= /* @noEscape */ $currency ?>',
'transaction_id': '<?= /* @noEscape */ $block->getOrderId() ?>'
});
<?php endif;?>
</script> </script>
...@@ -16,11 +16,6 @@ ...@@ -16,11 +16,6 @@
<li id="shipping" class="checkout-shipping-address address-one" data-bind="fadeVisible: addressVisible" style="order:1;"> <li id="shipping" class="checkout-shipping-address address-one" data-bind="fadeVisible: addressVisible" style="order:1;">
<!--<div class="step-title" translate="'Shipping Address'" data-role="title" />--> <!--<div class="step-title" translate="'Shipping Address'" data-role="title" />-->
<p class="step-title"> <p class="step-title">
<!--
<span class="number">
<span translate="'1'" />
</span>
-->
<span translate="'Shipping address'" /> <span translate="'Shipping address'" />
</p> </p>
<div id="checkout-step-shipping" <div id="checkout-step-shipping"
......
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