GX-Bug #55362
geschlossenTracking Codes um weitere Positionen und Funktionalitäten erweitern | Extend tracking codes by additional positions and features
100%
SEO→Tracking-Codes erweitert um Codes im Head und Bestellabschluss; Tracking-Codes können jetzt Smarty-Code enthalten
Beschreibung
Wir bekommen Rückmeldungen von Kundenseite dass Google Analytics Codes im Head eingebunden werden müssen, damit diese von Google erkannt werden. Standardmäßig werden Tracking-Codes jedoch am unteren Ende des Bodys angezeigt.
Die Einstellung unter Shop Einstellungen > SEO > Tracking-Codes sollte um eine Option erweitert werden, den Tracking-Code wahlweise in Head oder Body anzuzeigen.
Checkliste 0/0
Von Marco Bruchmann vor mehr als 5 Jahren aktualisiert
- Thema wurde von Tracking Codes im Head einbindbar machen zu Tracking Codes um weitere Positionen und Funktionalitäten erweitern | Extend tracking codes by additional positions and features geändert
- Zugewiesen an wurde auf Marco Bruchmann gesetzt
Die Tracking Codes sollten dahingehend erweitert werden, dass zusätzliche Einbindungen im Head-Bereich der Seite und auf der Bestellabschlussseite (checkout_success) möglich werden. Hierbei sollten die Tracking Codes auch durch Smarty geparst werden, um zusätzliche Funktionalität und Datenquellen zu erschließen.
Tracking Codes should be extended to include additional tracking codes in the head section of each page and on the final page of the checkout (checkout_success). The codes should also be parsed by Smarty to allow for additional functionality and data sources.
Examples:
Tracking Code (head):
<script>
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('div').forEach(function(d) { d.style.boxShadow = '0 0 10px red'; });
});
let cartData = {$smarty.session.cart|json_encode};
</script>
<!-- Test Smarty: {42 + 23} -->
Will add a red shadow around each div element, inject $_SESSION['cart'] as a JSON object (quite pointless; just for illustration) and output the sum of 42 and 23 in an HTML comment.
Note the use of native Javascript here: jQuery is not available at this point in the page!
Tracking Code (bottom):
<script>
$('p').css('background-color', 'cornsilk');
</script>
<p>
{'c'|date}
</p>
<pre>{$_GLOBALS.order|print_r}</pre>
Here, jQuery is available and used to set the background color of all p elements to cornsilk. Also, a date is output through a Smarty call.
Tracking Code (checkout_success):
<p>
{foreach $order->getOrderItems() as $oItem}
{$oItem->getQuantity()} {$oItem->getName()} ({$oItem->getProductModel()}) für {$oItem->getPrice()|number_format:2} {$order->getCurrencyCode()->getCode()}<br>
{/foreach}
</p>
<p>Hello, there!</p>
<script>
document.write('hallo {$legacyOrder->info['payment_method']}');
if(true) { document.write('Moin.'); }
</script>
On the checkout_success page, additional Smarty variables $order and $legacyOrder are available. The $order is an implementation of OrderInterface, the result of a call to OrderReadService::getOrderById(). The $legacyOrder is simply an instance of includes/classes/order.inc.php.
Also, note that Smarty and Javascript code can be interspersed if the braces ({}) in Javascript code are followed by spaces.